Archived

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

Prozak

Sockets: Retrieving my IP

Recommended Posts

Hi all, using Sockets (i''m reading Prima''s Multiplayer Game Programming) how does one retrieve his machine IP address? And what call should one make to know if the machine is connected to internet/intranet ? Thanks for tha help,

[Hugo Ferreira][Positronic Dreams][]

Share this post


Link to post
Share on other sites
quote:
Original post by pentium3id
And what call should one make to know if the machine is
connected to internet/intranet ?


Do you mean like is the modem connected? I think you can determine that, I think it''s buried in the TAPI for Windows.

If you mean, does this computer have an ip route to Internet? Then you have to do something underhanded, like ping a known internet server... or tracert to your website.


Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

"What I see is a system that _could do anything - but currently does nothing !" - Anonymous CEO

Share this post


Link to post
Share on other sites
Look into the IP Helper API. Specifically, the GetIpAddrTable() function to get your valid IP addresses, and GetIfTable to get the status for each given interface.

Share this post


Link to post
Share on other sites
heres some code that gets your local ip address:

    

#include <winsock.h>


#include <iostream.h>

main()
{
hostent* localInfo = gethostbyname(NULL); // get localhost name

in_addr addr;
memcpy(&addr,localInfo->h_addr_list[0],sizeof(in_addr));
cout << inet_ntoa(addr) << endl;
}


Edited by - barazor on December 30, 2001 12:46:01 AM

Share this post


Link to post
Share on other sites