Sockets: Retrieving my IP
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,
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
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.
That will tell you if there''s a default route or not, but it won''t tell you if you actually have a route out onto the internet... (think LAN + Proxy)
error..
[Hugo Ferreira][Positronic Dreams][]
"Research is what I''m doing when I don''t know what I''m doing. "
- Wernher Von Braun (1912-1977)
heres some code that gets your local ip address:
Edited by - barazor on December 30, 2001 12:46:01 AM
#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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement