The attached patch fixes some problems in the function
getIPHelperDNSEntries() found in the file
sipXportlib\src\os\Wnt\getWindowsDNSServers.cpp. This function attempts to
obtain the list of DNS servers from Windows using the iphlpapi.dll function
available under most versions of Windows. However, under Windows XP, this
function was ALWAYS failing. This failure was masked because
getWindowsDNSServers() calls getDNSEntriesFromRegistry() if
getIPHelperDNSEntries() doesn't find anything - getDNSEntriesFromRegistry()
is intended to deal with Windows NT4 systems that don't support
iphlpapi.dll. Under Windows XP, getDNSEntriesFromRegistry() does succeed if
the DNS server list was obtained by DHCP, but it fails if the DNS servers
are statically configured, as they are stored in a different registry
location than they were under NT4 (under an adapter specific key).

The changes I made were as follows:
===================================

1. The function pointer GetNetworkParams was being set to NULL just before
calling loadIPHelperAPI(). Not only isn't this necessary (as it is
statically initialized to NULL), if the call to loadIPHelperAPI() that
occurs here is not the first time loadIPHelperAPI() is called (and it
frequently isn't), then the address of the iphlpapi.dll function is lost as
loadIPHelperAPI() only sets the function pointers the FIRST time it is
called).

2. I changed getIPHelperDNSEntries() to return early for the cases where it
fails (wrong windows version or unable to load iphlpapi.dll).

3. The code for Windows 2000 and XP, called GetInterfaceInfo() to get a list
of adapter names and the corresponding index, and looked for and adapter
with a name matching the return value from getContractAdapterName().
However, the test used to determine this was backwards:

    if (contactAdapterName.contains(szAdapterName))

Since contactAdapterName (obtained from getContactAdapterName()) returns a
name of the form  "{GUID}", while szAdapterName (obtained from the list
returned from GetInterfaceInfo()) is of the form "\DEVICE\TCPIP_{GUID}".
Thus, this test never succeeded. Instead of using getContactAdapterName() to
find the adapter by name, I've changed the code to walk the list of adapters
looking for one with the correct IP address (which is how
getContactAdapterName() gets the name in the first place) and then just use
its index directly to call GetPerAdapterInfo().



I've only been able to test the code path used by Windows XP (but same code
should also be used by Windows 2000 and Windows Vista). The code path used
by Windows 98/Me systems (using the GetNetworkParams() function in
iphlpapi.dll) hasn't changed, and I haven't changed
getDNSEntriesFromRegistry() which is used for NT4.

Stephen C. Steel

Attachment: DNS_servers_bug.patch
Description: Binary data

_______________________________________________
sipxtapi-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/

Reply via email to