Detecting when an internet connection is active
-
I need to know how I can detect whether the user currently has an active internet connection. Can anyone help? I've tried InetIsOffline(), but that only determines if the user is in online or offline mode, not if the actual connection is currently active.
-
I need to know how I can detect whether the user currently has an active internet connection. Can anyone help? I've tried InetIsOffline(), but that only determines if the user is in online or offline mode, not if the actual connection is currently active.
-
I need to know how I can detect whether the user currently has an active internet connection. Can anyone help? I've tried InetIsOffline(), but that only determines if the user is in online or offline mode, not if the actual connection is currently active.
bool IsConnectedToInternet(void)
{
DEBUGF("IsConnectedToInternet");WORD wVersionRequested = MAKEWORD(1, 1); WSADATA wsaData; TCHAR hostaname\[1000\]; int hostname\_size = sizeof(hostaname); bool connected = false; if (WSAStartup(wVersionRequested, &wsaData) != 0) { DEBUGF("WSAStartup Failed (%i.%i) %s", wsaData.wHighVersion, wsaData.wVersion, wsaData.szDescription); return connected; } if (gethostname(hostaname, hostname\_size) != SOCKET\_ERROR) { struct hostent FAR \*h = gethostbyname(hostaname); if (h != NULL) { // cif ip=127.0.0.1 then we are not connected DEBUGF("gethostname %s %s", h->h\_name, h->h\_addr\_list\[0\]); if (strncmp(h->h\_addr\_list\[0\], "\\x7f\\x0\\x0\\0x1", 4)!=0) { connected = true; } } } else { DEBUGF("gethostname Failed"); } WSACleanup(); return connected;
}
Todd Smith