diff --git a/lib/drivers/ip/network/icmp.c b/lib/drivers/ip/network/icmp.c index 6802230ee0c..33a487d627f 100644 --- a/lib/drivers/ip/network/icmp.c +++ b/lib/drivers/ip/network/icmp.c @@ -178,9 +178,6 @@ NTSTATUS ICMPSendDatagram( TI_DbgPrint(MID_TRACE,("About to get route to destination\n")); - if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) - return STATUS_NETWORK_UNREACHABLE; - LocalAddress = AddrFile->Address; if (AddrIsUnspecified(&LocalAddress)) { @@ -188,8 +185,16 @@ NTSTATUS ICMPSendDatagram( * then use the unicast address of the * interface we're sending over */ + if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) + return STATUS_NETWORK_UNREACHABLE; + LocalAddress = NCE->Interface->Unicast; } + else + { + if(!(NCE = NBLocateNeighbor( &LocalAddress ))) + return STATUS_INVALID_PARAMETER; + } Status = PrepareICMPPacket( NCE->Interface, &Packet, diff --git a/lib/drivers/ip/transport/rawip/rawip.c b/lib/drivers/ip/transport/rawip/rawip.c index 328337cdb38..44c6465ca75 100644 --- a/lib/drivers/ip/transport/rawip/rawip.c +++ b/lib/drivers/ip/transport/rawip/rawip.c @@ -218,12 +218,6 @@ NTSTATUS RawIPSendDatagram( TI_DbgPrint(MID_TRACE,("About to get route to destination\n")); - if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) - { - KeReleaseSpinLock(&AddrFile->Lock, OldIrql); - return STATUS_NETWORK_UNREACHABLE; - } - LocalAddress = AddrFile->Address; if (AddrIsUnspecified(&LocalAddress)) { @@ -231,8 +225,20 @@ NTSTATUS RawIPSendDatagram( * then use the unicast address of the * interface we're sending over */ + if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) { + KeReleaseSpinLock(&AddrFile->Lock, OldIrql); + return STATUS_NETWORK_UNREACHABLE; + } + LocalAddress = NCE->Interface->Unicast; } + else + { + if(!(NCE = NBLocateNeighbor( &LocalAddress ))) { + KeReleaseSpinLock(&AddrFile->Lock, OldIrql); + return STATUS_INVALID_PARAMETER; + } + } Status = BuildRawIpPacket( AddrFile, &Packet, diff --git a/lib/drivers/ip/transport/tcp/tcp.c b/lib/drivers/ip/transport/tcp/tcp.c index fe571126379..0d1710adb6c 100644 --- a/lib/drivers/ip/transport/tcp/tcp.c +++ b/lib/drivers/ip/transport/tcp/tcp.c @@ -631,11 +631,6 @@ NTSTATUS TCPConnect return Status; } - if (!(NCE = RouteGetRouteToDestination(&RemoteAddress))) - { - return STATUS_NETWORK_UNREACHABLE; - } - /* Freed in TCPSocketState */ TI_DbgPrint(DEBUG_TCP, ("Connecting to address %x:%x\n", @@ -644,10 +639,30 @@ NTSTATUS TCPConnect AddressToConnect.sin_family = AF_INET; AddressToBind = AddressToConnect; - AddressToBind.sin_addr.s_addr = NCE->Interface->Unicast.Address.IPv4Address; KeAcquireSpinLock(&Connection->Lock, &OldIrql); + if (!Connection->AddressFile) + { + KeReleaseSpinLock(&Connection->Lock, OldIrql); + return STATUS_INVALID_PARAMETER; + } + + if (AddrIsUnspecified(&Connection->AddressFile->Address)) + { + if (!(NCE = RouteGetRouteToDestination(&RemoteAddress))) + { + KeReleaseSpinLock(&Connection->Lock, OldIrql); + return STATUS_NETWORK_UNREACHABLE; + } + + AddressToBind.sin_addr.s_addr = NCE->Interface->Unicast.Address.IPv4Address; + } + else + { + AddressToBind.sin_addr.s_addr = Connection->AddressFile->Address.Address.IPv4Address; + } + Status = TCPTranslateError ( OskitTCPBind( Connection->SocketContext, &AddressToBind, diff --git a/lib/drivers/ip/transport/udp/udp.c b/lib/drivers/ip/transport/udp/udp.c index 125e5101fc0..510e8827cc8 100644 --- a/lib/drivers/ip/transport/udp/udp.c +++ b/lib/drivers/ip/transport/udp/udp.c @@ -193,11 +193,6 @@ NTSTATUS UDPSendDatagram( return STATUS_UNSUCCESSFUL; } - if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) { - KeReleaseSpinLock(&AddrFile->Lock, OldIrql); - return STATUS_NETWORK_UNREACHABLE; - } - LocalAddress = AddrFile->Address; if (AddrIsUnspecified(&LocalAddress)) { @@ -205,8 +200,20 @@ NTSTATUS UDPSendDatagram( * then use the unicast address of the * interface we're sending over */ + if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) { + KeReleaseSpinLock(&AddrFile->Lock, OldIrql); + return STATUS_NETWORK_UNREACHABLE; + } + LocalAddress = NCE->Interface->Unicast; } + else + { + if(!(NCE = NBLocateNeighbor( &LocalAddress ))) { + KeReleaseSpinLock(&AddrFile->Lock, OldIrql); + return STATUS_INVALID_PARAMETER; + } + } Status = BuildUDPPacket( AddrFile, &Packet,