Erich Hoover wrote:
Real Name: Erich Hoover Description: If an application calls gethostbyname on it's own hostname then it expects an IP to be returned for each interface, in order of the routing priority (see MS Knowledge Base article #160215). The attached patch first checks to see if the gethostbyname request resolved to a loopback address (which currently gets replaced by the magic IP). If the magic IP would have been returned then it uses the routing table to build the list of IP addresses and properly sorts those addresses from highest routing priority to lowest routing priority (lowest metric to highest metric). Changelog: ws2_32: Use the routing table information for gethostbyname('self') if the magic IP would otherwise be returned.
Thanks for the patch, however there are few issues with it.
Why do you return a list of IP addresses from WS2_get_local_ips if you need only one? Just get the one with the lowest metric and return it.
I think it would be better
- adapters = HeapAlloc(GetProcessHeap(),0,adap_size);
- routes = HeapAlloc(GetProcessHeap(),0,route_size);
- route_addrs = HeapAlloc(GetProcessHeap(),0,0); /* HeapReAlloc doesn't work on NULL */
Here and everywhere else please put space before comas to follow the file's formatting.
- if (route_addrs != NULL)
HeapFree(GetProcessHeap(), 0, route_addrs);
- if (adapters != NULL)
HeapFree(GetProcessHeap(), 0, adapters);
- if (routes != NULL)
HeapFree(GetProcessHeap(), 0, routes);
You do not need to check pointers for NULL before freeing them.
Vitaliy.