g_network_monitor_base_can_reach: Check for default route after enumerating.
authorMatthew Barnes <mbarnes@redhat.com>
Tue, 19 Feb 2013 16:18:11 +0000 (11:18 -0500)
committerDan Winship <danw@gnome.org>
Wed, 20 Feb 2013 12:33:58 +0000 (07:33 -0500)
Enumerate the GSocketConnectable before checking for a default route.
For some connectable types this will involve a DNS lookup.  This will
elminate false positives for hosts behind a VPN since DNS lookup will
fail if the VPN is not connected.

https://bugzilla.gnome.org/show_bug.cgi?id=694181

gio/gnetworkmonitorbase.c

index 2494ca3..5baf5fd 100644 (file)
@@ -168,10 +168,6 @@ g_network_monitor_base_can_reach (GNetworkMonitor      *monitor,
   GSocketAddressEnumerator *enumerator;
   GSocketAddress *addr;
 
-  if (priv->have_ipv4_default_route &&
-      priv->have_ipv6_default_route)
-    return TRUE;
-
   if (priv->networks->len == 0)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NETWORK_UNREACHABLE,
@@ -188,6 +184,14 @@ g_network_monitor_base_can_reach (GNetworkMonitor      *monitor,
       return FALSE;
     }
 
+  if (priv->have_ipv4_default_route &&
+      priv->have_ipv6_default_route)
+    {
+      g_object_unref (enumerator);
+      g_object_unref (addr);
+      return TRUE;
+    }
+
   while (addr)
     {
       if (G_IS_INET_SOCKET_ADDRESS (addr))