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

interfaces: Only use `ifr_ifindex` if OS supports it

This fixes compilation on e.g. macOS and FreeBSD, where it is missing.
parent 2d5ab516
...@@ -373,6 +373,7 @@ get_local_ips_ioctl (gboolean include_loopback) ...@@ -373,6 +373,7 @@ get_local_ips_ioctl (gboolean include_loopback)
static guint static guint
get_local_if_index_by_addr_ioctl (NiceAddress *addr) get_local_if_index_by_addr_ioctl (NiceAddress *addr)
{ {
#ifdef HAVE_IFR_IFINDEX
gint sockfd; gint sockfd;
gint size = 0; gint size = 0;
struct ifreq *ifr; struct ifreq *ifr;
...@@ -427,6 +428,11 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr) ...@@ -427,6 +428,11 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr)
close (sockfd); close (sockfd);
return if_index; return if_index;
#else
g_critical ("getifaddrs() should not fail on a platform that doesn't"
" include ifr_index in the struct ifreq. Please report the bug.");
return 0;
#endif
} }
#ifdef HAVE_GETIFADDRS #ifdef HAVE_GETIFADDRS
......
...@@ -119,6 +119,10 @@ foreach f : ['poll', 'getifaddrs'] ...@@ -119,6 +119,10 @@ foreach f : ['poll', 'getifaddrs']
endif endif
endforeach endforeach
if cc.has_member('struct ifreq', 'ifr_ifindex', prefix: '#include <net/if.h>')
cdata.set('HAVE_IFR_IFINDEX', 1)
endif
if cc.has_argument('-fno-strict-aliasing') if cc.has_argument('-fno-strict-aliasing')
add_project_arguments('-fno-strict-aliasing', language: 'c') add_project_arguments('-fno-strict-aliasing', language: 'c')
endif endif
......
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