Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How to get adress from adapters?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Icebone1000   Members   -  Reputation: 1125

Like
0Likes
Like

Posted 18 March 2011 - 12:48 PM

Returning adresses with getaddrinfo is kind a blind thing..even specifying AI_PASSIVE and the computer name, I cant know where are the addresses Im interested on..

More specific, executing ipconfig /a//, I can see 2 titles that Im interested on: Wireless LAN adapter Wireless Network Conection and Ethernet Adapter Local Area Connection...In the case, I would test to see the one who doesnt have the media disconnected state, and get its IP...With getaddrinfo the first address on the list is my virtual box ip =__=, the thing I use to trade files with the win2000 I have installed on virtual box...

I want know if theres a way I can do this straight from the info I have from getaddrinfo, without using the ip helpers apis..How can I know the networking availability on the addresses returned with a hostname?

Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5547

Like
1Likes
Like

Posted 18 March 2011 - 03:56 PM

Returning adresses with getaddrinfo is kind a blind thing..even specifying AI_PASSIVE and the computer name, I cant know where are the addresses Im interested on..

More specific, executing ipconfig /a//, I can see 2 titles that Im interested on: Wireless LAN adapter Wireless Network Conection and Ethernet Adapter Local Area Connection...In the case, I would test to see the one who doesnt have the media disconnected state, and get its IP...With getaddrinfo the first address on the list is my virtual box ip =__=, the thing I use to trade files with the win2000 I have installed on virtual box...

I want know if theres a way I can do this straight from the info I have from getaddrinfo, without using the ip helpers apis..How can I know the networking availability on the addresses returned with a hostname?


What you want isn't, strictly speaking, well defined. A machine may have zero or more physical interfaces. Each interface may have zero or more virtual interfaces. Each virtual interface may have zero or one IPv4 address, zero or more IPv6 addresses, and zero or more default gateways.

You could enumerate all the interfaces using OS-specific functions (such as Windows Management and Instrumentation), and then ask for the IPv4 address for each (if present), and then filter addresses by certain criteria:
- if it has no default gateway, it's probably not interesting
- if it has an address in the 10.x, 192.168.x or 172.16.x subnet ranges, it's probably not interesting unless you only want to talk to a LAN

Unfortunately, for 99.999% of all home computers, this will filter out all interfaces, because the NAT gateway/router will re-write your address to some public address, to be visible from the outside. To get around this, you need to use a NAT introducer. The FAQ has more information.
enum Bool { True, False, FileNotFound };

#3 Zimans   Members   -  Reputation: 233

Like
0Likes
Like

Posted 21 March 2011 - 08:21 AM

WMI and the IPHLPAPI are the only two native API methods for retrieving IP information. WMI is hit or miss on a good day, so I would avoid it. It's also COM, so unless you are a COM guru, or you are working in a managed language, that's another reason to avoid it.

To query a list of adapters on the local system I use GetAdaptersAddresses(). This function will return a linked list of IP_ADAPTER_ADDRESSES structures. ( See the MSDN page about allocating the buffer for these structures ). The IP_ADAPTER_ADDRESSES structure has a member named friendlyname that is the name you see when you bring up network connections. This is the only function call / structure I have encountered that contains this information. The adaptername is the GUID identifying the adapter on the system. The rest of the members are somewhat self explanatory, and explained decently well on MSDN.

Even with the IPHLPAPI there are some other caveats that I have encountered dealing with network interfaces: 1) If the interface is disabled, then it will not be included in the list. 2) If the interface is disconnected ( cable unplugged ) then it will not return any IP information even if it is statically configured. To get the current static configuration when the adapter is disconnected, use the registry. I've actually found that the registry is the most reliable source of information for getting an adapters configuration. 3) If you need netmask, then you need to go to a different API ( or get it from the registry ). For some reason netmask was omitted from GetAdapterAddresses() / IP_ADAPTER_ADDRESSES. 4) If you need to change the IP configuration of an adapter, there is no native API. Use CreateProcess and netsh.exe. WMI can configure an interface, but cannot configure an interface that is disconnected.

To get the media state, I use GetIfEntry().

--Z




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS