Jump to content
  • Advertisement

Archived

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

jonbell

Local IP's

This topic is 5461 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
Advertisement
Guest Anonymous Poster
"winipcfg"

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!