diff options
author | Matthew Zipkin <pinheadmz@gmail.com> | 2023-05-26 12:26:43 -0400 |
---|---|---|
committer | Matthew Zipkin <pinheadmz@gmail.com> | 2024-03-01 13:13:07 -0500 |
commit | bae86c8d318d06818aa75a9ebe3db864197f0bc6 (patch) | |
tree | 893a4fde71f37fcfab090b216a8f097ce9308fb8 /src/netbase.cpp | |
parent | adb3a3e51de205cc69b1a58647c65c04fa6c6362 (diff) | |
download | bitcoin-bae86c8d318d06818aa75a9ebe3db864197f0bc6.tar.xz |
netbase: refactor CreateSock() to accept sa_family_t
Also implement CService::GetSAFamily() to provide sa_family_t
Diffstat (limited to 'src/netbase.cpp')
-rw-r--r-- | src/netbase.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp index 9fbd9f7dea..973d888722 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -444,18 +444,13 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a } } -std::unique_ptr<Sock> CreateSockTCP(const CService& address_family) +std::unique_ptr<Sock> CreateSockOS(sa_family_t address_family) { - // Create a sockaddr from the specified service. - struct sockaddr_storage sockaddr; - socklen_t len = sizeof(sockaddr); - if (!address_family.GetSockAddr((struct sockaddr*)&sockaddr, &len)) { - LogPrintf("Cannot create socket for %s: unsupported network\n", address_family.ToStringAddrPort()); - return nullptr; - } + // Not IPv4 or IPv6 + if (address_family == AF_UNSPEC) return nullptr; // Create a TCP socket in the address family of the specified service. - SOCKET hSocket = socket(((struct sockaddr*)&sockaddr)->sa_family, SOCK_STREAM, IPPROTO_TCP); + SOCKET hSocket = socket(address_family, SOCK_STREAM, IPPROTO_TCP); if (hSocket == INVALID_SOCKET) { return nullptr; } @@ -493,7 +488,7 @@ std::unique_ptr<Sock> CreateSockTCP(const CService& address_family) return sock; } -std::function<std::unique_ptr<Sock>(const CService&)> CreateSock = CreateSockTCP; +std::function<std::unique_ptr<Sock>(const sa_family_t&)> CreateSock = CreateSockOS; template<typename... Args> static void LogConnectFailure(bool manual_connection, const char* fmt, const Args&... args) { |