Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenaccept.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS TCP/IP protocol driver 00004 * FILE: transport/tcp/accept.c 00005 * PURPOSE: Transmission Control Protocol Listen/Accept code 00006 * PROGRAMMERS: Art Yerkes (arty@users.sf.net) 00007 * REVISIONS: 00008 * arty 12/21/2004 Created 00009 */ 00010 00011 #include "precomp.h" 00012 00013 #include "rosip.h" 00014 00015 extern NPAGED_LOOKASIDE_LIST TdiBucketLookasideList; 00016 00017 NTSTATUS TCPCheckPeerForAccept(PVOID Context, 00018 PTDI_REQUEST_KERNEL Request) 00019 { 00020 struct tcp_pcb *newpcb = (struct tcp_pcb*)Context; 00021 NTSTATUS Status; 00022 PTDI_CONNECTION_INFORMATION WhoIsConnecting; 00023 PTA_IP_ADDRESS RemoteAddress; 00024 struct ip_addr ipaddr; 00025 00026 if (Request->RequestFlags & TDI_QUERY_ACCEPT) 00027 DbgPrint("TDI_QUERY_ACCEPT NOT SUPPORTED!!!\n"); 00028 00029 WhoIsConnecting = (PTDI_CONNECTION_INFORMATION)Request->ReturnConnectionInformation; 00030 RemoteAddress = (PTA_IP_ADDRESS)WhoIsConnecting->RemoteAddress; 00031 00032 RemoteAddress->TAAddressCount = 1; 00033 RemoteAddress->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP; 00034 RemoteAddress->Address[0].AddressType = TDI_ADDRESS_TYPE_IP; 00035 00036 Status = TCPTranslateError(LibTCPGetPeerName(newpcb, 00037 &ipaddr, 00038 &RemoteAddress->Address[0].Address[0].sin_port)); 00039 00040 RemoteAddress->Address[0].Address[0].in_addr = ipaddr.addr; 00041 00042 return Status; 00043 } 00044 00045 /* This listen is on a socket we keep as internal. That socket has the same 00046 * lifetime as the address file */ 00047 NTSTATUS TCPListen(PCONNECTION_ENDPOINT Connection, UINT Backlog) 00048 { 00049 NTSTATUS Status = STATUS_SUCCESS; 00050 struct ip_addr AddressToBind; 00051 KIRQL OldIrql; 00052 TA_IP_ADDRESS LocalAddress; 00053 00054 ASSERT(Connection); 00055 00056 LockObject(Connection, &OldIrql); 00057 00058 ASSERT_KM_POINTER(Connection->AddressFile); 00059 00060 TI_DbgPrint(DEBUG_TCP,("[IP, TCPListen] Called\n")); 00061 00062 TI_DbgPrint(DEBUG_TCP, ("Connection->SocketContext %x\n", 00063 Connection->SocketContext)); 00064 00065 AddressToBind.addr = Connection->AddressFile->Address.Address.IPv4Address; 00066 00067 Status = TCPTranslateError(LibTCPBind(Connection, 00068 &AddressToBind, 00069 Connection->AddressFile->Port)); 00070 00071 if (NT_SUCCESS(Status)) 00072 { 00073 /* Check if we had an unspecified port */ 00074 if (!Connection->AddressFile->Port) 00075 { 00076 /* We did, so we need to copy back the port */ 00077 Status = TCPGetSockAddress(Connection, (PTRANSPORT_ADDRESS)&LocalAddress, FALSE); 00078 if (NT_SUCCESS(Status)) 00079 { 00080 /* Allocate the port in the port bitmap */ 00081 Connection->AddressFile->Port = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port); 00082 00083 /* This should never fail */ 00084 ASSERT(Connection->AddressFile->Port != 0xFFFF); 00085 } 00086 } 00087 } 00088 00089 if (NT_SUCCESS(Status)) 00090 { 00091 Connection->SocketContext = LibTCPListen(Connection, Backlog); 00092 if (!Connection->SocketContext) 00093 Status = STATUS_UNSUCCESSFUL; 00094 } 00095 00096 UnlockObject(Connection, OldIrql); 00097 00098 TI_DbgPrint(DEBUG_TCP,("[IP, TCPListen] Leaving. Status = %x\n", Status)); 00099 00100 return Status; 00101 } 00102 00103 BOOLEAN TCPAbortListenForSocket 00104 ( PCONNECTION_ENDPOINT Listener, 00105 PCONNECTION_ENDPOINT Connection) 00106 { 00107 PLIST_ENTRY ListEntry; 00108 PTDI_BUCKET Bucket; 00109 KIRQL OldIrql; 00110 BOOLEAN Found = FALSE; 00111 00112 LockObject(Listener, &OldIrql); 00113 00114 ListEntry = Listener->ListenRequest.Flink; 00115 while (ListEntry != &Listener->ListenRequest) 00116 { 00117 Bucket = CONTAINING_RECORD(ListEntry, TDI_BUCKET, Entry); 00118 00119 if (Bucket->AssociatedEndpoint == Connection) 00120 { 00121 DereferenceObject(Bucket->AssociatedEndpoint); 00122 RemoveEntryList( &Bucket->Entry ); 00123 ExFreeToNPagedLookasideList(&TdiBucketLookasideList, Bucket); 00124 Found = TRUE; 00125 break; 00126 } 00127 00128 ListEntry = ListEntry->Flink; 00129 } 00130 00131 UnlockObject(Listener, OldIrql); 00132 00133 return Found; 00134 } 00135 00136 NTSTATUS TCPAccept ( PTDI_REQUEST Request, 00137 PCONNECTION_ENDPOINT Listener, 00138 PCONNECTION_ENDPOINT Connection, 00139 PTCP_COMPLETION_ROUTINE Complete, 00140 PVOID Context ) 00141 { 00142 NTSTATUS Status; 00143 PTDI_BUCKET Bucket; 00144 KIRQL OldIrql; 00145 00146 LockObject(Listener, &OldIrql); 00147 00148 Bucket = ExAllocateFromNPagedLookasideList(&TdiBucketLookasideList); 00149 00150 if (Bucket) 00151 { 00152 Bucket->AssociatedEndpoint = Connection; 00153 ReferenceObject(Bucket->AssociatedEndpoint); 00154 00155 Bucket->Request.RequestNotifyObject = Complete; 00156 Bucket->Request.RequestContext = Context; 00157 InsertTailList( &Listener->ListenRequest, &Bucket->Entry ); 00158 Status = STATUS_PENDING; 00159 } 00160 else 00161 Status = STATUS_NO_MEMORY; 00162 00163 UnlockObject(Listener, OldIrql); 00164 00165 return Status; 00166 } Generated on Sat May 26 2012 04:34:54 for ReactOS by
1.7.6.1
|