/*
- * 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.
#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 {
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;
}
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;
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];
}
}
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;