Link to home
Start Free TrialLog in
Avatar of sads
sads

asked on

finding address of NICs DNS servers

How do I programically find the address's of the configured DNS servers in winsock 1.1.  I can find all other relavent info using GetAdaptersInfo. I'm using VC++ 6.

Thanks in advance..

Chris
Avatar of jkr
jkr
Flag of Germany image

You could use 'GetAdaptersInfo()' from the IP helper API: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tcpip/tcpip_6tpr.asp

An overview can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tcpip/ipover_394j.asp ("Managing Network Adapters")
Avatar of jhance
jhance

The problem with the IPHLPAPI.DLL is that it's not available on your platform.  Since you're using WINSOCK 1.1 I'm assuming it's Win95 and you don't have access to it.  

The best approach in this instance is to use the WINIPCFG with its output directed to a file.  Then you can parse the file for the DNS server information.

Use something like:

system("WINIPCFG /ALL /BATCH");

will dump the output to WINIPCFG.OUT.  There you can easily find the DNS server(s) for the system.  In WINSOCK 1.1 there is only global DNS setting that is shared by all network adapters on the system.
Alternatively, on WINSOCK 1.1 systems you can locate the DNS server(s) from the registry at:

HLM\System\CurrentControlSet\Services\VxD\MSTCP and the NameServer value you'll find there.
Avatar of sads

ASKER

I have asked this question twice (by accident). Refer to the other question. Sorry, its been a bad day.
Hum, why are you trying to delete this one as it contains a solution that works on XP (as you mentioned that in the other Q)? See my above comment...
Avatar of sads

ASKER

I am already using that call (see the question).  It gets me everthing I need, but it does not return the DNS entries (unless its well hidden).  Thats what I'm looking for, the DNS entries.

I somehow asked this question 2 times (and got **** for it).  So I just picked one to delete and this was it.

Thanks

Chris
>>unless its well hidden

Not really :o)

See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tcpip/tcpip_6ptf.asp ("IP_ADAPTER_DNS_SERVER_ADDRESS")

And it seems that it was my fault, I thought of 'GetAdaptersAddresses()' (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tcpip/tcpip_2joz.asp), but wroute '...AdapterInfo()' :o)
Avatar of sads

ASKER

Does this not need a define (see the h file) that requires winsock 2?  
I don't have the .h file here at the moment, but the MS docs are pretty clear:

Requirements
  Windows NT/2000/XP: Included in Windows XP and Windows .NET Server.
  Windows 95/98/Me: Unsupported.
  Header: Declared in Iphlpapi.h.
  Library: Use Iphlpapi.lib.
Avatar of sads

ASKER

I have tried the below, but again winsock2....



#ifdef _WINSOCK2API_

//
// The following functions require Winsock2.
//

DWORD
WINAPI
GetAdaptersAddresses(
    ULONG Family,
    DWORD Flags,
    PVOID Reserved,
    PIP_ADAPTER_ADDRESSES pAdapterAddresses,
    PULONG pOutBufLen
    );

#endif

DWORD
WINAPI
GetPerAdapterInfo(
    ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen
    );

DWORD
Hmmm.. so, why don't you just

#define _WINSOCK2API_

before including the header file?
Avatar of sads

ASKER

Yup I tried that, then went full out on winsock2 and got shot down by the implementation team as to not wanting to update to winsock2 on the older 98 machines.  So I went back to the drawing board thinking there must be source for a nslookup etc etc, but so far that two has come up empty...

Thanks for you input so far, It did make me go back to see if I missed anything...
ASKER CERTIFIED SOLUTION
Avatar of cookre
cookre
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sads

ASKER

Thanks very much.

Chris
As promised, for boxes set to get DNS via DHCP:

2K:
Value DhcpNameServerList

HKLM\System\CurrentControlSet\Services\TcpIp\Parameters\Interfaces\<Class>
value DhcpNameServer

This ClassID is the <Class> from <Service>_<Class> mentioned above.

NT:
Values DhcpNameServer and DhcpNameServerBackup


95:
No option for DNS via DHCP
Avatar of sads

ASKER

Very cool

Thanks a lot.  I appreciate the effort.

Chris