21 #include <system_error> 50 sockaddr_storage addrStorage;
52 const sockaddr_in* inaddr =
reinterpret_cast<sockaddr_in*
>(&addrStorage);
53 EXPECT_EQ(inaddr->sin_addr.s_addr, htonl(0x01020304));
69 for (
int pos = 0; pos < 4; ++pos) {
70 for (
int i = 0;
i < 256; ++
i) {
82 folly::IPAddress ipAddr(
"123.234.0.23");
89 folly::IPAddress ip6Addr(
"2620:0:1cfe:face:b00c::3");
103 sockaddr_storage addrStorage;
105 const sockaddr_in* inaddr =
reinterpret_cast<sockaddr_in*
>(&addrStorage);
106 EXPECT_EQ(inaddr->sin_addr.s_addr, htonl(0xfffefdfc));
107 EXPECT_EQ(inaddr->sin_port, htons(8888));
126 sockaddr_storage addrStorage;
128 const sockaddr_in* inaddr =
reinterpret_cast<sockaddr_in*
>(&addrStorage);
129 EXPECT_EQ(inaddr->sin_addr.s_addr, htonl(0x0c22384e));
157 if (SocketAddressTestHelper::isIPv4Enabled()) {
162 if (SocketAddressTestHelper::isIPv6Enabled()) {
223 other2.setFromIpPort(
"1.2.3.4", 0);
226 other2.setPort(1234);
271 auto unix5 = SocketAddress::makeFromPath(
"/foo");
272 auto unixAnon2 = SocketAddress::makeFromPath(
"");
348 addr.
setFromIpPort(
"fbff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 0);
352 addr.
setFromIpPort(
"fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 0);
357 addr.
setFromIpPort(
"fe7f:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 0);
363 addr.
setFromIpPort(
"febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 0);
432 unsigned matchingPrefixLen) {
434 for (i = 0; i <= matchingPrefixLen; i++) {
437 unsigned addrLen = (first.
getFamily() == AF_INET6) ? 128 : 32;
438 for (; i <= addrLen; i++) {
553 const char longPath[] =
554 "abcdefghijklmnopqrstuvwxyz0123456789" 555 "abcdefghijklmnopqrstuvwxyz0123456789" 556 "abcdefghijklmnopqrstuvwxyz0123456789" 557 "abcdefghijklmnopqrstuvwxyz0123456789";
565 const char exactLengthPath[] =
566 "abcdefghijklmnopqrstuvwxyz0123456789" 567 "abcdefghijklmnopqrstuvwxyz0123456789" 568 "abcdefghijklmnopqrstuvwxyz0123456789";
674 #define REQUIRE_ERRNO(cond, msg) \ 676 ADD_FAILURE() << (msg) << ": " << ::folly::errnoStr(errno); \ 690 listenSock !=
NetworkSocket(),
"failed to create listen socket");
691 sockaddr_storage laddr;
695 netops::bind(listenSock, reinterpret_cast<sockaddr*>(&laddr), laddrLen);
710 clientSock !=
NetworkSocket(),
"failed to create client socket");
711 if (clientBindAddr !=
nullptr) {
712 sockaddr_storage clientAddr;
717 reinterpret_cast<sockaddr*>(&clientAddr),
722 sockaddr_storage listenAddr;
726 reinterpret_cast<sockaddr*>(&listenAddr),
730 sockaddr_storage acceptAddr;
731 socklen_t acceptAddrLen =
sizeof(acceptAddr);
733 listenSock, reinterpret_cast<sockaddr*>(&acceptAddr), &acceptAddrLen);
736 reinterpret_cast<sockaddr*>(&acceptAddr), acceptAddrLen);
792 path.append(
"test address");
859 unlink(serverPath.c_str());
860 unlink(clientPath.c_str());
863 unlink(serverPath.c_str());
864 unlink(clientPath.c_str());
905 unlink(serverPath.c_str());
908 unlink(serverPath.c_str());
951 folly::IPAddress ipAddr(
"123.234.0.23");
955 folly::IPAddress ip6Addr(
"2620:0:1cfe:face:b00c::3");
void testSetFromSocket(const SocketAddress *serverBindAddr, const SocketAddress *clientBindAddr, SocketAddress *listenAddrRet, SocketAddress *acceptAddrRet, SocketAddress *serverAddrRet, SocketAddress *serverPeerAddrRet, SocketAddress *clientAddrRet, SocketAddress *clientPeerAddrRet)
#define REQUIRE_ERRNO(cond, msg)
void setFromLocalIpPort(const char *addressAndPort)
void setFromPath(StringPiece path)
void setFromIpAddrPort(const IPAddress &ip, uint16_t port)
void setFromPeerAddress(int socket)
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
#define EXPECT_THROW(statement, expected_exception)
bool prefixMatch(const SocketAddress &other, unsigned prefixLength) const
void setFromHostPort(const char *host, uint16_t port)
void setFromLocalPort(uint16_t port)
bool isIPv4Mapped() const
#define EXPECT_EQ(val1, val2)
constexpr array_detail::return_type< D, TList... > make_array(TList &&...t)
constexpr detail::Map< Move > move
socklen_t getActualSize() const
void setFromSockaddr(const struct sockaddr *address)
std::string getPath() const
std::string describe() const
#define EXPECT_STREQ(s1, s2)
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
TEST(SocketAddress, Size)
bool isFamilyInet() const
sa_family_t getFamily() const
bool isInitialized() const
void CheckPrefixMatch(const SocketAddress &first, const SocketAddress &second, unsigned matchingPrefixLen)
const folly::IPAddress & getIPAddress() const
NetworkSocket socket(int af, int type, int protocol)
socklen_t getAddress(sockaddr_storage *addr) const
int listen(NetworkSocket s, int backlog)
void setFromIpPort(const char *ip, uint16_t port)
#define EXPECT_TRUE(condition)
void setFromLocalAddress(int socket)
int bind(NetworkSocket s, const sockaddr *name, socklen_t namelen)
bool isPrivateAddress() const
#define EXPECT_NE(val1, val2)
void join(const Delim &delimiter, Iterator begin, Iterator end, String &output)
#define EXPECT_FALSE(condition)
int close(NetworkSocket s)
ThreadPoolListHook * addr
const fs::path & path() const
bool isLoopbackAddress() const
std::string getAddressStr() const
constexpr detail::First first
void CheckFirstLessThanSecond(SocketAddress first, SocketAddress second)
int socketpair(int domain, int type, int protocol, NetworkSocket sv[2])
NetworkSocket accept(NetworkSocket s, sockaddr *addr, socklen_t *addrlen)