cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Connected ?

From: Darrick Brown <dbrown_at_macromedia.com>
Date: Mon, 14 Jul 2003 13:40:06 -0700

The Win32 info can be found in Allen Weng's famous usenet post:

http://www.ndis.com/faq/inetactive.txt

Regardless of platform/OS, the bottom line is that it is extremely difficult to determine network connectivity without actually attempting a network operation. The only way to be sure you have a network connection is to contact a known host and get a response (ping, DNS lookup, HTTP get, etc.), which in itself is unreliable (host could be down, network lag, lost connections, routing errors...). Some hardware/OS may have a way to detect the physical connection of a cable and know if it has a carrier signal. But beyond that, it's anyone's guess if that physical layer will actual be able to transmit/receive data.

Network connections are like electrical outlets. You don't know if it's live until you try it.

 - Darrick

-----Original Message-----
From: Michael Roberts [mailto:michael_at_vivtek.com]
Sent: Monday, July 14, 2003 11:23 AM
To: curl-library_at_lists.sourceforge.net
Subject: Re: Connected ?

Is there a list of "ways to figure out connectedness" for various OS's? That'd be a pretty interesting new feature for libcurl: a system-independent way of determining connectivity. People ask about it often enough.

Michael

Andrew Francis wrote:

On Mon, Jul 14, 2003 at 10:37:41AM +0100, Paul Johnson wrote:
  
Fair point. I'm on win32 trying to talk to a unix server across an internet
connection. curl has initalised successfully and returned with no errors,
but I need to make my own program stop right there if an auto-dial flag
isn't set and theres no internet connection.
    

Take a look at InternetGetConnectedState and InternetDial, in
<wininet.h>. You want something along these lines:

DWORD inetInfo;
if(InternetGetConnectedState(&inetInfo, 0) == FALSE) {
        if(!weAreAllowedToConnect)
                bombout(); // not connected and not allowed to fix that

        if(InternetDial(0, 0, 0, &inetInfo, 0) != ERROR_SUCCESS)
                bombout(); // we tried to dial up but couldn't
 }

I've pretty much paraphrased this from some source I have lying around
but I wrote it eons ago and don't remember what all of those zeroes mean,
so I wouldn't recommend using this blindly without going to the docs first.

You want to do this _before_ initialising WinSock. (I believe
curl_easy_init() takes care of that these days, so do this before
hitting curl).

Cheers

  

-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1
Received on 2003-07-14