Commit 0b856bd5 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply clang-format to folly/**/*Address*.*

Summary: [Folly] Apply `clang-format` to `folly/**/*Address*.*`.

Reviewed By: Orvid

Differential Revision: D5581523

fbshipit-source-id: 97b5270e43e279e7deb9606524d5fee844a50649
parent d44f36ab
......@@ -69,7 +69,8 @@ IPAddressV6 IPAddress::createIPv6(const IPAddress& addr) {
}
// public static
CIDRNetwork IPAddress::createNetwork(StringPiece ipSlashCidr,
CIDRNetwork IPAddress::createNetwork(
StringPiece ipSlashCidr,
int defaultCidr, /* = -1 */
bool applyMask /* = true */) {
if (defaultCidr > std::numeric_limits<uint8_t>::max()) {
......@@ -133,17 +134,10 @@ IPAddress IPAddress::fromLongHBO(uint32_t src) {
}
// default constructor
IPAddress::IPAddress()
: addr_()
, family_(AF_UNSPEC)
{
}
IPAddress::IPAddress() : addr_(), family_(AF_UNSPEC) {}
// public string constructor
IPAddress::IPAddress(StringPiece addr)
: addr_()
, family_(AF_UNSPEC)
{
IPAddress::IPAddress(StringPiece addr) : addr_(), family_(AF_UNSPEC) {
string ip = addr.str(); // inet_pton() needs NUL-terminated string
auto throwFormatException = [&](const string& msg) {
throw IPAddressFormatException(sformat("Invalid IP '{}': {}", ip, msg));
......@@ -186,22 +180,19 @@ IPAddress::IPAddress(StringPiece addr)
}
// public sockaddr constructor
IPAddress::IPAddress(const sockaddr* addr)
: addr_()
, family_(AF_UNSPEC)
{
IPAddress::IPAddress(const sockaddr* addr) : addr_(), family_(AF_UNSPEC) {
if (addr == nullptr) {
throw IPAddressFormatException("sockaddr == nullptr");
}
family_ = addr->sa_family;
switch (addr->sa_family) {
case AF_INET: {
const sockaddr_in *v4addr = reinterpret_cast<const sockaddr_in*>(addr);
const sockaddr_in* v4addr = reinterpret_cast<const sockaddr_in*>(addr);
addr_.ipV4Addr = IPAddressV4(v4addr->sin_addr);
break;
}
case AF_INET6: {
const sockaddr_in6 *v6addr = reinterpret_cast<const sockaddr_in6*>(addr);
const sockaddr_in6* v6addr = reinterpret_cast<const sockaddr_in6*>(addr);
addr_.ipV6Addr = IPAddressV6(*v6addr);
break;
}
......@@ -212,31 +203,19 @@ IPAddress::IPAddress(const sockaddr* addr)
// public ipv4 constructor
IPAddress::IPAddress(const IPAddressV4 ipV4Addr)
: addr_(ipV4Addr)
, family_(AF_INET)
{
}
: addr_(ipV4Addr), family_(AF_INET) {}
// public ipv4 constructor
IPAddress::IPAddress(const in_addr ipV4Addr)
: addr_(IPAddressV4(ipV4Addr))
, family_(AF_INET)
{
}
: addr_(IPAddressV4(ipV4Addr)), family_(AF_INET) {}
// public ipv6 constructor
IPAddress::IPAddress(const IPAddressV6& ipV6Addr)
: addr_(ipV6Addr)
, family_(AF_INET6)
{
}
: addr_(ipV6Addr), family_(AF_INET6) {}
// public ipv6 constructor
IPAddress::IPAddress(const in6_addr& ipV6Addr)
: addr_(IPAddressV6(ipV6Addr))
, family_(AF_INET6)
{
}
: addr_(IPAddressV6(ipV6Addr)), family_(AF_INET6) {}
// Assign from V4 address
IPAddress& IPAddress::operator=(const IPAddressV4& ipv4_addr) {
......@@ -286,8 +265,8 @@ bool IPAddress::inSubnet(const IPAddress& subnet, uint8_t cidr) const {
}
// public
bool IPAddress::inSubnetWithMask(const IPAddress& subnet,
ByteRange mask) const {
bool IPAddress::inSubnetWithMask(const IPAddress& subnet, ByteRange mask)
const {
auto mkByteArray4 = [&]() -> ByteArray4 {
ByteArray4 ba{{0}};
std::memcpy(ba.data(), mask.begin(), std::min<size_t>(mask.size(), 4));
......@@ -392,8 +371,9 @@ bool operator<(const IPAddress& addr1, const IPAddress& addr2) {
return false;
}
CIDRNetwork
IPAddress::longestCommonPrefix(const CIDRNetwork& one, const CIDRNetwork& two) {
CIDRNetwork IPAddress::longestCommonPrefix(
const CIDRNetwork& one,
const CIDRNetwork& two) {
if (one.first.family() != two.first.family()) {
throw std::invalid_argument(sformat(
"Can't compute longest common prefix between addresses of different"
......@@ -403,13 +383,11 @@ IPAddress::longestCommonPrefix(const CIDRNetwork& one, const CIDRNetwork& two) {
}
if (one.first.isV4()) {
auto prefix = IPAddressV4::longestCommonPrefix(
{one.first.asV4(), one.second},
{two.first.asV4(), two.second});
{one.first.asV4(), one.second}, {two.first.asV4(), two.second});
return {IPAddress(prefix.first), prefix.second};
} else if (one.first.isV6()) {
auto prefix = IPAddressV6::longestCommonPrefix(
{one.first.asV6(), one.second},
{two.first.asV6(), two.second});
{one.first.asV6(), one.second}, {two.first.asV6(), two.second});
return {IPAddress(prefix.first), prefix.second};
} else {
throw std::invalid_argument("Unknown address family");
......
......@@ -95,7 +95,9 @@ class IPAddress {
* @return pair with IPAddress network and uint8_t mask
*/
static CIDRNetwork createNetwork(
StringPiece ipSlashCidr, int defaultCidr = -1, bool mask = true);
StringPiece ipSlashCidr,
int defaultCidr = -1,
bool mask = true);
/**
* Return a string representation of a CIDR block created with createNetwork.
......@@ -122,7 +124,8 @@ class IPAddress {
// Given 2 IPAddress,mask pairs extract the longest common IPAddress,
// mask pair
static CIDRNetwork longestCommonPrefix(const CIDRNetwork& one,
static CIDRNetwork longestCommonPrefix(
const CIDRNetwork& one,
const CIDRNetwork& two);
/**
......@@ -188,10 +191,12 @@ class IPAddress {
}
// Return sa_family_t of IPAddress
sa_family_t family() const { return family_; }
sa_family_t family() const {
return family_;
}
// Populate sockaddr_storage with an appropriate value
int toSockaddrStorage(sockaddr_storage *dest, uint16_t port = 0) const {
int toSockaddrStorage(sockaddr_storage* dest, uint16_t port = 0) const {
if (dest == nullptr) {
throw IPAddressFormatException("dest must not be null");
}
......@@ -199,7 +204,7 @@ class IPAddress {
dest->ss_family = family();
if (isV4()) {
sockaddr_in *sin = reinterpret_cast<sockaddr_in*>(dest);
sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(dest);
sin->sin_addr = asV4().toAddr();
sin->sin_port = port;
#if defined(__APPLE__)
......@@ -207,7 +212,7 @@ class IPAddress {
#endif
return sizeof(*sin);
} else if (isV6()) {
sockaddr_in6 *sin = reinterpret_cast<sockaddr_in6*>(dest);
sockaddr_in6* sin = reinterpret_cast<sockaddr_in6*>(dest);
sin->sin6_addr = asV6().toAddr();
sin->sin6_port = port;
sin->sin6_scope_id = asV6().getScopeId();
......@@ -260,16 +265,24 @@ class IPAddress {
}
// @return true if address is uninitialized
bool empty() const { return (family_ == AF_UNSPEC); }
bool empty() const {
return (family_ == AF_UNSPEC);
}
// @return true if address is initialized
explicit operator bool() const { return !empty(); }
explicit operator bool() const {
return !empty();
}
// @return true if this is an IPAddressV4 instance
bool isV4() const { return (family_ == AF_INET); }
bool isV4() const {
return (family_ == AF_INET);
}
// @return true if this is an IPAddressV6 instance
bool isV6() const { return (family_ == AF_INET6); }
bool isV6() const {
return (family_ == AF_INET6);
}
// @return true if this address is all zeros
bool isZero() const {
......@@ -284,17 +297,17 @@ class IPAddress {
size_t byteCount() const {
return bitCount() / 8;
}
//get nth most significant bit - 0 indexed
// get nth most significant bit - 0 indexed
bool getNthMSBit(size_t bitIndex) const {
return detail::getNthMSBitImpl(*this, bitIndex, family());
}
//get nth most significant byte - 0 indexed
// get nth most significant byte - 0 indexed
uint8_t getNthMSByte(size_t byteIndex) const;
//get nth bit - 0 indexed
// get nth bit - 0 indexed
bool getNthLSBit(size_t bitIndex) const {
return getNthMSBit(bitCount() - bitIndex - 1);
}
//get nth byte - 0 indexed
// get nth byte - 0 indexed
uint8_t getNthLSByte(size_t byteIndex) const {
return getNthMSByte(byteCount() - byteIndex - 1);
}
......@@ -408,8 +421,8 @@ class IPAddress {
IPAddressV46() {
std::memset(this, 0, sizeof(IPAddressV46));
}
explicit IPAddressV46(const IPAddressV4& addr): ipV4Addr(addr) {}
explicit IPAddressV46(const IPAddressV6& addr): ipV6Addr(addr) {}
explicit IPAddressV46(const IPAddressV4& addr) : ipV4Addr(addr) {}
explicit IPAddressV46(const IPAddressV6& addr) : ipV6Addr(addr) {}
} IPAddressV46;
IPAddressV46 addr_;
sa_family_t family_;
......
......@@ -29,7 +29,6 @@ using std::string;
namespace folly {
// free functions
size_t hash_value(const IPAddressV4& addr) {
return addr.hash();
......@@ -85,19 +84,13 @@ uint32_t IPAddressV4::toLongHBO(StringPiece ip) {
}
// public default constructor
IPAddressV4::IPAddressV4() {
}
IPAddressV4::IPAddressV4() {}
// ByteArray4 constructor
IPAddressV4::IPAddressV4(const ByteArray4& src)
: addr_(src)
{
}
IPAddressV4::IPAddressV4(const ByteArray4& src) : addr_(src) {}
// public string constructor
IPAddressV4::IPAddressV4(StringPiece addr)
: addr_()
{
IPAddressV4::IPAddressV4(StringPiece addr) : addr_() {
auto ip = addr.str();
if (inet_pton(AF_INET, ip.c_str(), &addr_.inAddr_) != 1) {
throw IPAddressFormatException(sformat("Invalid IPv4 address '{}'", addr));
......@@ -105,10 +98,7 @@ IPAddressV4::IPAddressV4(StringPiece addr)
}
// in_addr constructor
IPAddressV4::IPAddressV4(const in_addr src)
: addr_(src)
{
}
IPAddressV4::IPAddressV4(const in_addr src) : addr_(src) {}
// public
void IPAddressV4::setFromBinary(ByteRange bytes) {
......@@ -172,11 +162,11 @@ bool IPAddressV4::inSubnet(StringPiece cidrNetwork) const {
}
// public
bool IPAddressV4::inSubnetWithMask(const IPAddressV4& subnet,
bool IPAddressV4::inSubnetWithMask(
const IPAddressV4& subnet,
const ByteArray4 cidrMask) const {
const ByteArray4 mask = detail::Bytes::mask(toByteArray(), cidrMask);
const ByteArray4 subMask = detail::Bytes::mask(subnet.toByteArray(),
cidrMask);
const auto mask = detail::Bytes::mask(toByteArray(), cidrMask);
const auto subMask = detail::Bytes::mask(subnet.toByteArray(), cidrMask);
return (mask == subMask);
}
......@@ -196,24 +186,26 @@ bool IPAddressV4::isLinkLocal() const {
bool IPAddressV4::isNonroutable() const {
auto ip = toLongHBO();
return isPrivate() ||
(ip <= 0x00FFFFFF) || // 0.0.0.0-0.255.255.255
(/* align */ true && ip <= 0x00FFFFFF) || // 0.0.0.0-0.255.255.255
(ip >= 0xC0000000 && ip <= 0xC00000FF) || // 192.0.0.0-192.0.0.255
(ip >= 0xC0000200 && ip <= 0xC00002FF) || // 192.0.2.0-192.0.2.255
(ip >= 0xC6120000 && ip <= 0xC613FFFF) || // 198.18.0.0-198.19.255.255
(ip >= 0xC6336400 && ip <= 0xC63364FF) || // 198.51.100.0-198.51.100.255
(ip >= 0xCB007100 && ip <= 0xCB0071FF) || // 203.0.113.0-203.0.113.255
(ip >= 0xE0000000 && ip <= 0xFFFFFFFF); // 224.0.0.0-255.255.255.255
(ip >= 0xE0000000 && ip <= 0xFFFFFFFF) || // 224.0.0.0-255.255.255.255
false;
}
// public
bool IPAddressV4::isPrivate() const {
auto ip = toLongHBO();
return
return // some ranges below
(ip >= 0x0A000000 && ip <= 0x0AFFFFFF) || // 10.0.0.0-10.255.255.255
(ip >= 0x7F000000 && ip <= 0x7FFFFFFF) || // 127.0.0.0-127.255.255.255
(ip >= 0xA9FE0000 && ip <= 0xA9FEFFFF) || // 169.254.0.0-169.254.255.255
(ip >= 0xAC100000 && ip <= 0xAC1FFFFF) || // 172.16.0.0-172.31.255.255
(ip >= 0xC0A80000 && ip <= 0xC0A8FFFF); // 192.168.0.0-192.168.255.255
(ip >= 0xC0A80000 && ip <= 0xC0A8FFFF) || // 192.168.0.0-192.168.255.255
false;
}
// public
......
......@@ -80,7 +80,7 @@ class IPAddressV4 {
* Returns the address as a Range.
*/
ByteRange toBinary() const {
return ByteRange((const unsigned char *) &addr_.inAddr_.s_addr, 4);
return ByteRange((const unsigned char*)&addr_.inAddr_.s_addr, 4);
}
/**
......@@ -140,7 +140,9 @@ class IPAddressV4 {
* @see IPAddress#bitCount
* @returns 32
*/
static size_t bitCount() { return 32; }
static size_t bitCount() {
return 32;
}
/**
* @See IPAddress#toJson
......@@ -197,7 +199,9 @@ class IPAddressV4 {
std::string toInverseArpaName() const;
// return underlying in_addr structure
in_addr toAddr() const { return addr_.inAddr_; }
in_addr toAddr() const {
return addr_.inAddr_;
}
sockaddr_in toSockAddr() const {
sockaddr_in addr;
......@@ -214,13 +218,17 @@ class IPAddressV4 {
}
// @see IPAddress#toFullyQualified
std::string toFullyQualified() const { return str(); }
std::string toFullyQualified() const {
return str();
}
// @see IPAddress#toFullyQualifiedAppend
void toFullyQualifiedAppend(std::string& out) const;
// @see IPAddress#version
uint8_t version() const { return 4; }
uint8_t version() const {
return 4;
}
/**
* Return the mask associated with the given number of bits.
......@@ -238,35 +246,40 @@ class IPAddressV4 {
const CIDRNetworkV4& one,
const CIDRNetworkV4& two);
// Number of bytes in the address representation.
static size_t byteCount() { return 4; }
//get nth most significant bit - 0 indexed
static size_t byteCount() {
return 4;
}
// get nth most significant bit - 0 indexed
bool getNthMSBit(size_t bitIndex) const {
return detail::getNthMSBitImpl(*this, bitIndex, AF_INET);
}
//get nth most significant byte - 0 indexed
// get nth most significant byte - 0 indexed
uint8_t getNthMSByte(size_t byteIndex) const;
//get nth bit - 0 indexed
// get nth bit - 0 indexed
bool getNthLSBit(size_t bitIndex) const {
return getNthMSBit(bitCount() - bitIndex - 1);
}
//get nth byte - 0 indexed
// get nth byte - 0 indexed
uint8_t getNthLSByte(size_t byteIndex) const {
return getNthMSByte(byteCount() - byteIndex - 1);
}
const unsigned char* bytes() const { return addr_.bytes_.data(); }
const unsigned char* bytes() const {
return addr_.bytes_.data();
}
private:
union AddressStorage {
static_assert(sizeof(in_addr) == sizeof(ByteArray4),
static_assert(
sizeof(in_addr) == sizeof(ByteArray4),
"size of in_addr and ByteArray4 are different");
in_addr inAddr_;
ByteArray4 bytes_;
AddressStorage() {
std::memset(this, 0, sizeof(AddressStorage));
}
explicit AddressStorage(const ByteArray4 bytes): bytes_(bytes) {}
explicit AddressStorage(const in_addr addr): inAddr_(addr) {}
explicit AddressStorage(const ByteArray4 bytes) : bytes_(bytes) {}
explicit AddressStorage(const in_addr addr) : inAddr_(addr) {}
} addr_;
/**
......
......@@ -77,8 +77,7 @@ bool IPAddressV6::validate(StringPiece ip) {
}
// public default constructor
IPAddressV6::IPAddressV6() {
}
IPAddressV6::IPAddressV6() {}
// public string constructor
IPAddressV6::IPAddressV6(StringPiece addr) {
......@@ -110,28 +109,17 @@ IPAddressV6::IPAddressV6(StringPiece addr) {
}
// in6_addr constructor
IPAddressV6::IPAddressV6(const in6_addr& src)
: addr_(src)
{
}
IPAddressV6::IPAddressV6(const in6_addr& src) : addr_(src) {}
// sockaddr_in6 constructor
IPAddressV6::IPAddressV6(const sockaddr_in6& src)
: addr_(src.sin6_addr)
, scope_(uint16_t(src.sin6_scope_id))
{
}
: addr_(src.sin6_addr), scope_(uint16_t(src.sin6_scope_id)) {}
// ByteArray16 constructor
IPAddressV6::IPAddressV6(const ByteArray16& src)
: addr_(src)
{
}
IPAddressV6::IPAddressV6(const ByteArray16& src) : addr_(src) {}
// link-local constructor
IPAddressV6::IPAddressV6(LinkLocalTag, MacAddress mac)
: addr_(mac) {
}
IPAddressV6::IPAddressV6(LinkLocalTag, MacAddress mac) : addr_(mac) {}
IPAddressV6::AddressStorage::AddressStorage(MacAddress mac) {
// The link-local address uses modified EUI-64 format,
......@@ -228,9 +216,8 @@ static inline uint16_t unpack(uint8_t lobyte, uint8_t hibyte) {
// given a src string, unpack count*2 bytes into dest
// dest must have as much storage as count
static inline void unpackInto(const unsigned char* src,
uint16_t* dest,
size_t count) {
static inline void
unpackInto(const unsigned char* src, uint16_t* dest, size_t count) {
for (size_t i = 0, hi = 1, lo = 0; i < count; i++) {
dest[i] = unpack(src[hi], src[lo]);
hi += 2;
......@@ -245,7 +232,7 @@ IPAddressV4 IPAddressV6::getIPv4For6To4() const {
sformat("Invalid IP '{}': not a 6to4 address", str()));
}
// convert 16x8 bytes into first 4x16 bytes
uint16_t ints[4] = {0,0,0,0};
uint16_t ints[4] = {0, 0, 0, 0};
unpackInto(bytes(), ints, 4);
// repack into 4x8
union {
......@@ -281,7 +268,7 @@ bool IPAddressV6::isIPv4Mapped() const {
// public
IPAddressV6::Type IPAddressV6::type() const {
// convert 16x8 bytes into first 2x16 bytes
uint16_t ints[2] = {0,0};
uint16_t ints[2] = {0, 0};
unpackInto(bytes(), ints, 2);
if ((((uint32_t)ints[0] << 16) | ints[1]) == IPAddressV6::PREFIX_TEREDO) {
......@@ -327,11 +314,11 @@ bool IPAddressV6::inSubnet(StringPiece cidrNetwork) const {
}
// public
bool IPAddressV6::inSubnetWithMask(const IPAddressV6& subnet,
bool IPAddressV6::inSubnetWithMask(
const IPAddressV6& subnet,
const ByteArray16& cidrMask) const {
const ByteArray16 mask = detail::Bytes::mask(toByteArray(), cidrMask);
const ByteArray16 subMask = detail::Bytes::mask(subnet.toByteArray(),
cidrMask);
const auto mask = detail::Bytes::mask(toByteArray(), cidrMask);
const auto subMask = detail::Bytes::mask(subnet.toByteArray(), cidrMask);
return (mask == subMask);
}
......@@ -392,11 +379,24 @@ IPAddressV6 IPAddressV6::getSolicitedNodeAddress() const {
// addresses
DCHECK(!isMulticast());
uint8_t bytes[16] = { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00 };
bytes[13] = addr_.bytes_[13];
bytes[14] = addr_.bytes_[14];
bytes[15] = addr_.bytes_[15];
uint8_t bytes[16] = {
0xff,
0x02,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x01,
0xff,
addr_.bytes_[13],
addr_.bytes_[14],
addr_.bytes_[15],
};
return IPAddressV6::fromBinary(ByteRange(bytes, 16));
}
......@@ -504,7 +504,8 @@ CIDRNetworkV6 IPAddressV6::longestCommonPrefix(
}
// protected
bool IPAddressV6::inBinarySubnet(const std::array<uint8_t, 2> addr,
bool IPAddressV6::inBinarySubnet(
const std::array<uint8_t, 2> addr,
size_t numBits) const {
auto masked = mask(numBits);
return (std::memcmp(addr.data(), masked.bytes(), 2) == 0);
......
......@@ -69,7 +69,9 @@ class IPAddressV6 {
public:
// V6 Address Type
enum Type {
TEREDO, T6TO4, NORMAL,
TEREDO,
T6TO4,
NORMAL,
};
// A constructor parameter to indicate that we should create a link-local
// IPAddressV6.
......@@ -112,7 +114,7 @@ class IPAddressV6 {
* Returns the address as a Range.
*/
ByteRange toBinary() const {
return ByteRange((const unsigned char *) &addr_.in6Addr_.s6_addr, 16);
return ByteRange((const unsigned char*)&addr_.in6Addr_.s6_addr, 16);
}
/**
......@@ -171,7 +173,9 @@ class IPAddressV6 {
* @see IPAddress#bitCount
* @returns 128
*/
static size_t bitCount() { return 128; }
static size_t bitCount() {
return 128;
}
/**
* @see IPAddress#toJson
......@@ -188,8 +192,8 @@ class IPAddressV6 {
bool inSubnet(const IPAddressV6& subnet, uint8_t cidr) const {
return inSubnetWithMask(subnet, fetchMask(cidr));
}
bool inSubnetWithMask(const IPAddressV6& subnet,
const ByteArray16& mask) const;
bool inSubnetWithMask(const IPAddressV6& subnet, const ByteArray16& mask)
const;
// @see IPAddress#isLoopback
bool isLoopback() const;
......@@ -256,9 +260,13 @@ class IPAddressV6 {
IPAddressV6 mask(size_t numBits) const;
// return underlying in6_addr structure
in6_addr toAddr() const { return addr_.in6Addr_; }
in6_addr toAddr() const {
return addr_.in6Addr_;
}
uint16_t getScopeId() const { return scope_; }
uint16_t getScopeId() const {
return scope_;
}
void setScopeId(uint16_t scope) {
scope_ = scope;
}
......@@ -290,7 +298,9 @@ class IPAddressV6 {
std::string str() const;
// @see IPAddress#version
uint8_t version() const { return 6; }
uint8_t version() const {
return 6;
}
/**
* Return the solicited-node multicast address for this address.
......@@ -312,32 +322,35 @@ class IPAddressV6 {
const CIDRNetworkV6& one,
const CIDRNetworkV6& two);
// Number of bytes in the address representation.
static constexpr size_t byteCount() { return 16; }
static constexpr size_t byteCount() {
return 16;
}
//get nth most significant bit - 0 indexed
// get nth most significant bit - 0 indexed
bool getNthMSBit(size_t bitIndex) const {
return detail::getNthMSBitImpl(*this, bitIndex, AF_INET6);
}
//get nth most significant byte - 0 indexed
// get nth most significant byte - 0 indexed
uint8_t getNthMSByte(size_t byteIndex) const;
//get nth bit - 0 indexed
// get nth bit - 0 indexed
bool getNthLSBit(size_t bitIndex) const {
return getNthMSBit(bitCount() - bitIndex - 1);
}
//get nth byte - 0 indexed
// get nth byte - 0 indexed
uint8_t getNthLSByte(size_t byteIndex) const {
return getNthMSByte(byteCount() - byteIndex - 1);
}
const unsigned char* bytes() const { return addr_.in6Addr_.s6_addr; }
const unsigned char* bytes() const {
return addr_.in6Addr_.s6_addr;
}
protected:
/**
* Helper that returns true if the address is in the binary subnet specified
* by addr.
*/
bool inBinarySubnet(const std::array<uint8_t, 2> addr,
size_t numBits) const;
bool inBinarySubnet(const std::array<uint8_t, 2> addr, size_t numBits) const;
private:
auto tie() const {
......@@ -371,8 +384,8 @@ class IPAddressV6 {
AddressStorage() {
std::memset(this, 0, sizeof(AddressStorage));
}
explicit AddressStorage(const ByteArray16& bytes): bytes_(bytes) {}
explicit AddressStorage(const in6_addr& addr): in6Addr_(addr) {}
explicit AddressStorage(const ByteArray16& bytes) : bytes_(bytes) {}
explicit AddressStorage(const in6_addr& addr) : in6Addr_(addr) {}
explicit AddressStorage(MacAddress mac);
} addr_;
......
......@@ -73,9 +73,7 @@ string MacAddress::toString() const {
void MacAddress::parse(StringPiece str) {
// Helper function to convert a single hex char into an integer
auto isSeparatorChar = [](char c) {
return c == ':' || c == '-';
};
auto isSeparatorChar = [](char c) { return c == ':' || c == '-'; };
uint8_t parsed[SIZE];
auto p = str.begin();
......
......@@ -222,8 +222,9 @@ class MacAddress {
/* Define toAppend() so to<string> will work */
template <class Tgt>
typename std::enable_if<IsSomeString<Tgt>::value>::type
toAppend(MacAddress address, Tgt* result) {
typename std::enable_if<IsSomeString<Tgt>::value>::type toAppend(
MacAddress address,
Tgt* result) {
toAppend(address.toString(), result);
}
......
......@@ -15,7 +15,7 @@
*/
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <folly/SocketAddress.h>
......@@ -61,10 +61,7 @@ struct ScopedAddrInfo {
*/
struct HostAndPort {
HostAndPort(const char* str, bool hostRequired)
: host(nullptr),
port(nullptr),
allocated(nullptr) {
: host(nullptr), port(nullptr), allocated(nullptr) {
// Look for the last colon
const char* colon = strrchr(str, ':');
if (colon == nullptr) {
......@@ -85,7 +82,7 @@ struct HostAndPort {
throw std::bad_alloc();
}
char *allocatedColon = allocated + (colon - str);
char* allocatedColon = allocated + (colon - str);
*allocatedColon = '\0';
host = allocated;
port = allocatedColon + 1;
......@@ -167,8 +164,8 @@ void SocketAddress::setFromLocalPort(const char* port) {
void SocketAddress::setFromLocalIpPort(const char* addressAndPort) {
HostAndPort hp(addressAndPort, false);
ScopedAddrInfo results(getAddrInfo(hp.host, hp.port,
AI_NUMERICHOST | AI_ADDRCONFIG));
ScopedAddrInfo results(
getAddrInfo(hp.host, hp.port, AI_NUMERICHOST | AI_ADDRCONFIG));
setFromLocalAddr(results.info);
}
......@@ -275,11 +272,12 @@ void SocketAddress::setFromSockaddr(const struct sockaddr* address) {
setFromIpAddrPort(folly::IPAddress(address), port);
}
void SocketAddress::setFromSockaddr(const struct sockaddr* address,
void SocketAddress::setFromSockaddr(
const struct sockaddr* address,
socklen_t addrlen) {
// Check the length to make sure we can access address->sa_family
if (addrlen < (offsetof(struct sockaddr, sa_family) +
sizeof(address->sa_family))) {
if (addrlen <
(offsetof(struct sockaddr, sa_family) + sizeof(address->sa_family))) {
throw std::invalid_argument(
"SocketAddress::setFromSockaddr() called "
"with length too short for a sockaddr");
......@@ -300,8 +298,8 @@ void SocketAddress::setFromSockaddr(const struct sockaddr* address,
}
setFromSockaddr(reinterpret_cast<const struct sockaddr_in6*>(address));
} else if (address->sa_family == AF_UNIX) {
setFromSockaddr(reinterpret_cast<const struct sockaddr_un*>(address),
addrlen);
setFromSockaddr(
reinterpret_cast<const struct sockaddr_un*>(address), addrlen);
} else {
throw std::invalid_argument(
"SocketAddress::setFromSockaddr() called "
......@@ -319,7 +317,8 @@ void SocketAddress::setFromSockaddr(const struct sockaddr_in6* address) {
setFromSockaddr((sockaddr*)address);
}
void SocketAddress::setFromSockaddr(const struct sockaddr_un* address,
void SocketAddress::setFromSockaddr(
const struct sockaddr_un* address,
socklen_t addrlen) {
assert(address->sun_family == AF_UNIX);
if (addrlen > sizeof(struct sockaddr_un)) {
......@@ -337,7 +336,7 @@ void SocketAddress::setFromSockaddr(const struct sockaddr_un* address,
// Fill the rest with 0s, just for safety
if (addrlen < sizeof(struct sockaddr_un)) {
char *p = reinterpret_cast<char*>(storage_.un.addr);
char* p = reinterpret_cast<char*>(storage_.un.addr);
memset(p + addrlen, 0, sizeof(struct sockaddr_un) - addrlen);
}
}
......@@ -488,16 +487,14 @@ std::string SocketAddress::describe() const {
switch (getFamily()) {
case AF_UNSPEC:
return "<uninitialized address>";
case AF_INET:
{
case AF_INET: {
char buf[NI_MAXHOST + 16];
getAddressStr(buf, sizeof(buf));
size_t iplen = strlen(buf);
snprintf(buf + iplen, sizeof(buf) - iplen, ":%" PRIu16, getPort());
return buf;
}
case AF_INET6:
{
case AF_INET6: {
char buf[NI_MAXHOST + 18];
buf[0] = '[';
getAddressStr(buf + 1, sizeof(buf) - 1);
......@@ -505,11 +502,9 @@ std::string SocketAddress::describe() const {
snprintf(buf + iplen, sizeof(buf) - iplen, "]:%" PRIu16, getPort());
return buf;
}
default:
{
default: {
char buf[64];
snprintf(buf, sizeof(buf), "<unknown address family %d>",
getFamily());
snprintf(buf, sizeof(buf), "<unknown address family %d>", getFamily());
return buf;
}
}
......@@ -521,8 +516,7 @@ bool SocketAddress::operator==(const SocketAddress& other) const {
}
if (external_) {
// anonymous addresses are never equal to any other addresses
if (storage_.un.pathLength() == 0 ||
other.storage_.un.pathLength() == 0) {
if (storage_.un.pathLength() == 0 || other.storage_.un.pathLength() == 0) {
return false;
}
......@@ -539,8 +533,7 @@ bool SocketAddress::operator==(const SocketAddress& other) const {
switch (getFamily()) {
case AF_INET:
case AF_INET6:
return (other.storage_.addr == storage_.addr) &&
(other.port_ == port_);
return (other.storage_.addr == storage_.addr) && (other.port_ == port_);
default:
throw std::invalid_argument(
"SocketAddress: unsupported address family "
......@@ -548,7 +541,8 @@ bool SocketAddress::operator==(const SocketAddress& other) const {
}
}
bool SocketAddress::prefixMatch(const SocketAddress& other,
bool SocketAddress::prefixMatch(
const SocketAddress& other,
unsigned prefixLength) const {
if (other.getFamily() != getFamily()) {
return false;
......@@ -558,11 +552,9 @@ bool SocketAddress::prefixMatch(const SocketAddress& other,
case AF_INET:
mask_length = 32;
FOLLY_FALLTHROUGH;
case AF_INET6:
{
case AF_INET6: {
auto prefix = folly::IPAddress::longestCommonPrefix(
{storage_.addr, mask_length},
{other.storage_.addr, mask_length});
{storage_.addr, mask_length}, {other.storage_.addr, mask_length});
return prefix.second >= prefixLength;
}
default:
......@@ -570,13 +562,12 @@ bool SocketAddress::prefixMatch(const SocketAddress& other,
}
}
size_t SocketAddress::hash() const {
size_t seed = folly::hash::twang_mix64(getFamily());
if (external_) {
enum { kUnixPathMax = sizeof(storage_.un.addr->sun_path) };
const char *path = storage_.un.addr->sun_path;
const char* path = storage_.un.addr->sun_path;
auto pathLength = storage_.un.pathLength();
// TODO: this probably could be made more efficient
for (off_t n = 0; n < pathLength; ++n) {
......@@ -604,9 +595,8 @@ size_t SocketAddress::hash() const {
return seed;
}
struct addrinfo* SocketAddress::getAddrInfo(const char* host,
uint16_t port,
int flags) {
struct addrinfo*
SocketAddress::getAddrInfo(const char* host, uint16_t port, int flags) {
// getaddrinfo() requires the port number as a string
char portString[sizeof("65535")];
snprintf(portString, sizeof(portString), "%" PRIu16, port);
......@@ -614,16 +604,15 @@ struct addrinfo* SocketAddress::getAddrInfo(const char* host,
return getAddrInfo(host, portString, flags);
}
struct addrinfo* SocketAddress::getAddrInfo(const char* host,
const char* port,
int flags) {
struct addrinfo*
SocketAddress::getAddrInfo(const char* host, const char* port, int flags) {
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV | flags;
struct addrinfo *results;
struct addrinfo* results;
int error = getaddrinfo(host, port, &hints, &results);
if (error != 0) {
auto os = folly::sformat(
......@@ -674,10 +663,9 @@ std::string SocketAddress::getIpString(int flags) const {
return std::string(addrString);
}
void SocketAddress::getIpString(char *buf, size_t buflen, int flags) const {
void SocketAddress::getIpString(char* buf, size_t buflen, int flags) const {
auto family = getFamily();
if (family != AF_INET &&
family != AF_INET6) {
if (family != AF_INET && family != AF_INET6) {
throw std::invalid_argument(
"SocketAddress: attempting to get IP address "
"for a non-IP address");
......@@ -685,8 +673,14 @@ void SocketAddress::getIpString(char *buf, size_t buflen, int flags) const {
sockaddr_storage tmp_sock;
storage_.addr.toSockaddrStorage(&tmp_sock, port_);
int rc = getnameinfo((sockaddr*)&tmp_sock, sizeof(sockaddr_storage),
buf, buflen, nullptr, 0, flags);
int rc = getnameinfo(
(sockaddr*)&tmp_sock,
sizeof(sockaddr_storage),
buf,
buflen,
nullptr,
0,
flags);
if (rc != 0) {
auto os = sformat(
"getnameinfo() failed in getIpString() error = {}", gai_strerror(rc));
......@@ -755,8 +749,7 @@ bool SocketAddress::operator<(const SocketAddress& other) const {
return port_ < other.port_;
}
return
storage_.addr < other.storage_.addr;
return storage_.addr < other.storage_.addr;
}
case AF_UNSPEC:
default:
......
......@@ -47,8 +47,7 @@ class SocketAddress {
* This is potentially a very slow operation, so is disabled by
* default.
*/
SocketAddress(const char* host, uint16_t port,
bool allowNameLookup = false) {
SocketAddress(const char* host, uint16_t port, bool allowNameLookup = false) {
// Initialize the address family first,
// since setFromHostPort() and setFromIpPort() will check it.
......@@ -59,7 +58,9 @@ class SocketAddress {
}
}
SocketAddress(const std::string& host, uint16_t port,
SocketAddress(
const std::string& host,
uint16_t port,
bool allowNameLookup = false) {
// Initialize the address family first,
// since setFromHostPort() and setFromIpPort() will check it.
......@@ -342,8 +343,7 @@ class SocketAddress {
* enough for the full address type required by
* address->sa_family.
*/
void setFromSockaddr(const struct sockaddr* address,
socklen_t addrlen);
void setFromSockaddr(const struct sockaddr* address, socklen_t addrlen);
/**
* Initialize this SocketAddress from a struct sockaddr_in.
......@@ -367,9 +367,7 @@ class SocketAddress {
* the valid bytes of sun_path, not including any NUL
* terminator.
*/
void setFromSockaddr(const struct sockaddr_un* address,
socklen_t addrlen);
void setFromSockaddr(const struct sockaddr_un* address, socklen_t addrlen);
/**
* Fill in a given sockaddr_storage with the ip or unix address.
......@@ -445,8 +443,7 @@ class SocketAddress {
* Return true if this is an IPv4-mapped IPv6 address.
*/
bool isIPv4Mapped() const {
return (getFamily() == AF_INET6 &&
storage_.addr.isIPv4Mapped());
return (getFamily() == AF_INET6 && storage_.addr.isIPv4Mapped());
}
/**
......@@ -540,7 +537,7 @@ class SocketAddress {
* the heap.
*/
struct ExternalUnixAddr {
struct sockaddr_un *addr;
struct sockaddr_un* addr;
socklen_t len;
socklen_t pathLength() const {
......@@ -552,12 +549,12 @@ class SocketAddress {
addr->sun_family = AF_UNIX;
len = 0;
}
void init(const ExternalUnixAddr &other) {
void init(const ExternalUnixAddr& other) {
addr = new struct sockaddr_un;
len = other.len;
memcpy(addr, other.addr, size_t(len));
}
void copy(const ExternalUnixAddr &other) {
void copy(const ExternalUnixAddr& other) {
len = other.len;
memcpy(addr, other.addr, size_t(len));
}
......@@ -572,7 +569,7 @@ class SocketAddress {
void setFromLocalAddr(const struct addrinfo* results);
void setFromSocket(int socket, int (*fn)(int, struct sockaddr*, socklen_t*));
std::string getIpString(int flags) const;
void getIpString(char *buf, size_t buflen, int flags) const;
void getIpString(char* buf, size_t buflen, int flags) const;
void updateUnixAddressLength(socklen_t addrlen);
......@@ -603,7 +600,6 @@ class SocketAddress {
size_t hash_value(const SocketAddress& address);
std::ostream& operator<<(std::ostream& os, const SocketAddress& addr);
}
namespace std {
......@@ -611,10 +607,8 @@ namespace std {
// Provide an implementation for std::hash<SocketAddress>
template <>
struct hash<folly::SocketAddress> {
size_t operator()(
const folly::SocketAddress& addr) const {
size_t operator()(const folly::SocketAddress& addr) const {
return addr.hash();
}
};
}
......@@ -18,7 +18,8 @@
#include <folly/Format.h>
namespace folly { namespace detail {
namespace folly {
namespace detail {
std::string familyNameStrDefault(sa_family_t family) {
return sformat("sa_family_t({})", family);
......@@ -30,5 +31,5 @@ std::string familyNameStrDefault(sa_family_t family) {
bitCount,
familyNameStr(family)));
}
}}
} // namespace detail
} // namespace folly
......@@ -22,7 +22,8 @@
#include <folly/portability/Sockets.h>
namespace folly { namespace detail {
namespace folly {
namespace detail {
std::string familyNameStrDefault(sa_family_t family);
......@@ -49,8 +50,8 @@ getNthMSBitImpl(const IPAddrType& ip, size_t bitIndex, sa_family_t family) {
if (bitIndex >= ip.bitCount()) {
getNthMSBitImplThrow(ip.bitCount(), family);
}
//Underlying bytes are in n/w byte order
// Underlying bytes are in n/w byte order
return (ip.getNthMSByte(bitIndex / 8) & (0x80 >> (bitIndex % 8))) != 0;
}
}} // folly::detail
} // namespace detail
} // namespace folly
......@@ -30,11 +30,8 @@ BENCHMARK(ipv4_to_string_inet_ntop, iters) {
char outputString[INET_ADDRSTRLEN] = {0};
while (iters--) {
const char* val = inet_ntop(
AF_INET,
&ip,
outputString,
sizeof(outputString));
const char* val =
inet_ntop(AF_INET, &ip, outputString, sizeof(outputString));
}
}
......@@ -78,11 +75,8 @@ BENCHMARK(ipv6_to_string_inet_ntop, iters) {
bool checkResult = (iters == 1);
while (iters--) {
const char* val = inet_ntop(
AF_INET6,
&ip,
outputString,
sizeof(outputString));
const char* val =
inet_ntop(AF_INET6, &ip, outputString, sizeof(outputString));
}
}
......@@ -135,7 +129,7 @@ BENCHMARK_RELATIVE(ipv6_append_to_fully_qualified_port, iters) {
// ipv6_append_to_fully_qualified_port 178.73% 84.35ns 11.86M
// ============================================================================
int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
runBenchmarks();
return 0;
......
This diff is collapsed.
......@@ -94,8 +94,8 @@ TEST(MacAddress, fromBinary) {
}
TEST(MacAddress, toString) {
EXPECT_EQ("12:34:56:78:9a:bc",
MacAddress::fromHBO(0x123456789abc).toString());
EXPECT_EQ(
"12:34:56:78:9a:bc", MacAddress::fromHBO(0x123456789abc).toString());
EXPECT_EQ("12:34:56:78:9a:bc", MacAddress("12:34:56:78:9a:bc").toString());
EXPECT_EQ("01:23:45:67:89:ab", MacAddress("01-23-45-67-89-ab").toString());
EXPECT_EQ("01:23:45:67:89:ab", MacAddress("0123456789ab").toString());
......@@ -131,9 +131,11 @@ TEST(MacAddress, attributes) {
}
TEST(MacAddress, createMulticast) {
EXPECT_EQ(MacAddress("33:33:00:01:00:03"),
EXPECT_EQ(
MacAddress("33:33:00:01:00:03"),
MacAddress::createMulticast(IPAddressV6("ff02:dead:beef::1:3")));
EXPECT_EQ(MacAddress("33:33:12:34:56:78"),
EXPECT_EQ(
MacAddress("33:33:12:34:56:78"),
MacAddress::createMulticast(IPAddressV6("ff02::abcd:1234:5678")));
}
......
......@@ -20,6 +20,8 @@
#include <sstream>
#include <system_error>
#include <folly/Array.h>
#include <folly/String.h>
#include <folly/experimental/TestUtil.h>
#include <folly/portability/GTest.h>
#include <folly/portability/Sockets.h>
......@@ -66,12 +68,9 @@ TEST(SocketAddress, IPv4ToStringConversion) {
SocketAddress addr;
for (int pos = 0; pos < 4; ++pos) {
for (int i = 0; i < 256; ++i) {
int fragments[] = {5,5,5,5};
auto fragments = folly::make_array(5, 5, 5, 5);
fragments[pos] = i;
std::ostringstream ss;
ss << fragments[0] << "." << fragments[1] << "."
<< fragments[2] << "." << fragments[3];
string ipString = ss.str();
auto ipString = folly::join(".", fragments);
addr.setFromIpPort(ipString, 1234);
EXPECT_EQ(addr.getAddressStr(), ipString);
}
......@@ -118,8 +117,7 @@ TEST(SocketAddress, SetFromInvalidIpv4) {
// Try setting to an invalid value
// Since setFromIpPort() shouldn't allow hostname lookups, setting to
// "localhost" should fail, even if localhost is resolvable
EXPECT_THROW(addr.setFromIpPort("localhost", 1234),
std::runtime_error);
EXPECT_THROW(addr.setFromIpPort("localhost", 1234), std::runtime_error);
// Make sure the address still has the old contents
EXPECT_EQ(addr.getFamily(), AF_INET);
......@@ -416,8 +414,10 @@ TEST(SocketAddress, IsLoopback) {
EXPECT_TRUE(addr.isLoopbackAddress());
}
void CheckPrefixMatch(const SocketAddress& first,
const SocketAddress& second, unsigned matchingPrefixLen) {
void CheckPrefixMatch(
const SocketAddress& first,
const SocketAddress& second,
unsigned matchingPrefixLen) {
unsigned i;
for (i = 0; i <= matchingPrefixLen; i++) {
EXPECT_TRUE(first.prefixMatch(second, i));
......@@ -468,7 +468,7 @@ TEST(SocketAddress, CheckComparatorBehavior) {
// The following comparison are strict (so if first and second were
// inverted that is ok.
//IP V4
// IP V4
// port comparisions
first.setFromIpPort("128.0.0.0", 0);
......@@ -669,14 +669,15 @@ TEST(SocketAddress, AnonymousUnix) {
ADD_FAILURE(); \
}
void testSetFromSocket(const SocketAddress *serverBindAddr,
const SocketAddress *clientBindAddr,
SocketAddress *listenAddrRet,
SocketAddress *acceptAddrRet,
SocketAddress *serverAddrRet,
SocketAddress *serverPeerAddrRet,
SocketAddress *clientAddrRet,
SocketAddress *clientPeerAddrRet) {
void testSetFromSocket(
const SocketAddress* serverBindAddr,
const SocketAddress* clientBindAddr,
SocketAddress* listenAddrRet,
SocketAddress* acceptAddrRet,
SocketAddress* serverAddrRet,
SocketAddress* serverPeerAddrRet,
SocketAddress* clientAddrRet,
SocketAddress* clientPeerAddrRet) {
int listenSock = fsp::socket(serverBindAddr->getFamily(), SOCK_STREAM, 0);
REQUIRE_ERRNO(listenSock > 0, "failed to create listen socket");
sockaddr_storage laddr;
......@@ -690,8 +691,8 @@ void testSetFromSocket(const SocketAddress *serverBindAddr,
listenAddrRet->setFromLocalAddress(listenSock);
SocketAddress listenPeerAddr;
EXPECT_THROW(listenPeerAddr.setFromPeerAddress(listenSock),
std::runtime_error);
EXPECT_THROW(
listenPeerAddr.setFromPeerAddress(listenSock), std::runtime_error);
// Note that we use the family from serverBindAddr here, since we allow
// clientBindAddr to be nullptr.
......@@ -701,21 +702,25 @@ void testSetFromSocket(const SocketAddress *serverBindAddr,
sockaddr_storage clientAddr;
clientBindAddr->getAddress(&clientAddr);
rc = bind(clientSock, reinterpret_cast<sockaddr*>(&clientAddr),
rc = bind(
clientSock,
reinterpret_cast<sockaddr*>(&clientAddr),
clientBindAddr->getActualSize());
REQUIRE_ERRNO(rc == 0, "failed to bind to client socket");
}
sockaddr_storage listenAddr;
listenAddrRet->getAddress(&listenAddr);
rc = connect(clientSock, reinterpret_cast<sockaddr*>(&listenAddr),
rc = connect(
clientSock,
reinterpret_cast<sockaddr*>(&listenAddr),
listenAddrRet->getActualSize());
REQUIRE_ERRNO(rc == 0, "failed to connect");
sockaddr_storage acceptAddr;
socklen_t acceptAddrLen = sizeof(acceptAddr);
int serverSock = accept(listenSock,
reinterpret_cast<sockaddr*>(&acceptAddr), &acceptAddrLen);
int serverSock = accept(
listenSock, reinterpret_cast<sockaddr*>(&acceptAddr), &acceptAddrLen);
REQUIRE_ERRNO(serverSock > 0, "failed to accept");
acceptAddrRet->setFromSockaddr(
reinterpret_cast<sockaddr*>(&acceptAddr), acceptAddrLen);
......@@ -740,10 +745,15 @@ TEST(SocketAddress, SetFromSocketIPv4) {
SocketAddress clientAddr;
SocketAddress clientPeerAddr;
testSetFromSocket(&serverBindAddr, &clientBindAddr,
&listenAddr, &acceptAddr,
&serverAddr, &serverPeerAddr,
&clientAddr, &clientPeerAddr);
testSetFromSocket(
&serverBindAddr,
&clientBindAddr,
&listenAddr,
&acceptAddr,
&serverAddr,
&serverPeerAddr,
&clientAddr,
&clientPeerAddr);
// The server socket's local address should have the same port as the listen
// address. The IP will be different, since the listening socket is
......@@ -781,10 +791,15 @@ TEST(SocketAddress, SetFromSocketUnixAbstract) {
SocketAddress clientAddr;
SocketAddress clientPeerAddr;
testSetFromSocket(&serverBindAddr, &clientBindAddr,
&listenAddr, &acceptAddr,
&serverAddr, &serverPeerAddr,
&clientAddr, &clientPeerAddr);
testSetFromSocket(
&serverBindAddr,
&clientBindAddr,
&listenAddr,
&acceptAddr,
&serverAddr,
&serverPeerAddr,
&clientAddr,
&clientPeerAddr);
// The server socket's local address should be the same as the listen
// address.
......@@ -820,10 +835,15 @@ TEST(SocketAddress, SetFromSocketUnixExplicit) {
serverBindAddr.setFromPath(serverPath.c_str());
clientBindAddr.setFromPath(clientPath.c_str());
testSetFromSocket(&serverBindAddr, &clientBindAddr,
&listenAddr, &acceptAddr,
&serverAddr, &serverPeerAddr,
&clientAddr, &clientPeerAddr);
testSetFromSocket(
&serverBindAddr,
&clientBindAddr,
&listenAddr,
&acceptAddr,
&serverAddr,
&serverPeerAddr,
&clientAddr,
&clientPeerAddr);
} catch (...) {
// Remove the socket files after we are done
unlink(serverPath.c_str());
......@@ -861,10 +881,15 @@ TEST(SocketAddress, SetFromSocketUnixAnonymous) {
try {
serverBindAddr.setFromPath(serverPath.c_str());
testSetFromSocket(&serverBindAddr, nullptr,
&listenAddr, &acceptAddr,
&serverAddr, &serverPeerAddr,
&clientAddr, &clientPeerAddr);
testSetFromSocket(
&serverBindAddr,
nullptr,
&listenAddr,
&acceptAddr,
&serverAddr,
&serverPeerAddr,
&clientAddr,
&clientPeerAddr);
} catch (...) {
// Remove the socket file after we are done
unlink(serverPath.c_str());
......
......@@ -47,5 +47,4 @@ bool SocketAddressTestHelper::isFamilyOfAddrEnabled(const char* addr) {
freeaddrinfo(resultsp);
return !err;
}
}
......@@ -20,7 +20,6 @@ namespace folly {
class SocketAddressTestHelper {
public:
static constexpr const char* kLoopbackAddrIPv4 = "127.0.0.1";
static constexpr const char* kLoopbackAddrIPv6 = "::1";
......@@ -40,8 +39,6 @@ class SocketAddressTestHelper {
static bool isIPv6Enabled();
private:
static bool isFamilyOfAddrEnabled(const char* addr);
};
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment