diff --git a/drivers/network/tcpip/ip/transport/tcp/accept.c b/drivers/network/tcpip/ip/transport/tcp/accept.c index 62c96cf5f33..e6f94b26d7a 100644 --- a/drivers/network/tcpip/ip/transport/tcp/accept.c +++ b/drivers/network/tcpip/ip/transport/tcp/accept.c @@ -77,10 +77,10 @@ NTSTATUS TCPListen(PCONNECTION_ENDPOINT Connection, UINT Backlog) if (NT_SUCCESS(Status)) { /* Allocate the port in the port bitmap */ - Connection->AddressFile->Port = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port); - + UINT AllocatedPort = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port); /* This should never fail */ - ASSERT(Connection->AddressFile->Port != 0xFFFF); + ASSERT(AllocatedPort != (UINT)-1); + Connection->AddressFile->Port = AllocatedPort; } } } diff --git a/drivers/network/tcpip/ip/transport/tcp/tcp.c b/drivers/network/tcpip/ip/transport/tcp/tcp.c index 604ce11bd62..7a7762a3411 100644 --- a/drivers/network/tcpip/ip/transport/tcp/tcp.c +++ b/drivers/network/tcpip/ip/transport/tcp/tcp.c @@ -214,7 +214,7 @@ NTSTATUS TCPStartup(VOID) { NTSTATUS Status; - Status = PortsStartup( &TCPPorts, 1, 0xfffe ); + Status = PortsStartup(&TCPPorts, 1, 0xffff); if (!NT_SUCCESS(Status)) { return Status; @@ -370,6 +370,8 @@ NTSTATUS TCPConnect /* Check if we had an unspecified port */ if (!Connection->AddressFile->Port) { + UINT AllocatedPort; + /* We did, so we need to copy back the port */ Status = TCPGetSockAddress(Connection, (PTRANSPORT_ADDRESS)&LocalAddress, FALSE); if (!NT_SUCCESS(Status)) @@ -379,10 +381,10 @@ NTSTATUS TCPConnect } /* Allocate the port in the port bitmap */ - Connection->AddressFile->Port = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port); - + AllocatedPort = TCPAllocatePort(LocalAddress.Address[0].Address[0].sin_port); /* This should never fail */ - ASSERT(Connection->AddressFile->Port != 0xFFFF); + ASSERT(AllocatedPort != (UINT)-1); + Connection->AddressFile->Port = AllocatedPort; } connaddr.addr = RemoteAddress.Address.IPv4Address; diff --git a/drivers/network/tcpip/tcpip/fileobjs.c b/drivers/network/tcpip/tcpip/fileobjs.c index d926abed97e..d3dee752efa 100644 --- a/drivers/network/tcpip/tcpip/fileobjs.c +++ b/drivers/network/tcpip/tcpip/fileobjs.c @@ -404,6 +404,7 @@ NTSTATUS FileOpenAddress( PVOID Options) { PADDRESS_FILE AddrFile; + UINT AllocatedPort; TI_DbgPrint(MID_TRACE, ("Called (Proto %d).\n", Protocol)); @@ -472,14 +473,15 @@ NTSTATUS FileOpenAddress( if (Address->Address[0].Address[0].sin_port) { /* The client specified an explicit port so we force a bind to this */ - AddrFile->Port = TCPAllocatePort(Address->Address[0].Address[0].sin_port); + AllocatedPort = TCPAllocatePort(Address->Address[0].Address[0].sin_port); /* Check for bind success */ - if (AddrFile->Port == 0xffff) + if (AllocatedPort == (UINT)-1) { ExFreePoolWithTag(AddrFile, ADDR_FILE_TAG); return STATUS_ADDRESS_ALREADY_EXISTS; } + AddrFile->Port = AllocatedPort; /* Sanity check */ ASSERT(Address->Address[0].Address[0].sin_port == AddrFile->Port); @@ -487,14 +489,15 @@ NTSTATUS FileOpenAddress( else if (!AddrIsUnspecified(&AddrFile->Address)) { /* The client is trying to bind to a local address so allocate a port now too */ - AddrFile->Port = TCPAllocatePort(0); + AllocatedPort = TCPAllocatePort(0); /* Check for bind success */ - if (AddrFile->Port == 0xffff) + if (AllocatedPort == (UINT)-1) { ExFreePoolWithTag(AddrFile, ADDR_FILE_TAG); return STATUS_ADDRESS_ALREADY_EXISTS; } + AddrFile->Port = AllocatedPort; } else { @@ -509,16 +512,16 @@ NTSTATUS FileOpenAddress( case IPPROTO_UDP: TI_DbgPrint(MID_TRACE,("Allocating udp port\n")); - AddrFile->Port = - UDPAllocatePort(Address->Address[0].Address[0].sin_port); + AllocatedPort = UDPAllocatePort(Address->Address[0].Address[0].sin_port); if ((Address->Address[0].Address[0].sin_port && - AddrFile->Port != Address->Address[0].Address[0].sin_port) || - AddrFile->Port == 0xffff) + AllocatedPort != Address->Address[0].Address[0].sin_port) || + AllocatedPort == (UINT)-1) { ExFreePoolWithTag(AddrFile, ADDR_FILE_TAG); return STATUS_ADDRESS_ALREADY_EXISTS; } + AddrFile->Port = AllocatedPort; TI_DbgPrint(MID_TRACE,("Setting port %d (wanted %d)\n", AddrFile->Port,