interfaces: Skip special interfaces on Apple OSes
authorOle André Vadla Ravnås <oleavr@gmail.com>
Mon, 19 Apr 2021 19:05:51 +0000 (21:05 +0200)
committerOlivier Crête <olivier.crete@collabora.com>
Tue, 20 Apr 2021 00:47:14 +0000 (20:47 -0400)
Including unused utun devices.

agent/interfaces.c
meson.build

index ba48644..67f260c 100644 (file)
@@ -69,6 +69,9 @@
 #endif
 
 #include <net/if.h>
+#ifdef HAVE_NET_IF_MEDIA_H
+ #include <net/if_media.h>
+#endif
 #include <arpa/inet.h>
 
 #endif /* G_OS_UNIX */
@@ -374,6 +377,7 @@ nice_interfaces_get_local_ips (gboolean include_loopback)
 {
   GList *ips = NULL;
   struct ifaddrs *ifa, *results;
+  int sockfd = -1;
   GList *loopbacks = NULL;
 #ifdef IGNORED_IFACE_PREFIX
   const gchar **prefix;
@@ -411,6 +415,24 @@ nice_interfaces_get_local_ips (gboolean include_loopback)
       continue;
 #endif
 
+#ifdef HAVE_NET_IF_MEDIA_H
+    {
+      struct ifmediareq ifmr;
+
+      if (sockfd == -1)
+        sockfd = socket (AF_INET, SOCK_DGRAM, 0);
+
+      memset (&ifmr, 0, sizeof (ifmr));
+      g_strlcpy (ifmr.ifm_name, ifa->ifa_name, sizeof (ifmr.ifm_name));
+
+      if (ioctl (sockfd, SIOCGIFMEDIA, &ifmr) == 0 &&
+          (ifmr.ifm_status & IFM_AVALID) != 0 &&
+          (ifmr.ifm_status & IFM_ACTIVE) == 0) {
+        continue;
+      }
+    }
+#endif
+
     /* Convert to a string. */
     addr_string = sockaddr_to_string (ifa->ifa_addr);
     if (addr_string == NULL) {
@@ -465,6 +487,9 @@ nice_interfaces_get_local_ips (gboolean include_loopback)
       ips = add_ip_to_list (ips, addr_string, FALSE);
   }
 
+  if (sockfd != -1)
+    close (sockfd);
+
   freeifaddrs (results);
 
   if (loopbacks)
index 8416f88..e1d525e 100644 (file)
@@ -91,7 +91,7 @@ cdata.set('NICEAPI_EXPORT', true,
   description: 'Public library function implementation')
 
 # headers
-foreach h : ['arpa/inet.h', 'net/in.h', 'netdb.h', 'ifaddrs.h', 'unistd.h']
+foreach h : ['arpa/inet.h', 'net/in.h', 'net/if_media.h', 'netdb.h', 'ifaddrs.h', 'unistd.h']
   if cc.has_header(h)
     define = 'HAVE_' + h.underscorify().to_upper()
     cdata.set(define, 1)