folly::IPAddress

A representation of an IP address (IPv4 or IPv6).

Synopsis

Declared in <folly/IPAddress.h>

class IPAddress;

Member Functions

NameDescription
IPAddress [constructor]Constructors
operator= Assignment operators
asV4 Converts an IPAddress to an IPAddressV4 instance.
asV6 Converts an IPAddress to an IPAddressV6 instance
bitCount The number of bits in the address representation
byteCount The number of bytes in the address representation
bytes Returns a pointer to the to IP address bytes, in network byte order.
empty Returns true if address is uninitialised
family Return then sa_family_t of the IP Address
getNthLSBit Get the nth bit of the IP address (0-indexed).
getNthLSByte Get the nth byte of the IP address (0-indexed).
getNthMSBit Get the nth most significant bit of the IP address (0-indexed).
getNthMSByte Get the nth most significant byte of the IP address (0-indexed).
hash Returns a hash of the IP address.
inSubnet inSubnet overloads
inSubnetWithMask Check if an IPAddress belongs to the subnet with the given mask.
isIPv4Mapped Returns true if address is a v4 mapped address
isLinkLocal Return true if the IP address qualifies as link local
isLinkLocalBroadcast Return true if the IP address qualifies as broadcast.
isLoopback Return true if the IP address qualifies as localhost.
isMulticast Return true if the IP address is a multicast address.
isNonroutable Return true if the IP address is a special purpose address, as defined per RFC 6890 (i.e. 0.0.0.0).
isPrivate Return true if the IP address is private, as per RFC 1918 and RFC 4193.
isV4 Returns true if this represents an IPv4 address
isV6 Returns true if this represents an IPv6 address
isZero Returns true if the address is all zeros
mask Creates an IPAddress instance with all but most significant numBits set to 0.
str Provides a string representation of address.
toFullyQualified Return the fully qualified string representation of the address.
toFullyQualifiedAppend Same as toFullyQualified() but append to an output string.
toJson Get a json representation of the IP address.
toSockaddrStorage Given a sockaddr_storage struct, populate it with an appropriate value.
version Returns the IP address version. 0 if empty, 4 or 6 if nonempty.
operator bool Returns true if address is initalised

Static Member Functions

NameDescription
createIPv4 Return the IPAddressV4 representation of the address, converting from V6 to V4 if needed.
createIPv6 Return the address as a IPAddressV6, converting from V4 to V6 if needed.
createNetwork Create a network and mask from a CIDR formatted address string.
fromBinary Create a new IPAddress instance from the provided binary data in network byte order.
fromLong Create an IPAddress from a uint32_t, using network byte order.
fromLongHBO Create an IPAddress from a uint32_t, using host byte order.
longestCommonPrefix Given 2 (IPAddress, mask) pairs, extract the longest common pair.
networkToString Return a string representation of a CIDR block created with createNetwork().
tryCreateNetwork Create a network and mask from a CIDR formatted address string.
tryFromBinary Non-throwing version of fromBinary(). On failure returns IPAddressFormatError.
tryFromSockAddr Tries to create a new IPAddress instance from the provided sockaddr.
tryFromString Tries to create a new IPAddress instance from provided string.
validate Returns true if the input string can be parsed as an IP address.

Non-Member Functions

NameDescription
hash_valueboost::hash uses hash_value(), so this allows boost::hash to work automatically for IPAddress
operator!=Return true if two address are not equal
operator<=>Three-way comparison for IPAddress.
operator==Return true if two addresses are equal.
toAppendAppend a string representation of the IP address to an fbstring.
toAppendoverloadbrief Define toAppend() to allow IPAddress to be used with folly::to<string>