views:

46

answers:

2

I want to generate the list of IP addresses on the local machine using C++. I looked at boost and it doesn't seem to have any function to do so.

I need this because I want to see if the host name/IP address entered by the user is for the local machine.

+1  A: 

I want to see if the host name/IP address entered by the user is for the local machine.

In general, you cannot do that. There could be any number of host names registered for the local machine. You could try to open a socket and see if ends up at yourself though.

Billy ONeal
Would it be possible if the machine has only one IP Address or hostname?
jobless
@jobless: Who defines the IP address of the machine? Not the host itself -- several machines in between the host and any potential target get to look at the packets -- and usually there's at least one NAT/NAPT type device which changes the IPs in the packets somewhere along the line.
Billy ONeal
@Billy I understand that the machine IP is not defined by the host. But I am just looking for the non loopback address that the interface has been configured to use.
jobless
A: 

If you are looking for portable solution, try ACE library. This library provide cross-platform functionality for network applications development.

Alexander Stavonin