Archived

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

Sockets: Retrieving my IP

This topic is 5825 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

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
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