Support if_indextoname in the socket portability header v2017.07.17.01
authorChristopher Dykes <cdykes@fb.com>
Tue, 18 Jul 2017 22:52:33 +0000 (15:52 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 18 Jul 2017 23:05:20 +0000 (16:05 -0700)
Summary: Windows doesn't have `net/if.h` and instead needs `iphlpapi.h` included, and `ntddndis.h` is ultimately needed to get the definition of `IF_NAMESIZE`.

Reviewed By: yfeldblum

Differential Revision: D5438188

fbshipit-source-id: 48a786f7d10ca4b8479bb20b257ed1e857431654

CMakeLists.txt
folly/IPAddressV6.cpp

index 6f71703..c067fb7 100755 (executable)
@@ -144,6 +144,7 @@ set(FOLLY_LINK_LIBRARIES
   ${LIBEVENT_LIB}
   ${LIBGFLAGS_LIBRARY}
   ${LIBGLOG_LIBRARY}
   ${LIBEVENT_LIB}
   ${LIBGFLAGS_LIBRARY}
   ${LIBGLOG_LIBRARY}
+  Iphlpapi.lib
   Ws2_32.lib
 
   ${FOLLY_SHINY_DEPENDENCIES}
   Ws2_32.lib
 
   ${FOLLY_SHINY_DEPENDENCIES}
index 70428f3..3490669 100644 (file)
 #include <ostream>
 #include <string>
 
 #include <ostream>
 #include <string>
 
-#include <net/if.h>
-
 #include <folly/Format.h>
 #include <folly/IPAddress.h>
 #include <folly/IPAddressV4.h>
 #include <folly/MacAddress.h>
 #include <folly/detail/IPAddressSource.h>
 
 #include <folly/Format.h>
 #include <folly/IPAddress.h>
 #include <folly/IPAddressV4.h>
 #include <folly/MacAddress.h>
 #include <folly/detail/IPAddressSource.h>
 
+#if !_WIN32
+#include <net/if.h>
+#else
+// Because of the massive pain that is libnl, this can't go into the socket
+// portability header as you can't include <linux/if.h> and <net/if.h> in
+// the same translation unit without getting errors -_-...
+#include <iphlpapi.h>
+#include <ntddndis.h>
+
+// Alias the max size of an interface name to what posix expects.
+#define IFNAMSIZ IF_NAMESIZE
+#endif
+
 using std::ostream;
 using std::string;
 
 using std::ostream;
 using std::string;