Commit e1a84135 authored by Ole André Vadla Ravnås's avatar Ole André Vadla Ravnås Committed by Olivier Crête

interfaces: Skip special interfaces on Apple OSes

Including unused utun devices.
parent 5d868c74
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment