Fix usingJEMalloc with Clang
[folly.git] / folly / detail / IPAddress.h
index ba43bf0697b73de6e293685d26bcda2349f15565..afb3f9f6a062a18e2dc1b95eefb37ac47f9f8eff 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -46,8 +46,12 @@ extern "C" {
 #include <folly/Conv.h>
 #include <folly/Format.h>
 
-#if defined(__APPLE__) && !defined(s6_addr16)
-# define s6_addr16 __u6_addr.__u6_addr16
+// BSDish platforms don't provide standard access to s6_addr16
+#ifndef s6_addr16
+# if defined(__APPLE__) || defined(__FreeBSD__) || \
+     defined(__NetBSD__) || defined(__OpenBSD__)
+#  define s6_addr16 __u6_addr.__u6_addr16
+# endif
 #endif
 
 namespace folly { namespace detail {
@@ -85,7 +89,7 @@ inline bool getNthMSBitImpl(const IPAddrType& ip, uint8_t bitIndex,
 struct Bytes : private boost::noncopyable {
   // return true if all values of src are zero
   static bool isZero(const uint8_t* src, std::size_t len) {
-    for (auto i = 0; i < len; i++) {
+    for (std::size_t i = 0; i < len; i++) {
       if (src[i] != 0x00) {
         return false;
       }
@@ -100,7 +104,7 @@ struct Bytes : private boost::noncopyable {
     static_assert(N > 0, "Can't mask an empty ByteArray");
     std::size_t asize = a.size();
     std::array<uint8_t, N> ba{{0}};
-    for (int i = 0; i < asize; i++) {
+    for (std::size_t i = 0; i < asize; i++) {
       ba[i] = a[i] & b[i];
     }
     return ba;
@@ -176,7 +180,7 @@ struct Bytes : private boost::noncopyable {
   static std::string toHex(const uint8_t* src, std::size_t len) {
     static const char* const lut = "0123456789abcdef";
     std::stringstream ss;
-    for (int i = 0; i < len; i++) {
+    for (std::size_t i = 0; i < len; i++) {
       const unsigned char c = src[i];
       ss << lut[c >> 4] << lut[c & 15];
     }
@@ -279,7 +283,11 @@ inline std::string fastIpv4ToString(
 }
 
 inline std::string fastIpv6ToString(const in6_addr& in6Addr) {
+#ifdef _MSC_VER
+  const uint16_t* bytes = reinterpret_cast<const uint16_t*>(&in6Addr.u.Word);
+#else
   const uint16_t* bytes = reinterpret_cast<const uint16_t*>(&in6Addr.s6_addr16);
+#endif
   char str[sizeof("2001:0db8:0000:0000:0000:ff00:0042:8329")];
   char* buf = str;