diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index d31f0b4..d8f6b62 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -5955,6 +5955,7 @@ static struct WS_hostent* WS_get_local_ips( char *hostname ) PMIB_IPFORWARDTABLE routes = NULL; struct route *route_addrs = NULL; DWORD adap_size, route_size; + int default_routes = 0; /* Obtain the size of the adapter list and routing table, also allocate memory */ if (GetAdaptersInfo(NULL, &adap_size) != ERROR_BUFFER_OVERFLOW) @@ -5978,10 +5979,18 @@ static struct WS_hostent* WS_get_local_ips( char *hostname ) DWORD ifmetric; BOOL exists = FALSE; - if (routes->table[n].u1.ForwardType != MIB_IPROUTE_TYPE_DIRECT) - continue; ifindex = routes->table[n].dwForwardIfIndex; - ifmetric = routes->table[n].dwForwardMetric1; + /* Check if this is the default route (there may be more than one) */ + if (!routes->table[n].dwForwardDest) + ifmetric = ++default_routes; + else if (routes->table[n].u1.ForwardType != MIB_IPROUTE_TYPE_DIRECT) + continue; + else + { + ifmetric = routes->table[n].dwForwardMetric1; + if (!ifmetric) ifmetric = 1000; /* Ignore 0 to not mess with the default routes */ + } + /* Only store the lowest valued metric for an interface */ for (j = 0; j < numroutes; j++) { @@ -6005,7 +6014,7 @@ static struct WS_hostent* WS_get_local_ips( char *hostname ) memcpy(&(route_addrs[numroutes].addr.s_addr), magic_loopback_addr, 4); numroutes++; } - if (numroutes == 0) + if (numroutes == 0) goto cleanup; /* No routes, fall back to the Magic IP */ /* Find the IP address associated with each found interface */ for (i = 0; i < numroutes; i++) @@ -6036,7 +6045,10 @@ static struct WS_hostent* WS_get_local_ips( char *hostname ) qsort(route_addrs, numroutes, sizeof(struct route), WS_compare_routes_by_metric_asc); for (i = 0; i < numroutes; i++) + { (*(struct in_addr *) hostlist->h_addr_list[i]) = route_addrs[i].addr; + printf("IP[%d] %s, metric %d\n", i, inet_ntoa(route_addrs[i].addr), route_addrs[i].metric); + } /* Cleanup all allocated memory except the address list, * the address list is used by the calling app.