proxygen
|
#include <SocketAddress.h>
Classes | |
union | AddrStorage |
struct | ExternalUnixAddr |
Public Member Functions | |
SocketAddress ()=default | |
SocketAddress (const char *host, uint16_t port, bool allowNameLookup=false) | |
SocketAddress (const std::string &host, uint16_t port, bool allowNameLookup=false) | |
SocketAddress (const IPAddress &ipAddr, uint16_t port) | |
SocketAddress (const SocketAddress &addr) | |
SocketAddress & | operator= (const SocketAddress &addr) |
SocketAddress (SocketAddress &&addr) noexcept | |
SocketAddress & | operator= (SocketAddress &&addr) |
~SocketAddress () | |
bool | isInitialized () const |
bool | isPrivateAddress () const |
bool | isLoopbackAddress () const |
void | reset () |
void | setFromHostPort (const char *host, uint16_t port) |
void | setFromHostPort (const std::string &host, uint16_t port) |
void | setFromIpPort (const char *ip, uint16_t port) |
void | setFromIpPort (const std::string &ip, uint16_t port) |
void | setFromIpAddrPort (const IPAddress &ip, uint16_t port) |
void | setFromLocalPort (uint16_t port) |
void | setFromLocalPort (const char *port) |
void | setFromLocalPort (const std::string &port) |
void | setFromLocalIpPort (const char *addressAndPort) |
void | setFromLocalIpPort (const std::string &addressAndPort) |
void | setFromIpPort (const char *addressAndPort) |
void | setFromIpPort (const std::string &addressAndPort) |
void | setFromHostPort (const char *hostAndPort) |
void | setFromHostPort (const std::string &hostAndPort) |
void | setFromPath (StringPiece path) |
void | setFromPath (const char *path, size_t length) |
void | setFromPeerAddress (int socket) |
void | setFromPeerAddress (NetworkSocket socket) |
void | setFromLocalAddress (int socket) |
void | setFromLocalAddress (NetworkSocket socket) |
void | setFromSockaddr (const struct sockaddr *address) |
void | setFromSockaddr (const struct sockaddr *address, socklen_t addrlen) |
void | setFromSockaddr (const struct sockaddr_in *address) |
void | setFromSockaddr (const struct sockaddr_in6 *address) |
void | setFromSockaddr (const struct sockaddr_un *address, socklen_t addrlen) |
socklen_t | getAddress (sockaddr_storage *addr) const |
const folly::IPAddress & | getIPAddress () const |
socklen_t | getActualSize () const |
sa_family_t | getFamily () const |
bool | empty () const |
std::string | getAddressStr () const |
void | getAddressStr (char *buf, size_t buflen) const |
bool | isFamilyInet () const |
std::string | getFullyQualified () const |
uint16_t | getPort () const |
void | setPort (uint16_t port) |
bool | isIPv4Mapped () const |
void | convertToIPv4 () |
bool | tryConvertToIPv4 () |
bool | mapToIPv6 () |
std::string | getHostStr () const |
std::string | getPath () const |
std::string | describe () const |
bool | operator== (const SocketAddress &other) const |
bool | operator!= (const SocketAddress &other) const |
bool | prefixMatch (const SocketAddress &other, unsigned prefixLength) const |
bool | operator< (const SocketAddress &other) const |
size_t | hash () const |
Static Public Member Functions | |
static int | getPortFrom (const struct sockaddr *address) |
static const char * | getFamilyNameFrom (const struct sockaddr *address, const char *defaultResult=nullptr) |
static SocketAddress | makeFromPath (StringPiece path) |
Private Member Functions | |
struct addrinfo * | getAddrInfo (const char *host, uint16_t port, int flags) |
struct addrinfo * | getAddrInfo (const char *host, const char *port, int flags) |
void | setFromAddrInfo (const struct addrinfo *results) |
void | setFromLocalAddr (const struct addrinfo *results) |
void | setFromSocket (NetworkSocket socket, int(*fn)(NetworkSocket, struct sockaddr *, socklen_t *)) |
std::string | getIpString (int flags) const |
void | getIpString (char *buf, size_t buflen, int flags) const |
void | updateUnixAddressLength (socklen_t addrlen) |
Private Attributes | |
union folly::SocketAddress::AddrStorage | storage_ |
uint16_t | port_ |
bool | external_ {false} |
Definition at line 32 of file SocketAddress.h.
|
default |
|
inline |
Construct a SocketAddress from a hostname and port.
Note: If the host parameter is not a numeric IP address, hostname resolution will be performed, which can be quite slow.
Raises std::system_error on error.
host | The IP address (or hostname, if allowNameLookup is true) |
port | The port (in host byte order) allowNameLookup If true, attempt to perform hostname lookup if the hostname does not appear to be a numeric IP address. This is potentially a very slow operation, so is disabled by default. |
Definition at line 51 of file SocketAddress.h.
References setFromHostPort(), and setFromIpPort().
|
inline |
Definition at line 62 of file SocketAddress.h.
References setFromHostPort(), and setFromIpPort().
|
inline |
Definition at line 76 of file SocketAddress.h.
References setFromIpAddrPort().
|
inline |
Definition at line 80 of file SocketAddress.h.
References external_, getFamily(), folly::SocketAddress::ExternalUnixAddr::init(), port_, storage_, and folly::SocketAddress::AddrStorage::un.
|
inlinenoexcept |
|
inline |
Definition at line 125 of file SocketAddress.h.
References external_, folly::SocketAddress::ExternalUnixAddr::free(), storage_, and folly::SocketAddress::AddrStorage::un.
void folly::SocketAddress::convertToIPv4 | ( | ) |
Convert an IPv4-mapped IPv6 address to an IPv4 address.
Raises std::invalid_argument if this is not an IPv4-mapped IPv6 address.
Definition at line 430 of file SocketAddress.cpp.
Referenced by isIPv4Mapped(), and TEST().
std::string folly::SocketAddress::describe | ( | ) | const |
Get human-readable string representation of the address.
This prints a string representation of the address, for human consumption. For IP addresses, the string is of the form "<IP>:<port>".
Definition at line 482 of file SocketAddress.cpp.
References string.
Referenced by wangle::SSLContextManager::addSSLContextConfig(), folly::AsyncUDPSocket::bind(), folly::AsyncServerSocket::bindSocket(), wangle::Acceptor::canAccept(), folly::AsyncSocket::fail(), folly::AsyncSocket::failConnect(), folly::AsyncSocket::failErrMessageRead(), folly::AsyncSocket::failRead(), folly::AsyncSocket::failWrite(), folly::AsyncSocket::handleConnect(), isIPv4Mapped(), proxygen::HTTPSessionAcceptor::onNewConnection(), folly::operator<<(), folly::AsyncServerSocket::setupSocket(), proxygen::HTTPSession::shutdownTransport(), TEST(), TelnetHandler::transportActive(), FileServerHandler::transportActive(), and folly::AsyncSocket::withAddr().
|
inline |
Definition at line 412 of file SocketAddress.h.
References getAddressStr(), getFamily(), getFullyQualified(), getPort(), isFamilyInet(), setPort(), string, and uint16_t.
Referenced by TEST().
socklen_t folly::SocketAddress::getActualSize | ( | ) | const |
Definition at line 362 of file SocketAddress.cpp.
Referenced by folly::AsyncUDPSocket::bind(), folly::AsyncServerSocket::bindSocket(), folly::AsyncUDPSocket::connect(), folly::AsyncSocket::connect(), getAddress(), testSetFromSocket(), and folly::AsyncUDPSocket::writev().
|
inline |
Fill in a given sockaddr_storage with the ip or unix address.
Returns the actual size of the storage used.
Definition at line 393 of file SocketAddress.h.
References folly::SocketAddress::ExternalUnixAddr::addr, folly::SocketAddress::AddrStorage::addr, external_, getActualSize(), getIPAddress(), folly::SocketAddress::ExternalUnixAddr::len, port_, storage_, and folly::SocketAddress::AddrStorage::un.
Referenced by folly::AsyncUDPSocket::bind(), folly::AsyncServerSocket::bindSocket(), folly::AsyncUDPSocket::connect(), folly::AsyncSocket::sendSocketMessage(), folly::TEST(), TEST(), testSetFromSocket(), and folly::AsyncUDPSocket::writev().
std::string folly::SocketAddress::getAddressStr | ( | ) | const |
Get a string representation of the IPv4 or IPv6 address.
Raises std::invalid_argument if an error occurs (for example, if the address is not an IPv4 or IPv6 address).
Definition at line 386 of file SocketAddress.cpp.
Referenced by empty(), main(), proxygen::HTTPMessage::setClientAddress(), proxygen::HTTPMessage::setDstAddress(), and TEST().
void folly::SocketAddress::getAddressStr | ( | char * | buf, |
size_t | buflen | ||
) | const |
Get a string representation of the IPv4 or IPv6 address.
Raises std::invalid_argument if an error occurs (for example, if the address is not an IPv4 or IPv6 address).
Definition at line 398 of file SocketAddress.cpp.
References min.
|
private |
Definition at line 609 of file SocketAddress.cpp.
Referenced by folly::SocketAddress::ExternalUnixAddr::free().
|
private |
Definition at line 618 of file SocketAddress.cpp.
References folly::pushmi::operators::error(), and folly::sformat().
|
inline |
Definition at line 407 of file SocketAddress.h.
References folly::SocketAddress::AddrStorage::addr, external_, and storage_.
Referenced by folly::AsyncUDPSocket::bind(), folly::AsyncServerSocket::bind(), folly::AsyncServerSocket::bindSocket(), CheckPrefixMatch(), folly::AsyncUDPSocket::dontFragment(), empty(), folly::AsyncUDPSocket::handleRead(), isInitialized(), isIPv4Mapped(), operator<(), operator=(), operator==(), prefixMatch(), folly::AsyncUDPSocket::setErrMessageCallback(), folly::AsyncSocket::setErrMessageCB(), wangle::ServerSocketConfig::setSocketOptions(), SocketAddress(), TEST(), testSetFromSocket(), and folly::AsyncServerSocket::useExistingSockets().
|
static |
Returns the family name from the given socketaddr structure (e.g.: AF_INET6 for IPv6).
Returns defaultResult
for unsupported socket families.
Definition at line 199 of file SocketAddress.cpp.
References GETFAMILYNAMEFROM_IMPL.
Referenced by folly::AsyncServerSocket::bind(), and setFromHostPort().
std::string folly::SocketAddress::getFullyQualified | ( | ) | const |
For v4 & v6 addresses, return the fully qualified address string
Definition at line 379 of file SocketAddress.cpp.
Referenced by empty().
std::string folly::SocketAddress::getHostStr | ( | ) | const |
Get string representation of the host name (or IP address if the host name cannot be resolved).
Warning: Using this method is strongly discouraged. It performs a DNS lookup, which may block for many seconds.
Raises std::invalid_argument if an error occurs.
Definition at line 456 of file SocketAddress.cpp.
Referenced by isIPv4Mapped().
const folly::IPAddress & folly::SocketAddress::getIPAddress | ( | ) | const |
Definition at line 354 of file SocketAddress.cpp.
Referenced by getAddress(), wangle::LoadShedConfiguration::AddressOnlyCompare::operator()(), and TEST().
|
private |
Definition at line 670 of file SocketAddress.cpp.
References string.
Referenced by folly::SocketAddress::ExternalUnixAddr::free().
|
private |
Definition at line 676 of file SocketAddress.cpp.
References folly::sformat().
std::string folly::SocketAddress::getPath | ( | ) | const |
Get the path name for a Unix domain socket.
Returns a std::string containing the path. For anonymous sockets, an empty string is returned.
For addresses in the abstract namespace (Linux-specific), a std::string containing binary data is returned. In this case the first character will always be a NUL character.
Raises std::invalid_argument if called on a non-Unix domain socket.
Definition at line 460 of file SocketAddress.cpp.
References string.
Referenced by isIPv4Mapped(), and TEST().
uint16_t folly::SocketAddress::getPort | ( | ) | const |
Get the IPv4 or IPv6 port for this address.
Raises std::invalid_argument if this is not an IPv4 or IPv6 address.
Definition at line 405 of file SocketAddress.cpp.
Referenced by folly::AsyncUDPSocket::bind(), folly::AsyncServerSocket::bind(), empty(), proxygen::HTTPMessage::setClientAddress(), proxygen::HTTPMessage::setDstAddress(), folly::TEST(), and TEST().
|
static |
Returns the port number from the given socketaddr structure.
Currently only IPv4 and IPv6 are supported.
Returns -1 for unsupported socket families.
Definition at line 186 of file SocketAddress.cpp.
Referenced by folly::AsyncServerSocket::bind(), and setFromHostPort().
size_t folly::SocketAddress::hash | ( | ) | const |
Compuate a hash of a SocketAddress.
Definition at line 575 of file SocketAddress.cpp.
References folly::hash::hash_combine(), seed, folly::hash::twang_mix64(), and uint64_t.
Referenced by folly::hash_value(), operator!=(), std::hash< folly::SocketAddress >::operator()(), and TEST().
bool folly::SocketAddress::isFamilyInet | ( | ) | const |
Return true if it is a valid IPv4 or IPv6 address.
Definition at line 393 of file SocketAddress.cpp.
Referenced by empty(), proxygen::HTTPSessionAcceptor::onNewConnection(), and TEST().
|
inline |
Definition at line 131 of file SocketAddress.h.
References getFamily(), isLoopbackAddress(), and isPrivateAddress().
Referenced by folly::AsyncSocket::cacheLocalAddress(), folly::AsyncSocket::cachePeerAddress(), and TEST().
|
inline |
Return true if this is an IPv4-mapped IPv6 address.
Definition at line 461 of file SocketAddress.h.
References folly::SocketAddress::AddrStorage::addr, convertToIPv4(), describe(), getFamily(), getHostStr(), getPath(), mapToIPv6(), operator==(), storage_, string, and tryConvertToIPv4().
Referenced by TEST().
bool folly::SocketAddress::isLoopbackAddress | ( | ) | const |
Return whether this address is a loopback address.
Definition at line 127 of file SocketAddress.cpp.
Referenced by isInitialized(), and TEST().
bool folly::SocketAddress::isPrivateAddress | ( | ) | const |
Return whether this address is within private network.
According to RFC1918, the 10/8 prefix, 172.16/12 prefix, and 192.168/16 prefix are reserved for private networks. fc00::/7 is the IPv6 version, defined in RFC4139. IPv6 link-local addresses (fe80::/10) are also considered private addresses.
The loopback addresses 127/8 and ::1 are also regarded as private networks for the purpose of this function.
Returns true if this is a private network address, and false otherwise.
Definition at line 113 of file SocketAddress.cpp.
Referenced by proxygen::HTTPSessionAcceptor::getErrorPage(), isInitialized(), and TEST().
|
inlinestatic |
Construct a SocketAddress from a local unix socket path.
Raises std::invalid_argument on error.
path | The Unix domain socket path. |
Definition at line 317 of file SocketAddress.h.
References addr, setFromLocalAddress(), setFromPath(), setFromPeerAddress(), setFromSockaddr(), and folly::netops::socket().
bool folly::SocketAddress::mapToIPv6 | ( | ) |
Convert an IPv4 address to IPv6 [::ffff:a.b.c.d]
Definition at line 447 of file SocketAddress.cpp.
Referenced by isIPv4Mapped().
|
inline |
Definition at line 522 of file SocketAddress.h.
References hash(), operator<(), and prefixMatch().
bool folly::SocketAddress::operator< | ( | const SocketAddress & | other | ) | const |
Use this operator for storing maps based on SocketAddress.
Definition at line 725 of file SocketAddress.cpp.
References folly::SocketAddress::ExternalUnixAddr::addr, folly::SocketAddress::AddrStorage::addr, getFamily(), folly::SocketAddress::ExternalUnixAddr::pathLength(), port_, storage_, and folly::SocketAddress::AddrStorage::un.
Referenced by operator!=().
|
inline |
Definition at line 90 of file SocketAddress.h.
References folly::SocketAddress::ExternalUnixAddr::copy(), external_, folly::SocketAddress::ExternalUnixAddr::free(), getFamily(), folly::SocketAddress::ExternalUnixAddr::init(), port_, storage_, and folly::SocketAddress::AddrStorage::un.
|
inline |
Definition at line 118 of file SocketAddress.h.
References addr, external_, port_, storage_, and folly::f14::swap().
bool folly::SocketAddress::operator== | ( | const SocketAddress & | other | ) | const |
Definition at line 523 of file SocketAddress.cpp.
References folly::SocketAddress::ExternalUnixAddr::addr, folly::SocketAddress::AddrStorage::addr, external_, getFamily(), folly::SocketAddress::ExternalUnixAddr::len, folly::SocketAddress::ExternalUnixAddr::pathLength(), port_, storage_, and folly::SocketAddress::AddrStorage::un.
Referenced by isIPv4Mapped().
bool folly::SocketAddress::prefixMatch | ( | const SocketAddress & | other, |
unsigned | prefixLength | ||
) | const |
Check whether the first N bits of this address match the first N bits of another address.
Definition at line 554 of file SocketAddress.cpp.
References folly::SocketAddress::AddrStorage::addr, FOLLY_FALLTHROUGH, getFamily(), prefix(), storage_, and uint8_t.
Referenced by CheckPrefixMatch(), wangle::NetworkAddress::contains(), operator!=(), and TEST().
|
inline |
Definition at line 155 of file SocketAddress.h.
References folly::SocketAddress::AddrStorage::addr, external_, folly::SocketAddress::ExternalUnixAddr::free(), setFromHostPort(), storage_, uint16_t, and folly::SocketAddress::AddrStorage::un.
Referenced by folly::SSLClient::SSLClient(), and TEST().
|
private |
Definition at line 639 of file SocketAddress.cpp.
Referenced by folly::SocketAddress::ExternalUnixAddr::free().
void folly::SocketAddress::setFromHostPort | ( | const char * | host, |
uint16_t | port | ||
) |
Initialize this SocketAddress from a hostname and port.
Note: If the host parameter is not a numeric IP address, hostname resolution will be performed, which can be quite slow.
If the hostname resolves to multiple addresses, only the first will be returned.
Raises std::system_error on error.
host | The hostname or IP address |
port | The port (in host byte order) |
Definition at line 138 of file SocketAddress.cpp.
Referenced by main(), reset(), setFromHostPort(), setFromIpPort(), SocketAddress(), and TEST().
|
inline |
Definition at line 179 of file SocketAddress.h.
References setFromHostPort(), setFromIpPort(), and uint16_t.
void folly::SocketAddress::setFromHostPort | ( | const char * | hostAndPort | ) |
Initialize this SocketAddress from a host name and port number.
The addressAndPort string must be of the form "<host>:<port>". E.g., "www.facebook.com:443".
If the host name is not a numeric IP address, a DNS lookup will be performed. Beware that the DNS lookup may be very slow. The port number must be numeric; non-numeric service port names are not accepted.
Definition at line 180 of file SocketAddress.cpp.
|
inline |
Definition at line 276 of file SocketAddress.h.
References getFamilyNameFrom(), getPortFrom(), setFromHostPort(), and setFromPath().
void folly::SocketAddress::setFromIpAddrPort | ( | const IPAddress & | ip, |
uint16_t | port | ||
) |
Initialize this SocketAddress from an IPAddress struct and port.
ip | The IP address in IPAddress format |
port | The port (in host byte order) |
Definition at line 148 of file SocketAddress.cpp.
Referenced by setFromIpPort(), SocketAddress(), and TEST().
void folly::SocketAddress::setFromIpPort | ( | const char * | ip, |
uint16_t | port | ||
) |
Initialize this SocketAddress from an IP address and port.
This is similar to setFromHostPort(), but only accepts numeric IP addresses. If the IP string does not look like an IP address, it throws a std::invalid_argument rather than trying to perform a hostname resolution.
Raises std::system_error on error.
ip | The IP address, as a human-readable string. |
port | The port (in host byte order) |
Definition at line 143 of file SocketAddress.cpp.
Referenced by TestAsyncTransport::getLocalAddress(), TestAsyncTransport::getPeerAddress(), setFromHostPort(), setFromIpPort(), setFromLocalIpPort(), SocketAddress(), and TEST().
|
inline |
Definition at line 197 of file SocketAddress.h.
References setFromIpAddrPort(), setFromIpPort(), setFromLocalPort(), and uint16_t.
void folly::SocketAddress::setFromIpPort | ( | const char * | addressAndPort | ) |
Initialize this SocketAddress from an IP address and port number.
The addressAndPort string must be of the form "<ip>:<port>". E.g., "10.0.0.1:1234".
Both the IP address and port number must be numeric. DNS host names and non-numeric service port names are not accepted.
Definition at line 174 of file SocketAddress.cpp.
|
inline |
Definition at line 261 of file SocketAddress.h.
References setFromHostPort(), and setFromIpPort().
|
private |
Definition at line 643 of file SocketAddress.cpp.
Referenced by folly::SocketAddress::ExternalUnixAddr::free().
void folly::SocketAddress::setFromLocalAddress | ( | int | socket | ) |
Initialize this SocketAddress from a socket's local address.
Raises std::system_error on error.
Definition at line 253 of file SocketAddress.cpp.
Referenced by folly::AsyncUDPSocket::bind(), folly::AsyncServerSocket::bind(), folly::AsyncSocket::cacheLocalAddress(), folly::AsyncServerSocket::getAddress(), makeFromPath(), folly::AsyncUDPSocket::setFD(), folly::AsyncServerSocket::setupSocket(), TEST(), testSetFromSocket(), and folly::AsyncServerSocket::useExistingSockets().
void folly::SocketAddress::setFromLocalAddress | ( | NetworkSocket | socket | ) |
Definition at line 257 of file SocketAddress.cpp.
References folly::netops::getsockname().
void folly::SocketAddress::setFromLocalIpPort | ( | const char * | addressAndPort | ) |
Initialize this SocketAddress from a local port number and optional IP address.
The addressAndPort string may be specified either as "<ip>:<port>", or just as "<port>". If the IP is not specified, the address will be initialized to 0, so that a server socket bound to this address will accept connections on all local IP addresses.
Both the IP address and port number must be numeric. DNS host names and non-numeric service port names are not accepted.
Definition at line 167 of file SocketAddress.cpp.
Referenced by setFromLocalIpPort(), setFromLocalPort(), and TEST().
|
inline |
Definition at line 247 of file SocketAddress.h.
References setFromIpPort(), and setFromLocalIpPort().
void folly::SocketAddress::setFromLocalPort | ( | uint16_t | port | ) |
Initialize this SocketAddress from a local port number.
This is intended to be used by server code to determine the address to listen on.
If the current machine has any IPv6 addresses configured, an IPv6 address will be returned (since connections from IPv4 clients can be mapped to the IPv6 address). If the machine does not have any IPv6 addresses, an IPv4 address will be returned.
Definition at line 157 of file SocketAddress.cpp.
Referenced by wangle::ServerBootstrap< DefaultPipeline >::bind(), SimpleServerPool::connect(), proxygen::ScopedHTTPServer::start< std::unique_ptr< RequestHandlerFactory > >(), setFromIpPort(), setFromLocalPort(), and TEST().
void folly::SocketAddress::setFromLocalPort | ( | const char * | port | ) |
Initialize this SocketAddress from a local port number.
This version of setFromLocalPort() accepts the port as a string. A std::invalid_argument will be raised if the string does not refer to a port number. Non-numeric service port names are not accepted.
Definition at line 162 of file SocketAddress.cpp.
|
inline |
Definition at line 230 of file SocketAddress.h.
References setFromLocalIpPort(), and setFromLocalPort().
void folly::SocketAddress::setFromPath | ( | StringPiece | path | ) |
Initialize this SocketAddress from a local unix path.
Raises std::invalid_argument on error.
Definition at line 219 of file SocketAddress.cpp.
References folly::Range< Iter >::data(), and folly::Range< Iter >::size().
Referenced by makeFromPath(), setFromHostPort(), setFromPath(), and TEST().
|
inline |
Definition at line 306 of file SocketAddress.h.
References setFromPath().
void folly::SocketAddress::setFromPeerAddress | ( | int | socket | ) |
Initialize this SocketAddress from a socket's peer address.
Raises std::system_error on error.
Definition at line 245 of file SocketAddress.cpp.
Referenced by folly::AsyncSocket::cachePeerAddress(), makeFromPath(), TEST(), and testSetFromSocket().
void folly::SocketAddress::setFromPeerAddress | ( | NetworkSocket | socket | ) |
Definition at line 249 of file SocketAddress.cpp.
References folly::netops::getpeername().
void folly::SocketAddress::setFromSockaddr | ( | const struct sockaddr * | address | ) |
Initialize this folly::SocketAddress from a struct sockaddr.
Raises std::system_error on error.
This method is not supported for AF_UNIX addresses. For unix addresses, the address length must be explicitly specified.
address | A struct sockaddr. The size of the address is implied from address->sa_family. |
Definition at line 261 of file SocketAddress.cpp.
References uint16_t.
Referenced by folly::AsyncUDPSocket::handleRead(), folly::AsyncServerSocket::handlerReady(), makeFromPath(), and testSetFromSocket().
void folly::SocketAddress::setFromSockaddr | ( | const struct sockaddr * | address, |
socklen_t | addrlen | ||
) |
Initialize this SocketAddress from a struct sockaddr.
Raises std::system_error on error.
address | A struct sockaddr. |
addrlen | The length of address data available. This must be long enough for the full address type required by address->sa_family. |
Definition at line 285 of file SocketAddress.cpp.
void folly::SocketAddress::setFromSockaddr | ( | const struct sockaddr_in * | address | ) |
Initialize this SocketAddress from a struct sockaddr_in.
Definition at line 320 of file SocketAddress.cpp.
void folly::SocketAddress::setFromSockaddr | ( | const struct sockaddr_in6 * | address | ) |
Initialize this SocketAddress from a struct sockaddr_in6.
Definition at line 325 of file SocketAddress.cpp.
void folly::SocketAddress::setFromSockaddr | ( | const struct sockaddr_un * | address, |
socklen_t | addrlen | ||
) |
Initialize this SocketAddress from a struct sockaddr_un.
Note that the addrlen parameter is necessary to properly detect anonymous addresses, which have 0 valid path bytes, and may not even have a NUL character at the start of the path.
address | A struct sockaddr_un. |
addrlen | The length of address data. This should include all of the valid bytes of sun_path, not including any NUL terminator. |
Definition at line 330 of file SocketAddress.cpp.
|
private |
Definition at line 657 of file SocketAddress.cpp.
References folly::throwSystemError().
Referenced by folly::SocketAddress::ExternalUnixAddr::free().
void folly::SocketAddress::setPort | ( | uint16_t | port | ) |
Set the IPv4 or IPv6 port for this address.
Raises std::invalid_argument if this is not an IPv4 or IPv6 address.
Definition at line 417 of file SocketAddress.cpp.
Referenced by empty(), and TEST().
bool folly::SocketAddress::tryConvertToIPv4 | ( | ) |
Try to convert an address to IPv4.
This attempts to convert an address to an IPv4 address if possible. If the address is an IPv4-mapped IPv6 address, it is converted to an IPv4 address and true is returned. Otherwise nothing is done, and false is returned.
Definition at line 438 of file SocketAddress.cpp.
Referenced by proxygen::HTTPSessionBase::HTTPSessionBase(), and isIPv4Mapped().
|
private |
Definition at line 701 of file SocketAddress.cpp.
Referenced by folly::SocketAddress::ExternalUnixAddr::free().
|
private |
Definition at line 609 of file SocketAddress.h.
Referenced by getAddress(), getFamily(), operator=(), operator==(), reset(), SocketAddress(), and ~SocketAddress().
|
private |
Definition at line 607 of file SocketAddress.h.
Referenced by getAddress(), operator<(), operator=(), operator==(), and SocketAddress().
|
private |