Author: cgutman
Date: Sun Aug 4 12:45:53 2013
New Revision: 59633
URL:
http://svn.reactos.org/svn/reactos?rev=59633&view=rev
Log:
[IP]
- Do a better job of selecting an interface to use when none was specified
- Fix build
Modified:
trunk/reactos/lib/drivers/ip/network/interface.c
Modified: trunk/reactos/lib/drivers/ip/network/interface.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/ip/network/int…
==============================================================================
--- trunk/reactos/lib/drivers/ip/network/interface.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/ip/network/interface.c [iso-8859-1] Sun Aug 4 12:45:53
2013
@@ -10,6 +10,8 @@
*/
#include "precomp.h"
+
+ULONG NextDefaultAdapter = 0;
NTSTATUS GetInterfaceIPv4Address( PIP_INTERFACE Interface,
ULONG TargetType,
@@ -143,18 +145,46 @@
return TRUE;
}
-static PIP_INTERFACE GetDefaultInterface(VOID)
+PIP_INTERFACE GetDefaultInterface(VOID)
{
KIRQL OldIrql;
+ ULONG Index = 0;
+
IF_LIST_ITER(CurrentIF);
TcpipAcquireSpinLock(&InterfaceListLock, &OldIrql);
+ /* DHCP hack: Always return the adapter without an IP address */
ForEachInterface(CurrentIF) {
if (CurrentIF->Context) {
+ if (AddrIsUnspecified(&CurrentIF->Unicast)) {
+ TcpipReleaseSpinLock(&InterfaceListLock, OldIrql);
+ return CurrentIF;
+ }
+ }
+ } EndFor(CurrentIF);
+
+ /* Try to continue from the next adapter */
+ ForEachInterface(CurrentIF) {
+ if (CurrentIF->Context) {
+ if (Index++ == NextDefaultAdapter) {
+ NextDefaultAdapter++;
+ TcpipReleaseSpinLock(&InterfaceListLock, OldIrql);
+ return CurrentIF;
+ }
+ }
+ } EndFor(CurrentIF);
+
+ /* No luck, so we'll choose the first adapter this time */
+ ForEachInterface(CurrentIF) {
+ if (CurrentIF->Context) {
+ NextDefaultAdapter = 1;
TcpipReleaseSpinLock(&InterfaceListLock, OldIrql);
return CurrentIF;
}
} EndFor(CurrentIF);
+
+ /* Even that didn't work, so we'll just go with loopback */
+ NextDefaultAdapter = 0;
TcpipReleaseSpinLock(&InterfaceListLock, OldIrql);
/* There are no physical interfaces on the system