summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOle André Vadla Ravnås <oleavr@gmail.com>2022-11-04 20:56:08 +0100
committerOlivier Crête <olivier.crete@ocrete.ca>2023-01-06 22:30:15 +0000
commit0fc589f3dc534ac514f48f98be42f1393d625aad (patch)
tree3cc3650c67246014f2ef5cad5f65c141bbd715b9
parent2d5ab5168c8f08d1d5aa73aa869663e46c91b783 (diff)
downloadlibnice-0fc589f3dc534ac514f48f98be42f1393d625aad.tar.gz
interfaces: Only use `ifr_ifindex` if OS supports it
This fixes compilation on e.g. macOS and FreeBSD, where it is missing.
-rw-r--r--agent/interfaces.c6
-rw-r--r--meson.build4
2 files changed, 10 insertions, 0 deletions
diff --git a/agent/interfaces.c b/agent/interfaces.c
index 4cd988c..3590e0d 100644
--- a/agent/interfaces.c
+++ b/agent/interfaces.c
@@ -373,6 +373,7 @@ get_local_ips_ioctl (gboolean include_loopback)
static guint
get_local_if_index_by_addr_ioctl (NiceAddress *addr)
{
+#ifdef HAVE_IFR_IFINDEX
gint sockfd;
gint size = 0;
struct ifreq *ifr;
@@ -427,6 +428,11 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr)
close (sockfd);
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
diff --git a/meson.build b/meson.build
index 5904367..ad7ae6e 100644
--- a/meson.build
+++ b/meson.build
@@ -119,6 +119,10 @@ foreach f : ['poll', 'getifaddrs']
endif
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')
add_project_arguments('-fno-strict-aliasing', language: 'c')
endif