From 37f1e243b4814e12a7a1a0f2302012fb6ae5b36c Mon Sep 17 00:00:00 2001 From: Klemens Nanni Date: Sat, 7 Jan 2023 22:35:28 +0400 Subject: [PATCH 1/2] Use ifr_index to fix build on OpenBSD `struct ifreq` from `` has no `ifr_ifindex` on OpenBSD. The canonical member access macro in all BSDs is ``` #define ifr_index ifr_ifru.ifru_index /* interface index */ ``` The existing `g_critical()` message already uses the correct name, so rectify the rest. FreeBSD has `ifr_ifindex` in what appears to be linux-compat code. Found by updating libnice from 0.1.19 to 0.1.20 on OpenBSD/amd64 -current. --- agent/interfaces.c | 6 +++--- meson.build | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/agent/interfaces.c b/agent/interfaces.c index 30944f58..9133b2c7 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_IFINDEX +#ifdef HAVE_IFR_INDEX gint sockfd; gint size = 0; struct ifreq *ifr; @@ -417,10 +417,10 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr) if (!nice_address_equal_no_port (myaddr, addr)) continue; - if (ifr->ifr_ifindex == 0) + if (ifr->ifr_index == 0) continue; - if_index = ifr->ifr_ifindex; + if_index = ifr->ifr_index; break; } diff --git a/meson.build b/meson.build index 5c46425e..c6440240 100644 --- a/meson.build +++ b/meson.build @@ -119,8 +119,8 @@ foreach f : ['poll', 'getifaddrs'] endif endforeach -if cc.has_member('struct ifreq', 'ifr_ifindex', prefix: '#include ') - cdata.set('HAVE_IFR_IFINDEX', 1) +if cc.has_member('struct ifreq', 'ifr_index', prefix: '#include ') + cdata.set('HAVE_IFR_INDEX', 1) endif if cc.has_argument('-fno-strict-aliasing') -- GitLab From 63f4962c11312fb1088a7a726592fe6aa5f8022f Mon Sep 17 00:00:00 2001 From: Klemens Nanni Date: Sat, 7 Jan 2023 22:55:26 +0400 Subject: [PATCH 2/2] Use ifr_ifindex on Linux --- agent/interfaces.c | 13 +++++++++++-- meson.build | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/agent/interfaces.c b/agent/interfaces.c index 9133b2c7..740d3e2b 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 c6440240..e0d2ac1f 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 ') cdata.set('HAVE_IFR_INDEX', 1) endif +# Linux +if cc.has_member('struct ifreq', 'ifr_ifindex', prefix: '#include ') + cdata.set('HAVE_IFR_IFINDEX', 1) +endif + if cc.has_argument('-fno-strict-aliasing') add_project_arguments('-fno-strict-aliasing', language: 'c') endif -- GitLab