Archived

This topic is now archived and is closed to further replies.

Local IP's

This topic is 5179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can i enumerate all the IP''s on a local machine? I am using sockets and getsockname but it returns 0.0.0.0 for the server as it is listening on all ip''s but i want to list all the ip''s.

Share this post


Link to post
Share on other sites
look at gethostbyname(). Here''s a fragment that''s putting them into a tooltip


//

// List Name/IP addresses for this server

//

const int cnHostname = 1024; // should be plenty big

char szHostname[cnHostname];
string sTooltip;
gethostname( szHostname, cnHostname );
struct hostent* pHostEnt = gethostbyname( szHostname );

//

// The address(es) are in an array that is null terminated

//

int i = 0;
struct in_addr** ppAddr = 0;
for ( ppAddr = (struct in_addr**)pHostEnt->h_addr_list; *ppAddr; ppAddr++ )
{
if ( i++ != 0 ) // on second and later...

sTooltip += "\n";
sTooltip += string(inet_ntoa( **ppAddr ));
}

Share this post


Link to post
Share on other sites