summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlemens Nanni <klemens@posteo.de>2023-01-07 22:55:26 +0400
committerOlivier CrĂȘte <olivier.crete@ocrete.ca>2023-01-09 18:27:52 +0000
commit63f4962c11312fb1088a7a726592fe6aa5f8022f (patch)
treed507fa7e0f54aecc3c7d657de9bd0444624364c4
parent37f1e243b4814e12a7a1a0f2302012fb6ae5b36c (diff)
Use ifr_ifindex on LinuxHEADmaster
-rw-r--r--agent/interfaces.c13
-rw-r--r--meson.build6
2 files changed, 17 insertions, 2 deletions
diff --git a/agent/interfaces.c b/agent/interfaces.c
index 9133b2c..740d3e2 100644
--- a/agent/interfaces.c
+++ b/agent/interfaces.c
@@ -373,7 +373,7 @@ get_local_ips_ioctl (gboolean include_loopback)
static guint
get_local_if_index_by_addr_ioctl (NiceAddress *addr)
{
-#ifdef HAVE_IFR_INDEX
+#if defined(HAVE_IFR_INDEX) || defined(HAVE_IFR_IFINDEX)
gint sockfd;
gint size = 0;
struct ifreq *ifr;
@@ -417,10 +417,18 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr)
if (!nice_address_equal_no_port (myaddr, addr))
continue;
+#if defined(HAVE_IFR_INDEX)
if (ifr->ifr_index == 0)
+#else
+ if (ifr->ifr_ifindex == 0)
+#endif
continue;
+#if defined(HAVE_IFR_INDEX)
if_index = ifr->ifr_index;
+#else
+ if_index = ifr->ifr_ifindex;
+#endif
break;
}
@@ -430,7 +438,8 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr)
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.");
+ " include ifr_index or ifr_ifindex in the struct ifreq."
+ " Please report the bug.");
return 0;
#endif
}
diff --git a/meson.build b/meson.build
index c644024..e0d2ac1 100644
--- a/meson.build
+++ b/meson.build
@@ -119,10 +119,16 @@ foreach f : ['poll', 'getifaddrs']
endif
endforeach
+# BSD and macOS
if cc.has_member('struct ifreq', 'ifr_index', prefix: '#include <net/if.h>')
cdata.set('HAVE_IFR_INDEX', 1)
endif
+# Linux
+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