X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=lib%2Fdrivers%2Fip%2Fnetwork%2Finterface.c;h=7efb3ac14cb04c7661b2f632a4547f9c175e75d7;hp=0d127ca9bcb60c0dadbdbca1168796e2294f4287;hb=f66525ee02257ec70732abc74034a2161e12190b;hpb=a989736ead401c669e8f30b190f3539e9d32d537 diff --git a/lib/drivers/ip/network/interface.c b/lib/drivers/ip/network/interface.c index 0d127ca9bcb..7efb3ac14cb 100644 --- a/lib/drivers/ip/network/interface.c +++ b/lib/drivers/ip/network/interface.c @@ -11,6 +11,8 @@ #include "precomp.h" +ULONG NextDefaultAdapter = 0; + NTSTATUS GetInterfaceIPv4Address( PIP_INTERFACE Interface, ULONG TargetType, PULONG Address ) { @@ -143,18 +145,46 @@ BOOLEAN HasPrefix( 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