[vlc-devel] [PATCH 1/2] win32: use if_nametoindex() from iphlpapi.h when available

Steve Lhomme robux4 at videolabs.io
Tue Oct 6 13:32:43 CEST 2015


---
 configure.ac          | 19 +++++++++++++++++--
 include/vlc_fixups.h  |  4 +++-
 include/vlc_network.h |  3 +++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index b414c47..8130ee6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -586,6 +586,14 @@ esac
 
 AH_BOTTOM([#include <vlc_fixups.h>])
 
+dnl  Win32
+AC_CHECK_HEADERS([iphlpapi.h],[have_iphlpapi="yes"], [have_iphlpapi="no"],[
+#include <winsock2.h>
+# if _WIN32_WINNT < 0x600
+#  error Needs vista+
+# endif
+])
+
 dnl Check for struct pollfd
 AC_CHECK_TYPES([struct pollfd],,,
 [#include <sys/types.h>
@@ -593,6 +601,9 @@ AC_CHECK_TYPES([struct pollfd],,,
 # include <poll.h>
 #elif defined (_WIN32)
 # include <winsock2.h>
+# ifdef HAVE_IPHLPAPI_H
+#  include <iphlpapi.h>
+# endif
 #endif
 ])
 
@@ -605,7 +616,11 @@ AC_SEARCH_LIBS(connect, [socket], [
   ])
 ], [
   AS_IF([test "${SYS}" = "mingw32"], [
-    SOCKET_LIBS="-lws2_32"
+    AS_IF([test "$have_iphlpapi" = "yes"], [
+      SOCKET_LIBS="-lws2_32 -liphlpapi"
+    ],[
+      SOCKET_LIBS="-lws2_32"
+    ])
   ])
 ])
 
@@ -1658,7 +1673,7 @@ You can get an updated one from http://www.live555.com/liveMedia .])
       other_libs_pic="-lgroupsock_pic -lBasicUsageEnvironment_pic -lUsageEnvironment_pic"
       AS_IF([test "${SYS}" = "mingw32"], [
         # add ws2_32 for closesocket, select, recv
-        other_libs="$other_libs -lws2_32"
+        other_libs="$other_libs $SOCKET_LIBS"
       ])
 
       dnl We need to check for pic because live555 don't provide shared libs
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 305de87..8f21475 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -323,7 +323,9 @@ struct if_nameindex
     char    *if_name;
 };
 # ifndef HAVE_IF_NAMETOINDEX
-#  define if_nametoindex(name)   atoi(name)
+#  ifndef HAVE_IPHLPAPI_H
+#   define if_nametoindex(name)   atoi(name)
+#  endif
 # endif
 # define if_nameindex()         (errno = ENOBUFS, NULL)
 # define if_freenameindex(list) (void)0
diff --git a/include/vlc_network.h b/include/vlc_network.h
index 4da4faf..dd87726 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -37,6 +37,9 @@
 #   include <io.h>
 #   include <winsock2.h>
 #   include <ws2tcpip.h>
+#   ifdef HAVE_IPHLPAPI_H
+#     include <iphlpapi.h>
+#   endif /* HAVE_IPHLPAPI_H */
 #   define net_errno (WSAGetLastError())
 
 struct iovec
-- 
2.5.2



More information about the vlc-devel mailing list