curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: How to check if machine has network connectivity using libcurl api reliably?

From: David Woodhouse via curl-library <curl-library_at_lists.haxx.se>
Date: Tue, 22 Nov 2022 14:04:43 +0000

On Tue, 2022-11-22 at 10:23 +0100, Daniel Stenberg via curl-library wrote:
> On Tue, 22 Nov 2022, Dipak B via curl-library wrote:
>
> > How can an Windows application integrated with libcurl find out reliably
> > and quickly if the machine has any kind of network connectivity?
> >
> > Further there can be situations were Wifi network is available but Internet
> > connection / link is not working.
> >
> > In such a situation how does one find if Internet connection is available
> > using libcurl?
>
> If you by "network connectivity" mean "connectivity to a known HTTP server you
> have reasonable expectations to exist and respond", then you can just do a
> HEAD request to that server with a reasonably short timeout and check that it
> succeeds.
>
> If you want to check something more fine-grained than so, then maybe libcurl
> is not the right answer for you. libcurl is a transfer library, not a network
> connectivity check library.

Indeed. You can *build* a network connectivity check with libcurl, but
it doesn't do that for you.

You'd probably want to start by making HTTP requests over IPv6 and
Legacy IP to a known server. Detect if your request is diverted to a
captive portal, and if so, maybe check for a WISPr XML fragment in what
you get back that will tell you more about the captive portal you're
behind.

Your code can then report whether you have full connectivity, legacy
only connectivity, or if you're behind a portal.

But connectivity isn't all-or-nothing. You might manage to connect to
the test URLs, but *not* to the service you're actually trying to use.
Or vice versa, if your device was only granted egress permission for
the services it actually needs.

The best option is usually just to try, and handle failures gracefully.


-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
  • application/pkcs7-signature attachment: smime.p7s
Received on 2022-11-22