brianbraunstein
asked on
Getting Network Interface Name using IP Helper or similar library
I am trying to get the "friendly" interface names for the network interfaces on a windows machine. What I need is exactly the list of names that are in the "Network and Dial-up Connections" control panel. I have tried getting the information from the IP_ADAPTER_INFO and MIB_IFROW structures but neither of these provide the name I need. I can get at the name of the physical device but not the "friendly" name. There is a field in the MIB_IFROW that doesn't seem to work properly that may be exactly what I'm looking for. It is the MIB_IFROW.wszName field. I always get this field always containing 0s, NULL value. Is there some trick to using this? I'm using windows 2000 but this also needs to run on XP and CE in the future. Is there some other library similar to IP Helper that has a function in it to get this data that I should use? Do I need to get the name differently for normal connections versus Dial up network connections, for example using MprXxx or RasXxx functions? PS, this is my first time on this site, what are the ways I can get more points.
ASKER
Thanks a bunch Dan. I ran across that function and the RasEnumConnections(), which is useful for my specific purpose. But the problem with both these functions is I cannot find a field in them that will map to the structures returned by GetAdaptersInfo() and GetIfTable(). In both of these functions the structure's returned, IP_ADAPTER_INFO and MIB_IFROW, have a field called Index or dwIndex, which is the index of the interface they correspond to. Am I going to have to do some silly work around to achieve my goal, whic is to have a mapping between MIB_IFROW/IP_ADAPTER_INFO structures and RASCONN or RASENTRY structures.
You didn't mention it, so I have to ask: Did you check MIB_IFROW.bDescr ? Often, the "description" is the text that is displayed to users.
You can get a list of the objects in the
Control Panel/Network and Dial-up Connections
shell folder by using the
IShellFolder::EnumObjects
Is that what you want? Not knowing your actual goal (that is, *why* you want these names) hampers me in my research.
-- Dan
You can get a list of the objects in the
Control Panel/Network and Dial-up Connections
shell folder by using the
IShellFolder::EnumObjects
Is that what you want? Not knowing your actual goal (that is, *why* you want these names) hampers me in my research.
-- Dan
ASKER
Thanks for all your help so far Dan. I'm looking into the IShellFolder documentation right now. I just wanted to post my goal. Basically, if I need to figure out how to create something exactly like ipconfig.exe, because what I'm trying to do follows directly from that. The ipconfig.exe example in the Platform SDK samples doesn't help because it doesn't retreive this "friendly" name. The real ipconfig.exe will display the "friendly" name along with the ip addresses, gateways, etc. Sorry for not stating that more clearly.
Thanks again!
Thanks again!
ASKER
I guess I should also say more boldly that I need something EXACTLY like ipconfig. So it works with dial up networknig connections, ethernet connections, wireless, bluetooth (which uses dial up networking), etc. I need to get the IP, gateway for all of these AS WELL AS THE INTERFACE INDEX, like in MIB_IFROW.dwIndex. The MIB_IFROW.bDescr doesn't contain the "friendly" name I'm looking for. I really wish it did! One way I could do what I'm trying to do is get the RASENTRY structs from RasEnumEntries(), then map the MIB_IFROWs and IP_ADAPTER_INFOs to their corresponding RASENTRY structs using the IP Address fields in both. This seems a bit inefficient to me though but I've been plugging away at this problem for a long long time so I may have to end up doing that.
Thanks.
Thanks.
ASKER
The "inefficient workaround" that I mentioned above doesn't work. I just tried it. The RasGetEntryProperties function returns an RASENTRY struct. The RASENTRY.ipaddr field in this is the ip address that you set for the connection if not using DHCP. It is not the ip address the connection is currently using. Bummer. This is the most annoying problem ever! Why doesn't microsoft provide the actual code for ipconfig.exe instead of a scaled down ipconfig? Grrr!!! Anyways, I hope you are having more luck than me.
Thanks,
Brian
Thanks,
Brian
Where did you get the "scaled down" ipconfig source code. That would give me a starting point.
-- Dan
-- Dan
ASKER
If you have the microsoft platform sdk installed with samples the IPConfig sample is at Program Files\Microsoft SDK\Samples\netds\IPHelp\I PConfig If you do not have this installed, which I imagine you totally do...but yeah if you don't I'll put it up on my server at
http://bristyle.com/IPConfigSample.zip
My latest attempts were to use GetAdaptersAddresses() function, which returns the IP_ADAPTERS_ADDRESSES struct. But this didn't work because it's not supported on windows 2000 according to the SDK documentation. And according to how it didn't work when I tried anyways in hopes that it would work. If you help me figure this out, then if I had 5 bazillion points I'd so give them to you :) Too bad I don't since I just found out about this site.
Anyways...
Thanks,
Brian
http://bristyle.com/IPConfigSample.zip
My latest attempts were to use GetAdaptersAddresses() function, which returns the IP_ADAPTERS_ADDRESSES struct. But this didn't work because it's not supported on windows 2000 according to the SDK documentation. And according to how it didn't work when I tried anyways in hopes that it would work. If you help me figure this out, then if I had 5 bazillion points I'd so give them to you :) Too bad I don't since I just found out about this site.
Anyways...
Thanks,
Brian
There is a clue... The actual IpConfig.exe (in my WinNT/system32 dir) may be calling an undocumented function
NhGetInterfaceNameFromGuid
since it is exported from IPHLPAPI.Dll
I can't find out anything about this fn, but it certainly seems like a candidate as to how IpConfig.Exe is locating the "friendly name" that you seek. It may be possible to figure out the parameters and returns for that fn...
Some other clues are in the MprAdminXxxxx API funcs in Routine and Remote Access Services.
I noticed that if you call RasGetEntryProperties after calling RasEnumeEntries, you can get back a GUID, but I can't make it match with anything.
=--=-==-=-=-=-=-=-=-=-=-=- =-
Since you brought up points... 75 is pretty low for such a complicated question. I'm pretty sure that you can purchase additional points via this link:
https://www.experts-exchange.com/jsp/buyPoints.jsp
but I've never done it...
-- Dan
NhGetInterfaceNameFromGuid
since it is exported from IPHLPAPI.Dll
I can't find out anything about this fn, but it certainly seems like a candidate as to how IpConfig.Exe is locating the "friendly name" that you seek. It may be possible to figure out the parameters and returns for that fn...
Some other clues are in the MprAdminXxxxx API funcs in Routine and Remote Access Services.
I noticed that if you call RasGetEntryProperties after calling RasEnumeEntries, you can get back a GUID, but I can't make it match with anything.
=--=-==-=-=-=-=-=-=-=-=-=-
Since you brought up points... 75 is pretty low for such a complicated question. I'm pretty sure that you can purchase additional points via this link:
https://www.experts-exchange.com/jsp/buyPoints.jsp
but I've never done it...
-- Dan
ASKER
Looks like we're both stuck now. Dang it. Fortunately I go to and work for UCSD, and apparently our computer science department is has a close relationship with Microsoft. I'll talk to someone here and see if I can get ahold of the documentation on that function.
Thanks anyways,
Brian
Thanks anyways,
Brian
Maybe what are you looking for is located in the Registry under the key
HKEY_LOCAL_MACHINE\SYSTEM\ CurrentCon trolSet\Co ntrol\Netw ork
HKEY_LOCAL_MACHINE\SYSTEM\
ASKER
Thanks for the suggestion. I've already been through the registry a bunch. I searched for each of the GUIDs that I could get from the IP Helper returned information. There was no consistent location between normal network connections and RAS connections. Plus the GUIDs I got from RasEnumConnections were not even in the registry at all, I believe these GUIDs are current-connection specific and therefor only stored in memory. Thanks anyways though! What I've been trying to do is step through the disassembly of ipconfig.exe using the VC++ debugger. This is incredibly painful. Hopefully the people at UCSD will come through and be able to pull their strings at Microsoft for me.
Thanks again,
Brian Braunstein
Thanks again,
Brian Braunstein
>>What I've been trying to do is step through the disassembly of ipconfig.exe using the VC++ debugger.
If you can find the call to
NhGetInterfaceNameFromGuid
then it should be pretty straightforward to figure out the parameters.
-- Dan
If you can find the call to
NhGetInterfaceNameFromGuid
then it should be pretty straightforward to figure out the parameters.
-- Dan
ASKER
I'm not the super hardcore genius that you are unfortunately. Finding the call is pretty annoying for me, and once I do find it, I'm afraid it will be very difficult for me to figure out what is going on since assebly from a disassembler isn't exactly documented. I was thinking maybe I could replace IPHlpApi.dll with my own version, put a variable argument for the parameter to the NhGetetc... function, and just print out 5 or 10 integers in hex assuming that the arguments were either pointers or 32 bit values of some sort. Then from these hex value I could figure out what these things being passed are, heap memory, stack memory, a number, etc... Then do printfs or MessageBoxs for the pointers assuming they are string pointers, then assuming integer pointers to see what they contain. The only problem is it seems windows really really doesn't like having a messed up IpHlpApi.dll in there and it would be really annoying to export all the IP Helper functions. I was thinking maybe I'll put my own fake dll and a copy of ipconfig.exe in a seperate folder and then maybe ipconfig.exe will use my fake dll instead of the system folder one, and my system doesn't get screwed up that way. Either that or the CS department guess will get those Microsoft strings pulled for me before I have time to try that...lets hope for the second one. I'LL BE SURE TO POST THE USAGE FOR THIS FUNCTION IF THEY GET IT FOR ME! MUHAHAH!
Brian Braunstein
Brian Braunstein
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
https://www.experts-exchange.com/questions/20556648/RasEnumEntries-problem.html
It returns the RAS names. On my system it returns "NetZero" and "MyTestConn" (exactly as in the Control Pnael), but does not return "Local Area Connection" or "Make new connection"
-- Dan