Checking Internet availability for two interfaces

Viewed 146

I am trying to detect internet availability of an access point(AP) that was connected. My implementation consists of using LwIP Stack and also two network interfaces. The scenario is described below:

Case 1: Ping Successful

  1. Interface 0 connects to AP1 (with internet)
  2. Interface 1 connects to AP2 (without internet)
  3. ping www.google.com
  4. LwIP stack uses default network interface which is Interface 0 to ping google.

In this case, ping will be successful since I have internet connection on AP1 but if the connection is reversed, ping will fail because it uses the default network interface.

Case 2: Ping Fail

  1. Interface 0 connects to AP2 (without internet)
  2. Interface 1 connects to AP1 (with internet)
  3. ping www.google.com
  4. LwIP stack uses default network interface which is Interface 0 to ping google.

Is there anyway that I can detect or check for internet connection before deciding which interface to use to send the ping packets?

From what I observed on my laptop by connecting the Wi-Fi and Ethernet, it can ping successfully in both cases. Please help thank you.

BR Sue~

1 Answers

I know you asked this a month ago...

LWIP directs all outgoing traffic to the default_netif. The only way around this is to dynamically change the default_netif or send directly on a particular netif.

A possible solution for determining if internet is available on each network interface would be for each netif, set it as the default netif with netifapi_netif_set_default, then do the ping.

Alternately you could manually send something like a DNS resolution request UDP packet directly on each network interface and check for a response.

Related