Commit 63f4962c authored by Klemens Nanni's avatar Klemens Nanni Committed by Olivier Crête

Use ifr_ifindex on Linux

parent 37f1e243
...@@ -373,7 +373,7 @@ get_local_ips_ioctl (gboolean include_loopback) ...@@ -373,7 +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_INDEX #if defined(HAVE_IFR_INDEX) || defined(HAVE_IFR_IFINDEX)
gint sockfd; gint sockfd;
gint size = 0; gint size = 0;
struct ifreq *ifr; struct ifreq *ifr;
...@@ -417,10 +417,18 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr) ...@@ -417,10 +417,18 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr)
if (!nice_address_equal_no_port (myaddr, addr)) if (!nice_address_equal_no_port (myaddr, addr))
continue; continue;
#if defined(HAVE_IFR_INDEX)
if (ifr->ifr_index == 0) if (ifr->ifr_index == 0)
#else
if (ifr->ifr_ifindex == 0)
#endif
continue; continue;
#if defined(HAVE_IFR_INDEX)
if_index = ifr->ifr_index; if_index = ifr->ifr_index;
#else
if_index = ifr->ifr_ifindex;
#endif
break; break;
} }
...@@ -430,7 +438,8 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr) ...@@ -430,7 +438,8 @@ get_local_if_index_by_addr_ioctl (NiceAddress *addr)
return if_index; return if_index;
#else #else
g_critical ("getifaddrs() should not fail on a platform that doesn't" 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; return 0;
#endif #endif
} }
......
...@@ -119,10 +119,16 @@ foreach f : ['poll', 'getifaddrs'] ...@@ -119,10 +119,16 @@ foreach f : ['poll', 'getifaddrs']
endif endif
endforeach endforeach
# BSD and macOS
if cc.has_member('struct ifreq', 'ifr_index', prefix: '#include <net/if.h>') if cc.has_member('struct ifreq', 'ifr_index', prefix: '#include <net/if.h>')
cdata.set('HAVE_IFR_INDEX', 1) cdata.set('HAVE_IFR_INDEX', 1)
endif 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') 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