> Further there can be situations were Wifi network is available but 
> Internet connection / link is not working.

I am dealing with such issues in my applications, although they are running on 
embedded devices, not on Windows, but the problem is similar.
For me, HTTP is the most important service, so I check the "connectivity" very 
similar as Daniel answered below.

Only in my "connectivity" test I use a full GET and download a small resource 
to make sure link can actually deliver data.
You can, for instance, read page from google.com, which is not that large.

The full GET, in my case, includes checking of name resolution, connection 
establishment and data flow phases.
If all these phases are good, then I consider "Internet connectivity" good and 
ready for HTTP-based applications.

If your use dual-stack libcurl, then you probably will need to run two 
"connectivity" tests - one for "IPv4 only" mode and the other for dual-stack 
"IPv6/IPv4".
That's because you may have issues with IPv6 when IPv4 is working well.

In this case, you have only "IPv4 connectivity" and thus need to make your 
dual-stack applications use "IPv4 only" mode.
(Of course, if you decide that your applications always use IPv4, then you need 
to run only "IPv4 connectivity" tests and explicitly set "IPv4 only" mode in 
your apps).

A few notes about timeouts.
I recommend setting timeouts for "connectivity" tests at least as big as 
several seconds. 
That's because for high-latency links it may take a few seconds to perform name 
resolutions and establish a connection.

My "rule of thumb" is to use 2 x DNS timeout, which translates to 10s timeout 
in my environment.
I use such values, because in typical setups I face there are two DNS servers 
provided by ISP, and the first one may be overloaded and not responding.

Thanks,
Dmitry Karpov

-----Original Message-----
From: curl-library <[email protected]> On Behalf Of Daniel 
Stenberg via curl-library
Sent: Tuesday, November 22, 2022 1:24 AM
To: Dipak B via curl-library <[email protected]>
Cc: Daniel Stenberg <[email protected]>
Subject: [EXTERNAL] Re: How to check if machine has network connectivity using 
libcurl api reliably?

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.

-- 

  / daniel.haxx.se
  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
  | https://curl.se/support.html
--
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html

Reply via email to