[vlc-devel] [PATCH] core: fix if_nametoindex detection

Steve Lhomme robux4 at videolabs.io
Tue Oct 24 14:00:47 CEST 2017


iphlpapi.h should be included if necessary and link with -liphlpapi must be
added
---
 configure.ac                     | 27 ++++++++++++++++++++++++++-
 modules/services_discovery/sap.c |  4 +++-
 src/Makefile.am                  |  2 +-
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index f4e5aa9d30..be1d0d37b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -659,6 +659,7 @@ AC_CHECK_TYPES([max_align_t],,,
 dnl Checks for socket stuff
 VLC_SAVE_FLAGS
 SOCKET_LIBS=""
+NETIF_LIBS=""
 AC_SEARCH_LIBS(connect, [socket], [
   AS_IF([test "$ac_cv_search_connect" != "none required"], [
     SOCKET_LIBS="$ac_cv_search_connect"
@@ -666,6 +667,7 @@ AC_SEARCH_LIBS(connect, [socket], [
 ], [
   AS_IF([test "${SYS}" = "mingw32"], [
     SOCKET_LIBS="-lws2_32"
+    NETIF_LIBS="-liphlpapi"
   ])
 ])
 
@@ -689,9 +691,32 @@ AC_LINK_IFELSE([
         char dst[[sizeof(struct in_addr)]];
         inet_pton(AF_INET, "127.0.0.1", dst);
     ])],[AC_DEFINE([HAVE_INET_PTON],[1],[Define to 1 if you have inet_pton function])],[AC_LIBOBJ([inet_pton])])
-AC_CHECK_FUNCS([if_nameindex if_nametoindex])
+LIBS="${LIBS} ${NETIF_LIBS}"
+AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([#ifdef _WIN32
+        # if _WIN32_WINNT < 0x600
+        #  error Needs vista+
+        # endif
+        #include <iphlpapi.h>
+        #else
+        #include <net/if.h>
+        #endif], [
+        if_nametoindex(NULL);
+    ])],[AC_DEFINE([HAVE_IF_NAMETOINDEX],[1],[Define to 1 if you have if_nametoindex function])],[])
+AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([#ifdef _WIN32
+        # if _WIN32_WINNT < 0x600
+        #  error Needs vista+
+        # endif
+        #include <iphlpapi.h>
+        #else
+        #include <net/if.h>
+        #endif], [
+        if_nameindex(NULL);
+    ])],[AC_DEFINE([HAVE_IF_NAMEINDEX],[1],[Define to 1 if you have if_nameindex function])],[])
 VLC_RESTORE_FLAGS
 AC_SUBST(SOCKET_LIBS)
+AC_SUBST(NETIF_LIBS)
 
 dnl Check for socklen_t
 AH_TEMPLATE(socklen_t, [Define to `int' if <sys/socket.h> does not define.])
diff --git a/modules/services_discovery/sap.c b/modules/services_discovery/sap.c
index 7c5569171d..cf070dcdcd 100644
--- a/modules/services_discovery/sap.c
+++ b/modules/services_discovery/sap.c
@@ -54,8 +54,10 @@
 #   include <zlib.h>
 #endif
 
-#ifndef _WIN32
+#ifdef HAVE_NET_IF_H
 #   include <net/if.h>
+#elif _WIN32
+#   include <iphlpapi.h>
 #endif
 
 /************************************************************************
diff --git a/src/Makefile.am b/src/Makefile.am
index 87ea540f69..e42328e281 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -356,7 +356,7 @@ libvlccore_la_SOURCES = \
 libvlccore_la_LIBADD = $(LIBS_libvlccore) \
 	../compat/libcompat.la \
 	$(LTLIBINTL) $(LTLIBICONV) \
-	$(IDN_LIBS) $(LIBPTHREAD) $(SOCKET_LIBS) $(LIBRT) $(LIBDL) $(LIBM)
+	$(IDN_LIBS) $(LIBPTHREAD) $(SOCKET_LIBS) $(NETIF_LIBS) $(LIBRT) $(LIBDL) $(LIBM)
 
 if HAVE_WIN32
 libvlccore_la_SOURCES += \
-- 
2.14.2



More information about the vlc-devel mailing list