views:

501

answers:

3

How can we get the network interface name (i.e. the one that appears in the "Network connections" dialog) given the device description (i.e. the string that appears in the "Device Properties -> Connect using:" textbox)? We must do it in pure C/C++ language, or through some of the standard command line tools (e.g. netsh, ipconfig...), or a combination of both. We CAN'T use the .NET API, because of deployment problems (the application must run on an XP embedded without .NET Framework). The SDK API GetIfTable and GetIfEntry seem promising, but on our system all the MIB_IFROW fields are filled correctly, except the "wszName" one, that remains uninitialized. Thank you in advance.

A: 

I'll have to double check, but I think this might be in the registry somewhere... I'll get back to this.

hklm/system/currentcontrolset/control/network

might help.

I did not find exactly what i thought I would though, sorry

EDIT This might help too:

http://www.java2s.com/Tutorial/CSharp/0520__Windows/Getthenetworkdevicenamedeviceservicename.htm

specifically: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\

I do not know if this is guaranteed for future, or not "approved" method, but it seems to have the info you need.

Tim
A: 

Your best bet is to use the Win32 API calls known collectively as "IP Helper". That will get you just about all the same information that you could get with a call to "ipconfig" from the CLI.

In particular, I'd start by looking at the "GetAdaptersInfo" function.

And, of course, since this part of the Win32 API, you can use pure C/C++ without needing to parse output from an outside utility.

Brian
The question points out that he used GetIfTable and GetIfEntry, which are both part of the IP Helper API. I have seen the same thing where wszName is left uninitialized, and I think that's the crux of the problem the original poster is having.
krupan
+1  A: 

I was able to do this via the registry. Using GetAdaptersInfo(), which gives an IP_ADAPTER_INFO output, take the AdapterName string. This should be a GUID for the adapter. For (ipv4 at least), under HKLM\SYSTEM\CurrentControlSet\Control\Network{4D36E972-E325-11CE-BFC1-08002BE10318}\{*INSERT GUID HERE*}\Connection, the value Name should contain the "friendly" network name.

Kris Kumler