LCOV - code coverage report
Current view: top level - src - netbase.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 29 390 7.4 %
Date: 2023-11-10 23:46:46 Functions: 3 32 9.4 %
Branches: 28 656 4.3 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2                 :            : // Copyright (c) 2009-2022 The Bitcoin Core developers
       3                 :            : // Distributed under the MIT software license, see the accompanying
       4                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5                 :            : 
       6                 :            : #include <netbase.h>
       7                 :            : 
       8                 :            : #include <compat/compat.h>
       9                 :            : #include <logging.h>
      10                 :            : #include <sync.h>
      11                 :            : #include <tinyformat.h>
      12                 :            : #include <util/sock.h>
      13                 :            : #include <util/strencodings.h>
      14                 :            : #include <util/string.h>
      15                 :            : #include <util/time.h>
      16                 :            : 
      17                 :            : #include <atomic>
      18                 :            : #include <chrono>
      19                 :            : #include <cstdint>
      20                 :            : #include <functional>
      21                 :            : #include <limits>
      22                 :            : #include <memory>
      23                 :            : 
      24                 :            : // Settings
      25                 :            : static GlobalMutex g_proxyinfo_mutex;
      26 [ +  - ][ +  + ]:         14 : static Proxy proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex);
      27                 :          2 : static Proxy nameProxy GUARDED_BY(g_proxyinfo_mutex);
      28                 :            : int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
      29                 :            : bool fNameLookup = DEFAULT_NAME_LOOKUP;
      30                 :            : 
      31                 :            : // Need ample time for negotiation for very slow proxies such as Tor
      32                 :            : std::chrono::milliseconds g_socks5_recv_timeout = 20s;
      33                 :            : static std::atomic<bool> interruptSocks5Recv(false);
      34                 :            : 
      35                 :          2 : ReachableNets g_reachable_nets;
      36                 :            : 
      37                 :          0 : std::vector<CNetAddr> WrappedGetAddrInfo(const std::string& name, bool allow_lookup)
      38                 :            : {
      39                 :          0 :     addrinfo ai_hint{};
      40                 :            :     // We want a TCP port, which is a streaming socket type
      41                 :          0 :     ai_hint.ai_socktype = SOCK_STREAM;
      42                 :          0 :     ai_hint.ai_protocol = IPPROTO_TCP;
      43                 :            :     // We don't care which address family (IPv4 or IPv6) is returned
      44                 :          0 :     ai_hint.ai_family = AF_UNSPEC;
      45                 :            :     // If we allow lookups of hostnames, use the AI_ADDRCONFIG flag to only
      46                 :            :     // return addresses whose family we have an address configured for.
      47                 :            :     //
      48                 :            :     // If we don't allow lookups, then use the AI_NUMERICHOST flag for
      49                 :            :     // getaddrinfo to only decode numerical network addresses and suppress
      50                 :            :     // hostname lookups.
      51                 :          0 :     ai_hint.ai_flags = allow_lookup ? AI_ADDRCONFIG : AI_NUMERICHOST;
      52                 :            : 
      53                 :          0 :     addrinfo* ai_res{nullptr};
      54                 :          0 :     const int n_err{getaddrinfo(name.c_str(), nullptr, &ai_hint, &ai_res)};
      55         [ #  # ]:          0 :     if (n_err != 0) {
      56                 :          0 :         return {};
      57                 :            :     }
      58                 :            : 
      59                 :            :     // Traverse the linked list starting with ai_trav.
      60                 :          0 :     addrinfo* ai_trav{ai_res};
      61                 :          0 :     std::vector<CNetAddr> resolved_addresses;
      62         [ #  # ]:          0 :     while (ai_trav != nullptr) {
      63         [ #  # ]:          0 :         if (ai_trav->ai_family == AF_INET) {
      64         [ #  # ]:          0 :             assert(ai_trav->ai_addrlen >= sizeof(sockaddr_in));
      65         [ #  # ]:          0 :             resolved_addresses.emplace_back(reinterpret_cast<sockaddr_in*>(ai_trav->ai_addr)->sin_addr);
      66                 :          0 :         }
      67         [ #  # ]:          0 :         if (ai_trav->ai_family == AF_INET6) {
      68         [ #  # ]:          0 :             assert(ai_trav->ai_addrlen >= sizeof(sockaddr_in6));
      69                 :          0 :             const sockaddr_in6* s6{reinterpret_cast<sockaddr_in6*>(ai_trav->ai_addr)};
      70         [ #  # ]:          0 :             resolved_addresses.emplace_back(s6->sin6_addr, s6->sin6_scope_id);
      71                 :          0 :         }
      72                 :          0 :         ai_trav = ai_trav->ai_next;
      73                 :            :     }
      74                 :          0 :     freeaddrinfo(ai_res);
      75                 :            : 
      76                 :          0 :     return resolved_addresses;
      77         [ #  # ]:          0 : }
      78                 :            : 
      79                 :          2 : DNSLookupFn g_dns_lookup{WrappedGetAddrInfo};
      80                 :            : 
      81                 :          0 : enum Network ParseNetwork(const std::string& net_in) {
      82                 :          0 :     std::string net = ToLower(net_in);
      83 [ #  # ][ #  # ]:          0 :     if (net == "ipv4") return NET_IPV4;
      84 [ #  # ][ #  # ]:          0 :     if (net == "ipv6") return NET_IPV6;
      85 [ #  # ][ #  # ]:          0 :     if (net == "onion") return NET_ONION;
      86 [ #  # ][ #  # ]:          0 :     if (net == "tor") {
      87 [ #  # ][ #  # ]:          0 :         LogPrintf("Warning: net name 'tor' is deprecated and will be removed in the future. You should use 'onion' instead.\n");
                 [ #  # ]
      88                 :          0 :         return NET_ONION;
      89                 :            :     }
      90 [ #  # ][ #  # ]:          0 :     if (net == "i2p") {
      91                 :          0 :         return NET_I2P;
      92                 :            :     }
      93 [ #  # ][ #  # ]:          0 :     if (net == "cjdns") {
      94                 :          0 :         return NET_CJDNS;
      95                 :            :     }
      96                 :          0 :     return NET_UNROUTABLE;
      97                 :          0 : }
      98                 :            : 
      99                 :         77 : std::string GetNetworkName(enum Network net)
     100                 :            : {
     101   [ +  +  +  +  :         77 :     switch (net) {
             +  -  +  -  
                      - ]
     102         [ +  - ]:          2 :     case NET_UNROUTABLE: return "not_publicly_routable";
     103         [ +  - ]:         15 :     case NET_IPV4: return "ipv4";
     104         [ +  - ]:         15 :     case NET_IPV6: return "ipv6";
     105         [ +  - ]:         15 :     case NET_ONION: return "onion";
     106         [ +  - ]:         15 :     case NET_I2P: return "i2p";
     107         [ +  - ]:         15 :     case NET_CJDNS: return "cjdns";
     108         [ #  # ]:          0 :     case NET_INTERNAL: return "internal";
     109                 :          0 :     case NET_MAX: assert(false);
     110                 :            :     } // no default case, so the compiler can warn about missing cases
     111                 :            : 
     112                 :          0 :     assert(false);
     113                 :         77 : }
     114                 :            : 
     115                 :         15 : std::vector<std::string> GetNetworkNames(bool append_unroutable)
     116                 :            : {
     117                 :         15 :     std::vector<std::string> names;
     118         [ +  + ]:        120 :     for (int n = 0; n < NET_MAX; ++n) {
     119                 :        105 :         const enum Network network{static_cast<Network>(n)};
     120 [ +  + ][ +  + ]:        105 :         if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
     121 [ +  - ][ +  - ]:         75 :         names.emplace_back(GetNetworkName(network));
     122                 :         75 :     }
     123         [ +  + ]:         15 :     if (append_unroutable) {
     124 [ +  - ][ -  + ]:          2 :         names.emplace_back(GetNetworkName(NET_UNROUTABLE));
     125                 :          2 :     }
     126                 :         15 :     return names;
     127         [ +  - ]:         15 : }
     128                 :            : 
     129                 :          0 : static std::vector<CNetAddr> LookupIntern(const std::string& name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
     130                 :            : {
     131         [ #  # ]:          0 :     if (!ContainsNoNUL(name)) return {};
     132                 :            :     {
     133                 :          0 :         CNetAddr addr;
     134                 :            :         // From our perspective, onion addresses are not hostnames but rather
     135                 :            :         // direct encodings of CNetAddr much like IPv4 dotted-decimal notation
     136                 :            :         // or IPv6 colon-separated hextet notation. Since we can't use
     137                 :            :         // getaddrinfo to decode them and it wouldn't make sense to resolve
     138                 :            :         // them, we return a network address representing it instead. See
     139                 :            :         // CNetAddr::SetSpecial(const std::string&) for more details.
     140 [ #  # ][ #  # ]:          0 :         if (addr.SetSpecial(name)) return {addr};
         [ #  # ][ #  # ]
     141      [ #  #  # ]:          0 :     }
     142                 :            : 
     143                 :          0 :     std::vector<CNetAddr> addresses;
     144                 :            : 
     145 [ #  # ][ #  # ]:          0 :     for (const CNetAddr& resolved : dns_lookup_function(name, fAllowLookup)) {
     146 [ #  # ][ #  # ]:          0 :         if (nMaxSolutions > 0 && addresses.size() >= nMaxSolutions) {
     147                 :          0 :             break;
     148                 :            :         }
     149                 :            :         /* Never allow resolving to an internal address. Consider any such result invalid */
     150 [ #  # ][ #  # ]:          0 :         if (!resolved.IsInternal()) {
     151         [ #  # ]:          0 :             addresses.push_back(resolved);
     152                 :          0 :         }
     153                 :            :     }
     154                 :            : 
     155                 :          0 :     return addresses;
     156         [ #  # ]:          0 : }
     157                 :            : 
     158                 :          0 : std::vector<CNetAddr> LookupHost(const std::string& name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
     159                 :            : {
     160         [ #  # ]:          0 :     if (!ContainsNoNUL(name)) return {};
     161                 :          0 :     std::string strHost = name;
     162         [ #  # ]:          0 :     if (strHost.empty()) return {};
     163 [ #  # ][ #  # ]:          0 :     if (strHost.front() == '[' && strHost.back() == ']') {
     164         [ #  # ]:          0 :         strHost = strHost.substr(1, strHost.size() - 2);
     165                 :          0 :     }
     166                 :            : 
     167 [ #  # ][ #  # ]:          0 :     return LookupIntern(strHost, nMaxSolutions, fAllowLookup, dns_lookup_function);
     168                 :          0 : }
     169                 :            : 
     170                 :          0 : std::optional<CNetAddr> LookupHost(const std::string& name, bool fAllowLookup, DNSLookupFn dns_lookup_function)
     171                 :            : {
     172         [ #  # ]:          0 :     const std::vector<CNetAddr> addresses{LookupHost(name, 1, fAllowLookup, dns_lookup_function)};
     173 [ #  # ][ #  # ]:          0 :     return addresses.empty() ? std::nullopt : std::make_optional(addresses.front());
     174                 :          0 : }
     175                 :            : 
     176                 :          0 : std::vector<CService> Lookup(const std::string& name, uint16_t portDefault, bool fAllowLookup, unsigned int nMaxSolutions, DNSLookupFn dns_lookup_function)
     177                 :            : {
     178 [ #  # ][ #  # ]:          0 :     if (name.empty() || !ContainsNoNUL(name)) {
     179                 :          0 :         return {};
     180                 :            :     }
     181                 :          0 :     uint16_t port{portDefault};
     182                 :          0 :     std::string hostname;
     183         [ #  # ]:          0 :     SplitHostPort(name, port, hostname);
     184                 :            : 
     185 [ #  # ][ #  # ]:          0 :     const std::vector<CNetAddr> addresses{LookupIntern(hostname, nMaxSolutions, fAllowLookup, dns_lookup_function)};
     186         [ #  # ]:          0 :     if (addresses.empty()) return {};
     187                 :          0 :     std::vector<CService> services;
     188         [ #  # ]:          0 :     services.reserve(addresses.size());
     189         [ #  # ]:          0 :     for (const auto& addr : addresses)
     190         [ #  # ]:          0 :         services.emplace_back(addr, port);
     191                 :          0 :     return services;
     192         [ #  # ]:          0 : }
     193                 :            : 
     194                 :          0 : std::optional<CService> Lookup(const std::string& name, uint16_t portDefault, bool fAllowLookup, DNSLookupFn dns_lookup_function)
     195                 :            : {
     196         [ #  # ]:          0 :     const std::vector<CService> services{Lookup(name, portDefault, fAllowLookup, 1, dns_lookup_function)};
     197                 :            : 
     198 [ #  # ][ #  # ]:          0 :     return services.empty() ? std::nullopt : std::make_optional(services.front());
     199                 :          0 : }
     200                 :            : 
     201                 :          0 : CService LookupNumeric(const std::string& name, uint16_t portDefault, DNSLookupFn dns_lookup_function)
     202                 :            : {
     203         [ #  # ]:          0 :     if (!ContainsNoNUL(name)) {
     204                 :          0 :         return {};
     205                 :            :     }
     206                 :            :     // "1.2:345" will fail to resolve the ip, but will still set the port.
     207                 :            :     // If the ip fails to resolve, re-init the result.
     208 [ #  # ][ #  # ]:          0 :     return Lookup(name, portDefault, /*fAllowLookup=*/false, dns_lookup_function).value_or(CService{});
                 [ #  # ]
     209                 :          0 : }
     210                 :            : 
     211                 :            : /** SOCKS version */
     212                 :            : enum SOCKSVersion: uint8_t {
     213                 :            :     SOCKS4 = 0x04,
     214                 :            :     SOCKS5 = 0x05
     215                 :            : };
     216                 :            : 
     217                 :            : /** Values defined for METHOD in RFC1928 */
     218                 :            : enum SOCKS5Method: uint8_t {
     219                 :            :     NOAUTH = 0x00,        //!< No authentication required
     220                 :            :     GSSAPI = 0x01,        //!< GSSAPI
     221                 :            :     USER_PASS = 0x02,     //!< Username/password
     222                 :            :     NO_ACCEPTABLE = 0xff, //!< No acceptable methods
     223                 :            : };
     224                 :            : 
     225                 :            : /** Values defined for CMD in RFC1928 */
     226                 :            : enum SOCKS5Command: uint8_t {
     227                 :            :     CONNECT = 0x01,
     228                 :            :     BIND = 0x02,
     229                 :            :     UDP_ASSOCIATE = 0x03
     230                 :            : };
     231                 :            : 
     232                 :            : /** Values defined for REP in RFC1928 */
     233                 :            : enum SOCKS5Reply: uint8_t {
     234                 :            :     SUCCEEDED = 0x00,        //!< Succeeded
     235                 :            :     GENFAILURE = 0x01,       //!< General failure
     236                 :            :     NOTALLOWED = 0x02,       //!< Connection not allowed by ruleset
     237                 :            :     NETUNREACHABLE = 0x03,   //!< Network unreachable
     238                 :            :     HOSTUNREACHABLE = 0x04,  //!< Network unreachable
     239                 :            :     CONNREFUSED = 0x05,      //!< Connection refused
     240                 :            :     TTLEXPIRED = 0x06,       //!< TTL expired
     241                 :            :     CMDUNSUPPORTED = 0x07,   //!< Command not supported
     242                 :            :     ATYPEUNSUPPORTED = 0x08, //!< Address type not supported
     243                 :            : };
     244                 :            : 
     245                 :            : /** Values defined for ATYPE in RFC1928 */
     246                 :            : enum SOCKS5Atyp: uint8_t {
     247                 :            :     IPV4 = 0x01,
     248                 :            :     DOMAINNAME = 0x03,
     249                 :            :     IPV6 = 0x04,
     250                 :            : };
     251                 :            : 
     252                 :            : /** Status codes that can be returned by InterruptibleRecv */
     253                 :            : enum class IntrRecvError {
     254                 :            :     OK,
     255                 :            :     Timeout,
     256                 :            :     Disconnected,
     257                 :            :     NetworkError,
     258                 :            :     Interrupted
     259                 :            : };
     260                 :            : 
     261                 :            : /**
     262                 :            :  * Try to read a specified number of bytes from a socket. Please read the "see
     263                 :            :  * also" section for more detail.
     264                 :            :  *
     265                 :            :  * @param data The buffer where the read bytes should be stored.
     266                 :            :  * @param len The number of bytes to read into the specified buffer.
     267                 :            :  * @param timeout The total timeout for this read.
     268                 :            :  * @param sock The socket (has to be in non-blocking mode) from which to read bytes.
     269                 :            :  *
     270                 :            :  * @returns An IntrRecvError indicating the resulting status of this read.
     271                 :            :  *          IntrRecvError::OK only if all of the specified number of bytes were
     272                 :            :  *          read.
     273                 :            :  *
     274                 :            :  * @see This function can be interrupted by calling InterruptSocks5(bool).
     275                 :            :  *      Sockets can be made non-blocking with Sock::SetNonBlocking().
     276                 :            :  */
     277                 :          0 : static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, std::chrono::milliseconds timeout, const Sock& sock)
     278                 :            : {
     279                 :          0 :     auto curTime{Now<SteadyMilliseconds>()};
     280                 :          0 :     const auto endTime{curTime + timeout};
     281 [ #  # ][ #  # ]:          0 :     while (len > 0 && curTime < endTime) {
     282                 :          0 :         ssize_t ret = sock.Recv(data, len, 0); // Optimistically try the recv first
     283         [ #  # ]:          0 :         if (ret > 0) {
     284                 :          0 :             len -= ret;
     285                 :          0 :             data += ret;
     286         [ #  # ]:          0 :         } else if (ret == 0) { // Unexpected disconnection
     287                 :          0 :             return IntrRecvError::Disconnected;
     288                 :            :         } else { // Other error or blocking
     289                 :          0 :             int nErr = WSAGetLastError();
     290 [ #  # ][ #  # ]:          0 :             if (nErr == WSAEINPROGRESS || nErr == WSAEWOULDBLOCK || nErr == WSAEINVAL) {
                 [ #  # ]
     291                 :            :                 // Only wait at most MAX_WAIT_FOR_IO at a time, unless
     292                 :            :                 // we're approaching the end of the specified total timeout
     293                 :          0 :                 const auto remaining = std::chrono::milliseconds{endTime - curTime};
     294                 :          0 :                 const auto timeout = std::min(remaining, std::chrono::milliseconds{MAX_WAIT_FOR_IO});
     295         [ #  # ]:          0 :                 if (!sock.Wait(timeout, Sock::RECV)) {
     296                 :          0 :                     return IntrRecvError::NetworkError;
     297                 :            :                 }
     298                 :          0 :             } else {
     299                 :          0 :                 return IntrRecvError::NetworkError;
     300                 :            :             }
     301                 :            :         }
     302         [ #  # ]:          0 :         if (interruptSocks5Recv)
     303                 :          0 :             return IntrRecvError::Interrupted;
     304                 :          0 :         curTime = Now<SteadyMilliseconds>();
     305                 :            :     }
     306                 :          0 :     return len == 0 ? IntrRecvError::OK : IntrRecvError::Timeout;
     307                 :          0 : }
     308                 :            : 
     309                 :            : /** Convert SOCKS5 reply to an error message */
     310                 :          0 : static std::string Socks5ErrorString(uint8_t err)
     311                 :            : {
     312   [ #  #  #  #  :          0 :     switch(err) {
             #  #  #  #  
                      # ]
     313                 :            :         case SOCKS5Reply::GENFAILURE:
     314         [ #  # ]:          0 :             return "general failure";
     315                 :            :         case SOCKS5Reply::NOTALLOWED:
     316         [ #  # ]:          0 :             return "connection not allowed";
     317                 :            :         case SOCKS5Reply::NETUNREACHABLE:
     318         [ #  # ]:          0 :             return "network unreachable";
     319                 :            :         case SOCKS5Reply::HOSTUNREACHABLE:
     320         [ #  # ]:          0 :             return "host unreachable";
     321                 :            :         case SOCKS5Reply::CONNREFUSED:
     322         [ #  # ]:          0 :             return "connection refused";
     323                 :            :         case SOCKS5Reply::TTLEXPIRED:
     324         [ #  # ]:          0 :             return "TTL expired";
     325                 :            :         case SOCKS5Reply::CMDUNSUPPORTED:
     326         [ #  # ]:          0 :             return "protocol error";
     327                 :            :         case SOCKS5Reply::ATYPEUNSUPPORTED:
     328         [ #  # ]:          0 :             return "address type not supported";
     329                 :            :         default:
     330         [ #  # ]:          0 :             return "unknown";
     331                 :            :     }
     332                 :          0 : }
     333                 :            : 
     334                 :          0 : bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* auth, const Sock& sock)
     335                 :            : {
     336                 :            :     IntrRecvError recvr;
     337 [ #  # ][ #  # ]:          0 :     LogPrint(BCLog::NET, "SOCKS5 connecting %s\n", strDest);
         [ #  # ][ #  # ]
     338         [ #  # ]:          0 :     if (strDest.size() > 255) {
     339                 :          0 :         return error("Hostname too long");
     340                 :            :     }
     341                 :            :     // Construct the version identifier/method selection message
     342                 :          0 :     std::vector<uint8_t> vSocks5Init;
     343         [ #  # ]:          0 :     vSocks5Init.push_back(SOCKSVersion::SOCKS5); // We want the SOCK5 protocol
     344         [ #  # ]:          0 :     if (auth) {
     345         [ #  # ]:          0 :         vSocks5Init.push_back(0x02); // 2 method identifiers follow...
     346         [ #  # ]:          0 :         vSocks5Init.push_back(SOCKS5Method::NOAUTH);
     347         [ #  # ]:          0 :         vSocks5Init.push_back(SOCKS5Method::USER_PASS);
     348                 :          0 :     } else {
     349         [ #  # ]:          0 :         vSocks5Init.push_back(0x01); // 1 method identifier follows...
     350         [ #  # ]:          0 :         vSocks5Init.push_back(SOCKS5Method::NOAUTH);
     351                 :            :     }
     352         [ #  # ]:          0 :     ssize_t ret = sock.Send(vSocks5Init.data(), vSocks5Init.size(), MSG_NOSIGNAL);
     353         [ #  # ]:          0 :     if (ret != (ssize_t)vSocks5Init.size()) {
     354         [ #  # ]:          0 :         return error("Error sending to proxy");
     355                 :            :     }
     356                 :            :     uint8_t pchRet1[2];
     357 [ #  # ][ #  # ]:          0 :     if (InterruptibleRecv(pchRet1, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
     358 [ #  # ][ #  # ]:          0 :         LogPrintf("Socks5() connect to %s:%d failed: InterruptibleRecv() timeout or other failure\n", strDest, port);
                 [ #  # ]
     359                 :          0 :         return false;
     360                 :            :     }
     361         [ #  # ]:          0 :     if (pchRet1[0] != SOCKSVersion::SOCKS5) {
     362         [ #  # ]:          0 :         return error("Proxy failed to initialize");
     363                 :            :     }
     364 [ #  # ][ #  # ]:          0 :     if (pchRet1[1] == SOCKS5Method::USER_PASS && auth) {
     365                 :            :         // Perform username/password authentication (as described in RFC1929)
     366                 :          0 :         std::vector<uint8_t> vAuth;
     367         [ #  # ]:          0 :         vAuth.push_back(0x01); // Current (and only) version of user/pass subnegotiation
     368 [ #  # ][ #  # ]:          0 :         if (auth->username.size() > 255 || auth->password.size() > 255)
     369         [ #  # ]:          0 :             return error("Proxy username or password too long");
     370         [ #  # ]:          0 :         vAuth.push_back(auth->username.size());
     371         [ #  # ]:          0 :         vAuth.insert(vAuth.end(), auth->username.begin(), auth->username.end());
     372         [ #  # ]:          0 :         vAuth.push_back(auth->password.size());
     373         [ #  # ]:          0 :         vAuth.insert(vAuth.end(), auth->password.begin(), auth->password.end());
     374         [ #  # ]:          0 :         ret = sock.Send(vAuth.data(), vAuth.size(), MSG_NOSIGNAL);
     375         [ #  # ]:          0 :         if (ret != (ssize_t)vAuth.size()) {
     376         [ #  # ]:          0 :             return error("Error sending authentication to proxy");
     377                 :            :         }
     378 [ #  # ][ #  # ]:          0 :         LogPrint(BCLog::PROXY, "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password);
         [ #  # ][ #  # ]
                 [ #  # ]
     379                 :            :         uint8_t pchRetA[2];
     380 [ #  # ][ #  # ]:          0 :         if (InterruptibleRecv(pchRetA, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
     381         [ #  # ]:          0 :             return error("Error reading proxy authentication response");
     382                 :            :         }
     383 [ #  # ][ #  # ]:          0 :         if (pchRetA[0] != 0x01 || pchRetA[1] != 0x00) {
     384         [ #  # ]:          0 :             return error("Proxy authentication unsuccessful");
     385                 :            :         }
     386 [ #  # ][ #  # ]:          0 :     } else if (pchRet1[1] == SOCKS5Method::NOAUTH) {
     387                 :            :         // Perform no authentication
     388                 :          0 :     } else {
     389         [ #  # ]:          0 :         return error("Proxy requested wrong authentication method %02x", pchRet1[1]);
     390                 :            :     }
     391                 :          0 :     std::vector<uint8_t> vSocks5;
     392         [ #  # ]:          0 :     vSocks5.push_back(SOCKSVersion::SOCKS5); // VER protocol version
     393         [ #  # ]:          0 :     vSocks5.push_back(SOCKS5Command::CONNECT); // CMD CONNECT
     394         [ #  # ]:          0 :     vSocks5.push_back(0x00); // RSV Reserved must be 0
     395         [ #  # ]:          0 :     vSocks5.push_back(SOCKS5Atyp::DOMAINNAME); // ATYP DOMAINNAME
     396         [ #  # ]:          0 :     vSocks5.push_back(strDest.size()); // Length<=255 is checked at beginning of function
     397         [ #  # ]:          0 :     vSocks5.insert(vSocks5.end(), strDest.begin(), strDest.end());
     398         [ #  # ]:          0 :     vSocks5.push_back((port >> 8) & 0xFF);
     399         [ #  # ]:          0 :     vSocks5.push_back((port >> 0) & 0xFF);
     400         [ #  # ]:          0 :     ret = sock.Send(vSocks5.data(), vSocks5.size(), MSG_NOSIGNAL);
     401         [ #  # ]:          0 :     if (ret != (ssize_t)vSocks5.size()) {
     402         [ #  # ]:          0 :         return error("Error sending to proxy");
     403                 :            :     }
     404                 :            :     uint8_t pchRet2[4];
     405 [ #  # ][ #  # ]:          0 :     if ((recvr = InterruptibleRecv(pchRet2, 4, g_socks5_recv_timeout, sock)) != IntrRecvError::OK) {
     406         [ #  # ]:          0 :         if (recvr == IntrRecvError::Timeout) {
     407                 :            :             /* If a timeout happens here, this effectively means we timed out while connecting
     408                 :            :              * to the remote node. This is very common for Tor, so do not print an
     409                 :            :              * error message. */
     410                 :          0 :             return false;
     411                 :            :         } else {
     412         [ #  # ]:          0 :             return error("Error while reading proxy response");
     413                 :            :         }
     414                 :            :     }
     415         [ #  # ]:          0 :     if (pchRet2[0] != SOCKSVersion::SOCKS5) {
     416         [ #  # ]:          0 :         return error("Proxy failed to accept request");
     417                 :            :     }
     418         [ #  # ]:          0 :     if (pchRet2[1] != SOCKS5Reply::SUCCEEDED) {
     419                 :            :         // Failures to connect to a peer that are not proxy errors
     420 [ #  # ][ #  # ]:          0 :         LogPrintf("Socks5() connect to %s:%d failed: %s\n", strDest, port, Socks5ErrorString(pchRet2[1]));
         [ #  # ][ #  # ]
     421                 :          0 :         return false;
     422                 :            :     }
     423         [ #  # ]:          0 :     if (pchRet2[2] != 0x00) { // Reserved field must be 0
     424         [ #  # ]:          0 :         return error("Error: malformed proxy response");
     425                 :            :     }
     426                 :            :     uint8_t pchRet3[256];
     427   [ #  #  #  # ]:          0 :     switch (pchRet2[3])
     428                 :            :     {
     429         [ #  # ]:          0 :         case SOCKS5Atyp::IPV4: recvr = InterruptibleRecv(pchRet3, 4, g_socks5_recv_timeout, sock); break;
     430         [ #  # ]:          0 :         case SOCKS5Atyp::IPV6: recvr = InterruptibleRecv(pchRet3, 16, g_socks5_recv_timeout, sock); break;
     431                 :            :         case SOCKS5Atyp::DOMAINNAME:
     432                 :            :         {
     433         [ #  # ]:          0 :             recvr = InterruptibleRecv(pchRet3, 1, g_socks5_recv_timeout, sock);
     434         [ #  # ]:          0 :             if (recvr != IntrRecvError::OK) {
     435         [ #  # ]:          0 :                 return error("Error reading from proxy");
     436                 :            :             }
     437                 :          0 :             int nRecv = pchRet3[0];
     438         [ #  # ]:          0 :             recvr = InterruptibleRecv(pchRet3, nRecv, g_socks5_recv_timeout, sock);
     439                 :          0 :             break;
     440                 :            :         }
     441         [ #  # ]:          0 :         default: return error("Error: malformed proxy response");
     442                 :            :     }
     443         [ #  # ]:          0 :     if (recvr != IntrRecvError::OK) {
     444         [ #  # ]:          0 :         return error("Error reading from proxy");
     445                 :            :     }
     446 [ #  # ][ #  # ]:          0 :     if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
     447         [ #  # ]:          0 :         return error("Error reading from proxy");
     448                 :            :     }
     449 [ #  # ][ #  # ]:          0 :     LogPrint(BCLog::NET, "SOCKS5 connected %s\n", strDest);
         [ #  # ][ #  # ]
                 [ #  # ]
     450                 :          0 :     return true;
     451                 :          0 : }
     452                 :            : 
     453                 :          0 : std::unique_ptr<Sock> CreateSockTCP(const CService& address_family)
     454                 :            : {
     455                 :            :     // Create a sockaddr from the specified service.
     456                 :            :     struct sockaddr_storage sockaddr;
     457                 :          0 :     socklen_t len = sizeof(sockaddr);
     458         [ #  # ]:          0 :     if (!address_family.GetSockAddr((struct sockaddr*)&sockaddr, &len)) {
     459 [ #  # ][ #  # ]:          0 :         LogPrintf("Cannot create socket for %s: unsupported network\n", address_family.ToStringAddrPort());
         [ #  # ][ #  # ]
     460                 :          0 :         return nullptr;
     461                 :            :     }
     462                 :            : 
     463                 :            :     // Create a TCP socket in the address family of the specified service.
     464                 :          0 :     SOCKET hSocket = socket(((struct sockaddr*)&sockaddr)->sa_family, SOCK_STREAM, IPPROTO_TCP);
     465         [ #  # ]:          0 :     if (hSocket == INVALID_SOCKET) {
     466                 :          0 :         return nullptr;
     467                 :            :     }
     468                 :            : 
     469                 :          0 :     auto sock = std::make_unique<Sock>(hSocket);
     470                 :            : 
     471                 :            :     // Ensure that waiting for I/O on this socket won't result in undefined
     472                 :            :     // behavior.
     473 [ #  # ][ #  # ]:          0 :     if (!sock->IsSelectable()) {
     474 [ #  # ][ #  # ]:          0 :         LogPrintf("Cannot create connection: non-selectable socket created (fd >= FD_SETSIZE ?)\n");
                 [ #  # ]
     475                 :          0 :         return nullptr;
     476                 :            :     }
     477                 :            : 
     478                 :            : #ifdef SO_NOSIGPIPE
     479                 :            :     int set = 1;
     480                 :            :     // Set the no-sigpipe option on the socket for BSD systems, other UNIXes
     481                 :            :     // should use the MSG_NOSIGNAL flag for every send.
     482                 :            :     if (sock->SetSockOpt(SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int)) == SOCKET_ERROR) {
     483                 :            :         LogPrintf("Error setting SO_NOSIGPIPE on socket: %s, continuing anyway\n",
     484                 :            :                   NetworkErrorString(WSAGetLastError()));
     485                 :            :     }
     486                 :            : #endif
     487                 :            : 
     488                 :            :     // Set the no-delay option (disable Nagle's algorithm) on the TCP socket.
     489                 :          0 :     const int on{1};
     490 [ #  # ][ #  # ]:          0 :     if (sock->SetSockOpt(IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) == SOCKET_ERROR) {
     491 [ #  # ][ #  # ]:          0 :         LogPrint(BCLog::NET, "Unable to set TCP_NODELAY on a newly created socket, continuing anyway\n");
         [ #  # ][ #  # ]
                 [ #  # ]
     492                 :          0 :     }
     493                 :            : 
     494                 :            :     // Set the non-blocking option on the socket.
     495 [ #  # ][ #  # ]:          0 :     if (!sock->SetNonBlocking()) {
     496 [ #  # ][ #  # ]:          0 :         LogPrintf("Error setting socket to non-blocking: %s\n", NetworkErrorString(WSAGetLastError()));
         [ #  # ][ #  # ]
     497                 :          0 :         return nullptr;
     498                 :            :     }
     499                 :          0 :     return sock;
     500                 :          0 : }
     501                 :            : 
     502                 :          2 : std::function<std::unique_ptr<Sock>(const CService&)> CreateSock = CreateSockTCP;
     503                 :            : 
     504                 :            : template<typename... Args>
     505                 :          0 : static void LogConnectFailure(bool manual_connection, const char* fmt, const Args&... args) {
     506                 :          0 :     std::string error_message = tfm::format(fmt, args...);
     507         [ #  # ]:          0 :     if (manual_connection) {
     508 [ #  # ][ #  # ]:          0 :         LogPrintf("%s\n", error_message);
                 [ #  # ]
     509                 :          0 :     } else {
     510 [ #  # ][ #  # ]:          0 :         LogPrint(BCLog::NET, "%s\n", error_message);
         [ #  # ][ #  # ]
                 [ #  # ]
     511                 :            :     }
     512                 :          0 : }
     513                 :            : 
     514                 :          0 : bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nTimeout, bool manual_connection)
     515                 :            : {
     516                 :            :     // Create a sockaddr from the specified service.
     517                 :            :     struct sockaddr_storage sockaddr;
     518                 :          0 :     socklen_t len = sizeof(sockaddr);
     519         [ #  # ]:          0 :     if (!addrConnect.GetSockAddr((struct sockaddr*)&sockaddr, &len)) {
     520 [ #  # ][ #  # ]:          0 :         LogPrintf("Cannot connect to %s: unsupported network\n", addrConnect.ToStringAddrPort());
         [ #  # ][ #  # ]
     521                 :          0 :         return false;
     522                 :            :     }
     523                 :            : 
     524                 :            :     // Connect to the addrConnect service on the hSocket socket.
     525         [ #  # ]:          0 :     if (sock.Connect(reinterpret_cast<struct sockaddr*>(&sockaddr), len) == SOCKET_ERROR) {
     526                 :          0 :         int nErr = WSAGetLastError();
     527                 :            :         // WSAEINVAL is here because some legacy version of winsock uses it
     528 [ #  # ][ #  # ]:          0 :         if (nErr == WSAEINPROGRESS || nErr == WSAEWOULDBLOCK || nErr == WSAEINVAL)
                 [ #  # ]
     529                 :            :         {
     530                 :            :             // Connection didn't actually fail, but is being established
     531                 :            :             // asynchronously. Thus, use async I/O api (select/poll)
     532                 :            :             // synchronously to check for successful connection with a timeout.
     533                 :          0 :             const Sock::Event requested = Sock::RECV | Sock::SEND;
     534                 :            :             Sock::Event occurred;
     535         [ #  # ]:          0 :             if (!sock.Wait(std::chrono::milliseconds{nTimeout}, requested, &occurred)) {
     536 [ #  # ][ #  # ]:          0 :                 LogPrintf("wait for connect to %s failed: %s\n",
         [ #  # ][ #  # ]
                 [ #  # ]
     537                 :            :                           addrConnect.ToStringAddrPort(),
     538                 :            :                           NetworkErrorString(WSAGetLastError()));
     539                 :          0 :                 return false;
     540         [ #  # ]:          0 :             } else if (occurred == 0) {
     541 [ #  # ][ #  # ]:          0 :                 LogPrint(BCLog::NET, "connection attempt to %s timed out\n", addrConnect.ToStringAddrPort());
         [ #  # ][ #  # ]
                 [ #  # ]
     542                 :          0 :                 return false;
     543                 :            :             }
     544                 :            : 
     545                 :            :             // Even if the wait was successful, the connect might not
     546                 :            :             // have been successful. The reason for this failure is hidden away
     547                 :            :             // in the SO_ERROR for the socket in modern systems. We read it into
     548                 :            :             // sockerr here.
     549                 :            :             int sockerr;
     550                 :          0 :             socklen_t sockerr_len = sizeof(sockerr);
     551         [ #  # ]:          0 :             if (sock.GetSockOpt(SOL_SOCKET, SO_ERROR, (sockopt_arg_type)&sockerr, &sockerr_len) ==
     552                 :            :                 SOCKET_ERROR) {
     553 [ #  # ][ #  # ]:          0 :                 LogPrintf("getsockopt() for %s failed: %s\n", addrConnect.ToStringAddrPort(), NetworkErrorString(WSAGetLastError()));
         [ #  # ][ #  # ]
                 [ #  # ]
     554                 :          0 :                 return false;
     555                 :            :             }
     556         [ #  # ]:          0 :             if (sockerr != 0) {
     557         [ #  # ]:          0 :                 LogConnectFailure(manual_connection,
     558                 :            :                                   "connect() to %s failed after wait: %s",
     559                 :          0 :                                   addrConnect.ToStringAddrPort(),
     560         [ #  # ]:          0 :                                   NetworkErrorString(sockerr));
     561                 :          0 :                 return false;
     562                 :            :             }
     563                 :          0 :         }
     564                 :            : #ifdef WIN32
     565                 :            :         else if (WSAGetLastError() != WSAEISCONN)
     566                 :            : #else
     567                 :            :         else
     568                 :            : #endif
     569                 :            :         {
     570 [ #  # ][ #  # ]:          0 :             LogConnectFailure(manual_connection, "connect() to %s failed: %s", addrConnect.ToStringAddrPort(), NetworkErrorString(WSAGetLastError()));
     571                 :          0 :             return false;
     572                 :            :         }
     573                 :          0 :     }
     574                 :          0 :     return true;
     575                 :          0 : }
     576                 :            : 
     577                 :          0 : bool SetProxy(enum Network net, const Proxy &addrProxy) {
     578 [ #  # ][ #  # ]:          0 :     assert(net >= 0 && net < NET_MAX);
     579         [ #  # ]:          0 :     if (!addrProxy.IsValid())
     580                 :          0 :         return false;
     581                 :          0 :     LOCK(g_proxyinfo_mutex);
     582         [ #  # ]:          0 :     proxyInfo[net] = addrProxy;
     583                 :          0 :     return true;
     584                 :          0 : }
     585                 :            : 
     586                 :          0 : bool GetProxy(enum Network net, Proxy &proxyInfoOut) {
     587 [ #  # ][ #  # ]:          0 :     assert(net >= 0 && net < NET_MAX);
     588                 :          0 :     LOCK(g_proxyinfo_mutex);
     589 [ #  # ][ #  # ]:          0 :     if (!proxyInfo[net].IsValid())
     590                 :          0 :         return false;
     591         [ #  # ]:          0 :     proxyInfoOut = proxyInfo[net];
     592                 :          0 :     return true;
     593                 :          0 : }
     594                 :            : 
     595                 :          0 : bool SetNameProxy(const Proxy &addrProxy) {
     596         [ #  # ]:          0 :     if (!addrProxy.IsValid())
     597                 :          0 :         return false;
     598                 :          0 :     LOCK(g_proxyinfo_mutex);
     599         [ #  # ]:          0 :     nameProxy = addrProxy;
     600                 :          0 :     return true;
     601                 :          0 : }
     602                 :            : 
     603                 :          0 : bool GetNameProxy(Proxy &nameProxyOut) {
     604                 :          0 :     LOCK(g_proxyinfo_mutex);
     605 [ #  # ][ #  # ]:          0 :     if(!nameProxy.IsValid())
     606                 :          0 :         return false;
     607         [ #  # ]:          0 :     nameProxyOut = nameProxy;
     608                 :          0 :     return true;
     609                 :          0 : }
     610                 :            : 
     611                 :          0 : bool HaveNameProxy() {
     612                 :          0 :     LOCK(g_proxyinfo_mutex);
     613         [ #  # ]:          0 :     return nameProxy.IsValid();
     614                 :          0 : }
     615                 :            : 
     616                 :          0 : bool IsProxy(const CNetAddr &addr) {
     617                 :          0 :     LOCK(g_proxyinfo_mutex);
     618         [ #  # ]:          0 :     for (int i = 0; i < NET_MAX; i++) {
     619 [ #  # ][ #  # ]:          0 :         if (addr == static_cast<CNetAddr>(proxyInfo[i].proxy))
                 [ #  # ]
     620                 :          0 :             return true;
     621                 :          0 :     }
     622                 :          0 :     return false;
     623                 :          0 : }
     624                 :            : 
     625                 :          0 : bool ConnectThroughProxy(const Proxy& proxy, const std::string& strDest, uint16_t port, const Sock& sock, int nTimeout, bool& outProxyConnectionFailed)
     626                 :            : {
     627                 :            :     // first connect to proxy server
     628         [ #  # ]:          0 :     if (!ConnectSocketDirectly(proxy.proxy, sock, nTimeout, true)) {
     629                 :          0 :         outProxyConnectionFailed = true;
     630                 :          0 :         return false;
     631                 :            :     }
     632                 :            :     // do socks negotiation
     633         [ #  # ]:          0 :     if (proxy.randomize_credentials) {
     634                 :          0 :         ProxyCredentials random_auth;
     635                 :            :         static std::atomic_int counter(0);
     636 [ #  # ][ #  # ]:          0 :         random_auth.username = random_auth.password = strprintf("%i", counter++);
     637 [ #  # ][ #  # ]:          0 :         if (!Socks5(strDest, port, &random_auth, sock)) {
     638                 :          0 :             return false;
     639                 :            :         }
     640      [ #  #  # ]:          0 :     } else {
     641         [ #  # ]:          0 :         if (!Socks5(strDest, port, nullptr, sock)) {
     642                 :          0 :             return false;
     643                 :            :         }
     644                 :            :     }
     645                 :          0 :     return true;
     646                 :          0 : }
     647                 :            : 
     648                 :          0 : CSubNet LookupSubNet(const std::string& subnet_str)
     649                 :            : {
     650                 :          0 :     CSubNet subnet;
     651 [ #  # ][ #  # ]:          0 :     assert(!subnet.IsValid());
     652         [ #  # ]:          0 :     if (!ContainsNoNUL(subnet_str)) {
     653                 :          0 :         return subnet;
     654                 :            :     }
     655                 :            : 
     656                 :          0 :     const size_t slash_pos{subnet_str.find_last_of('/')};
     657         [ #  # ]:          0 :     const std::string str_addr{subnet_str.substr(0, slash_pos)};
     658 [ #  # ][ #  # ]:          0 :     std::optional<CNetAddr> addr{LookupHost(str_addr, /*fAllowLookup=*/false)};
     659                 :            : 
     660         [ #  # ]:          0 :     if (addr.has_value()) {
     661 [ #  # ][ #  # ]:          0 :         addr = static_cast<CNetAddr>(MaybeFlipIPv6toCJDNS(CService{addr.value(), /*port=*/0}));
                 [ #  # ]
     662         [ #  # ]:          0 :         if (slash_pos != subnet_str.npos) {
     663         [ #  # ]:          0 :             const std::string netmask_str{subnet_str.substr(slash_pos + 1)};
     664                 :            :             uint8_t netmask;
     665 [ #  # ][ #  # ]:          0 :             if (ParseUInt8(netmask_str, &netmask)) {
     666                 :            :                 // Valid number; assume CIDR variable-length subnet masking.
     667 [ #  # ][ #  # ]:          0 :                 subnet = CSubNet{addr.value(), netmask};
     668                 :          0 :             } else {
     669                 :            :                 // Invalid number; try full netmask syntax. Never allow lookup for netmask.
     670 [ #  # ][ #  # ]:          0 :                 const std::optional<CNetAddr> full_netmask{LookupHost(netmask_str, /*fAllowLookup=*/false)};
     671         [ #  # ]:          0 :                 if (full_netmask.has_value()) {
     672 [ #  # ][ #  # ]:          0 :                     subnet = CSubNet{addr.value(), full_netmask.value()};
                 [ #  # ]
     673                 :          0 :                 }
     674                 :          0 :             }
     675                 :          0 :         } else {
     676                 :            :             // Single IP subnet (<ipv4>/32 or <ipv6>/128).
     677 [ #  # ][ #  # ]:          0 :             subnet = CSubNet{addr.value()};
     678                 :            :         }
     679                 :          0 :     }
     680                 :            : 
     681                 :          0 :     return subnet;
     682         [ #  # ]:          0 : }
     683                 :            : 
     684                 :          1 : void InterruptSocks5(bool interrupt)
     685                 :            : {
     686                 :          1 :     interruptSocks5Recv = interrupt;
     687                 :          1 : }
     688                 :            : 
     689                 :          0 : bool IsBadPort(uint16_t port)
     690                 :            : {
     691                 :            :     /* Don't forget to update doc/p2p-bad-ports.md if you change this list. */
     692                 :            : 
     693         [ #  # ]:          0 :     switch (port) {
     694                 :            :     case 1:     // tcpmux
     695                 :            :     case 7:     // echo
     696                 :            :     case 9:     // discard
     697                 :            :     case 11:    // systat
     698                 :            :     case 13:    // daytime
     699                 :            :     case 15:    // netstat
     700                 :            :     case 17:    // qotd
     701                 :            :     case 19:    // chargen
     702                 :            :     case 20:    // ftp data
     703                 :            :     case 21:    // ftp access
     704                 :            :     case 22:    // ssh
     705                 :            :     case 23:    // telnet
     706                 :            :     case 25:    // smtp
     707                 :            :     case 37:    // time
     708                 :            :     case 42:    // name
     709                 :            :     case 43:    // nicname
     710                 :            :     case 53:    // domain
     711                 :            :     case 69:    // tftp
     712                 :            :     case 77:    // priv-rjs
     713                 :            :     case 79:    // finger
     714                 :            :     case 87:    // ttylink
     715                 :            :     case 95:    // supdup
     716                 :            :     case 101:   // hostname
     717                 :            :     case 102:   // iso-tsap
     718                 :            :     case 103:   // gppitnp
     719                 :            :     case 104:   // acr-nema
     720                 :            :     case 109:   // pop2
     721                 :            :     case 110:   // pop3
     722                 :            :     case 111:   // sunrpc
     723                 :            :     case 113:   // auth
     724                 :            :     case 115:   // sftp
     725                 :            :     case 117:   // uucp-path
     726                 :            :     case 119:   // nntp
     727                 :            :     case 123:   // NTP
     728                 :            :     case 135:   // loc-srv /epmap
     729                 :            :     case 137:   // netbios
     730                 :            :     case 139:   // netbios
     731                 :            :     case 143:   // imap2
     732                 :            :     case 161:   // snmp
     733                 :            :     case 179:   // BGP
     734                 :            :     case 389:   // ldap
     735                 :            :     case 427:   // SLP (Also used by Apple Filing Protocol)
     736                 :            :     case 465:   // smtp+ssl
     737                 :            :     case 512:   // print / exec
     738                 :            :     case 513:   // login
     739                 :            :     case 514:   // shell
     740                 :            :     case 515:   // printer
     741                 :            :     case 526:   // tempo
     742                 :            :     case 530:   // courier
     743                 :            :     case 531:   // chat
     744                 :            :     case 532:   // netnews
     745                 :            :     case 540:   // uucp
     746                 :            :     case 548:   // AFP (Apple Filing Protocol)
     747                 :            :     case 554:   // rtsp
     748                 :            :     case 556:   // remotefs
     749                 :            :     case 563:   // nntp+ssl
     750                 :            :     case 587:   // smtp (rfc6409)
     751                 :            :     case 601:   // syslog-conn (rfc3195)
     752                 :            :     case 636:   // ldap+ssl
     753                 :            :     case 989:   // ftps-data
     754                 :            :     case 990:   // ftps
     755                 :            :     case 993:   // ldap+ssl
     756                 :            :     case 995:   // pop3+ssl
     757                 :            :     case 1719:  // h323gatestat
     758                 :            :     case 1720:  // h323hostcall
     759                 :            :     case 1723:  // pptp
     760                 :            :     case 2049:  // nfs
     761                 :            :     case 3659:  // apple-sasl / PasswordServer
     762                 :            :     case 4045:  // lockd
     763                 :            :     case 5060:  // sip
     764                 :            :     case 5061:  // sips
     765                 :            :     case 6000:  // X11
     766                 :            :     case 6566:  // sane-port
     767                 :            :     case 6665:  // Alternate IRC
     768                 :            :     case 6666:  // Alternate IRC
     769                 :            :     case 6667:  // Standard IRC
     770                 :            :     case 6668:  // Alternate IRC
     771                 :            :     case 6669:  // Alternate IRC
     772                 :            :     case 6697:  // IRC + TLS
     773                 :            :     case 10080: // Amanda
     774                 :          0 :         return true;
     775                 :            :     }
     776                 :          0 :     return false;
     777                 :          0 : }
     778                 :            : 
     779                 :          0 : CService MaybeFlipIPv6toCJDNS(const CService& service)
     780                 :            : {
     781                 :          0 :     CService ret{service};
     782 [ #  # ][ #  # ]:          0 :     if (ret.IsIPv6() && ret.HasCJDNSPrefix() && g_reachable_nets.Contains(NET_CJDNS)) {
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     783                 :          0 :         ret.m_net = NET_CJDNS;
     784                 :          0 :     }
     785                 :          0 :     return ret;
     786         [ #  # ]:          0 : }

Generated by: LCOV version 1.14