Bitcoin Core  0.20.99
P2P Digital Currency
netaddress.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 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 <netaddress.h>
7 
8 #include <crypto/common.h>
9 #include <crypto/sha3.h>
10 #include <hash.h>
11 #include <prevector.h>
12 #include <tinyformat.h>
13 #include <util/asmap.h>
14 #include <util/strencodings.h>
15 #include <util/string.h>
16 
17 #include <algorithm>
18 #include <array>
19 #include <cstdint>
20 #include <ios>
21 #include <iterator>
22 #include <tuple>
23 
24 constexpr size_t CNetAddr::V1_SERIALIZATION_SIZE;
25 constexpr size_t CNetAddr::MAX_ADDRV2_SIZE;
26 
28 {
29  switch (m_net) {
30  case NET_IPV4:
31  return BIP155Network::IPV4;
32  case NET_IPV6:
33  return BIP155Network::IPV6;
34  case NET_ONION:
35  switch (m_addr.size()) {
36  case ADDR_TORV2_SIZE:
37  return BIP155Network::TORV2;
38  case ADDR_TORV3_SIZE:
39  return BIP155Network::TORV3;
40  default:
41  assert(false);
42  }
43  case NET_I2P:
44  return BIP155Network::I2P;
45  case NET_CJDNS:
46  return BIP155Network::CJDNS;
47  case NET_INTERNAL: // should have been handled before calling this function
48  case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE
49  case NET_MAX: // m_net is never and should not be set to NET_MAX
50  assert(false);
51  } // no default case, so the compiler can warn about missing cases
52 
53  assert(false);
54 }
55 
56 bool CNetAddr::SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size)
57 {
58  switch (possible_bip155_net) {
60  if (address_size == ADDR_IPV4_SIZE) {
61  m_net = NET_IPV4;
62  return true;
63  }
64  throw std::ios_base::failure(
65  strprintf("BIP155 IPv4 address with length %u (should be %u)", address_size,
68  if (address_size == ADDR_IPV6_SIZE) {
69  m_net = NET_IPV6;
70  return true;
71  }
72  throw std::ios_base::failure(
73  strprintf("BIP155 IPv6 address with length %u (should be %u)", address_size,
75  case BIP155Network::TORV2:
76  if (address_size == ADDR_TORV2_SIZE) {
77  m_net = NET_ONION;
78  return true;
79  }
80  throw std::ios_base::failure(
81  strprintf("BIP155 TORv2 address with length %u (should be %u)", address_size,
83  case BIP155Network::TORV3:
84  if (address_size == ADDR_TORV3_SIZE) {
85  m_net = NET_ONION;
86  return true;
87  }
88  throw std::ios_base::failure(
89  strprintf("BIP155 TORv3 address with length %u (should be %u)", address_size,
91  case BIP155Network::I2P:
92  if (address_size == ADDR_I2P_SIZE) {
93  m_net = NET_I2P;
94  return true;
95  }
96  throw std::ios_base::failure(
97  strprintf("BIP155 I2P address with length %u (should be %u)", address_size,
98  ADDR_I2P_SIZE));
99  case BIP155Network::CJDNS:
100  if (address_size == ADDR_CJDNS_SIZE) {
101  m_net = NET_CJDNS;
102  return true;
103  }
104  throw std::ios_base::failure(
105  strprintf("BIP155 CJDNS address with length %u (should be %u)", address_size,
106  ADDR_CJDNS_SIZE));
107  }
108 
109  // Don't throw on addresses with unknown network ids (maybe from the future).
110  // Instead silently drop them and have the unserialization code consume
111  // subsequent ones which may be known to us.
112  return false;
113 }
114 
121 
122 void CNetAddr::SetIP(const CNetAddr& ipIn)
123 {
124  // Size check.
125  switch (ipIn.m_net) {
126  case NET_IPV4:
127  assert(ipIn.m_addr.size() == ADDR_IPV4_SIZE);
128  break;
129  case NET_IPV6:
130  assert(ipIn.m_addr.size() == ADDR_IPV6_SIZE);
131  break;
132  case NET_ONION:
133  assert(ipIn.m_addr.size() == ADDR_TORV2_SIZE || ipIn.m_addr.size() == ADDR_TORV3_SIZE);
134  break;
135  case NET_I2P:
136  assert(ipIn.m_addr.size() == ADDR_I2P_SIZE);
137  break;
138  case NET_CJDNS:
139  assert(ipIn.m_addr.size() == ADDR_CJDNS_SIZE);
140  break;
141  case NET_INTERNAL:
142  assert(ipIn.m_addr.size() == ADDR_INTERNAL_SIZE);
143  break;
144  case NET_UNROUTABLE:
145  case NET_MAX:
146  assert(false);
147  } // no default case, so the compiler can warn about missing cases
148 
149  m_net = ipIn.m_net;
150  m_addr = ipIn.m_addr;
151 }
152 
154 {
155  assert(ipv6.size() == ADDR_IPV6_SIZE);
156 
157  size_t skip{0};
158 
159  if (HasPrefix(ipv6, IPV4_IN_IPV6_PREFIX)) {
160  // IPv4-in-IPv6
161  m_net = NET_IPV4;
162  skip = sizeof(IPV4_IN_IPV6_PREFIX);
163  } else if (HasPrefix(ipv6, TORV2_IN_IPV6_PREFIX)) {
164  // TORv2-in-IPv6
165  m_net = NET_ONION;
166  skip = sizeof(TORV2_IN_IPV6_PREFIX);
167  } else if (HasPrefix(ipv6, INTERNAL_IN_IPV6_PREFIX)) {
168  // Internal-in-IPv6
170  skip = sizeof(INTERNAL_IN_IPV6_PREFIX);
171  } else {
172  // IPv6
173  m_net = NET_IPV6;
174  }
175 
176  m_addr.assign(ipv6.begin() + skip, ipv6.end());
177 }
178 
185 bool CNetAddr::SetInternal(const std::string &name)
186 {
187  if (name.empty()) {
188  return false;
189  }
191  unsigned char hash[32] = {};
192  CSHA256().Write((const unsigned char*)name.data(), name.size()).Finalize(hash);
193  m_addr.assign(hash, hash + ADDR_INTERNAL_SIZE);
194  return true;
195 }
196 
197 namespace torv3 {
198 // https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt#n2135
199 static constexpr size_t CHECKSUM_LEN = 2;
200 static const unsigned char VERSION[] = {3};
201 static constexpr size_t TOTAL_LEN = ADDR_TORV3_SIZE + CHECKSUM_LEN + sizeof(VERSION);
202 
203 static void Checksum(Span<const uint8_t> addr_pubkey, uint8_t (&checksum)[CHECKSUM_LEN])
204 {
205  // TORv3 CHECKSUM = H(".onion checksum" | PUBKEY | VERSION)[:2]
206  static const unsigned char prefix[] = ".onion checksum";
207  static constexpr size_t prefix_len = 15;
208 
209  SHA3_256 hasher;
210 
211  hasher.Write(MakeSpan(prefix).first(prefix_len));
212  hasher.Write(addr_pubkey);
213  hasher.Write(VERSION);
214 
215  uint8_t checksum_full[SHA3_256::OUTPUT_SIZE];
216 
217  hasher.Finalize(checksum_full);
218 
219  memcpy(checksum, checksum_full, sizeof(checksum));
220 }
221 
222 }; // namespace torv3
223 
231 bool CNetAddr::SetSpecial(const std::string& str)
232 {
233  static const char* suffix{".onion"};
234  static constexpr size_t suffix_len{6};
235 
236  if (!ValidAsCString(str) || str.size() <= suffix_len ||
237  str.substr(str.size() - suffix_len) != suffix) {
238  return false;
239  }
240 
241  bool invalid;
242  const auto& input = DecodeBase32(str.substr(0, str.size() - suffix_len).c_str(), &invalid);
243 
244  if (invalid) {
245  return false;
246  }
247 
248  switch (input.size()) {
249  case ADDR_TORV2_SIZE:
250  m_net = NET_ONION;
251  m_addr.assign(input.begin(), input.end());
252  return true;
253  case torv3::TOTAL_LEN: {
254  Span<const uint8_t> input_pubkey{input.data(), ADDR_TORV3_SIZE};
255  Span<const uint8_t> input_checksum{input.data() + ADDR_TORV3_SIZE, torv3::CHECKSUM_LEN};
256  Span<const uint8_t> input_version{input.data() + ADDR_TORV3_SIZE + torv3::CHECKSUM_LEN, sizeof(torv3::VERSION)};
257 
258  uint8_t calculated_checksum[torv3::CHECKSUM_LEN];
259  torv3::Checksum(input_pubkey, calculated_checksum);
260 
261  if (input_checksum != calculated_checksum || input_version != torv3::VERSION) {
262  return false;
263  }
264 
265  m_net = NET_ONION;
266  m_addr.assign(input_pubkey.begin(), input_pubkey.end());
267  return true;
268  }
269  }
270 
271  return false;
272 }
273 
274 CNetAddr::CNetAddr(const struct in_addr& ipv4Addr)
275 {
276  m_net = NET_IPV4;
277  const uint8_t* ptr = reinterpret_cast<const uint8_t*>(&ipv4Addr);
278  m_addr.assign(ptr, ptr + ADDR_IPV4_SIZE);
279 }
280 
281 CNetAddr::CNetAddr(const struct in6_addr& ipv6Addr, const uint32_t scope)
282 {
283  SetLegacyIPv6(Span<const uint8_t>(reinterpret_cast<const uint8_t*>(&ipv6Addr), sizeof(ipv6Addr)));
284  m_scope_id = scope;
285 }
286 
288 {
289  if (!IsIPv4() && !IsIPv6()) {
290  return false;
291  }
292  return std::all_of(m_addr.begin(), m_addr.end(), [](uint8_t b) { return b == 0; });
293 }
294 
295 bool CNetAddr::IsIPv4() const { return m_net == NET_IPV4; }
296 
297 bool CNetAddr::IsIPv6() const { return m_net == NET_IPV6; }
298 
300 {
301  return IsIPv4() && (
302  m_addr[0] == 10 ||
303  (m_addr[0] == 192 && m_addr[1] == 168) ||
304  (m_addr[0] == 172 && m_addr[1] >= 16 && m_addr[1] <= 31));
305 }
306 
308 {
309  return IsIPv4() && m_addr[0] == 198 && (m_addr[1] == 18 || m_addr[1] == 19);
310 }
311 
313 {
314  return IsIPv4() && HasPrefix(m_addr, std::array<uint8_t, 2>{169, 254});
315 }
316 
318 {
319  return IsIPv4() && m_addr[0] == 100 && m_addr[1] >= 64 && m_addr[1] <= 127;
320 }
321 
323 {
324  return IsIPv4() && (HasPrefix(m_addr, std::array<uint8_t, 3>{192, 0, 2}) ||
325  HasPrefix(m_addr, std::array<uint8_t, 3>{198, 51, 100}) ||
326  HasPrefix(m_addr, std::array<uint8_t, 3>{203, 0, 113}));
327 }
328 
330 {
331  return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 4>{0x20, 0x01, 0x0D, 0xB8});
332 }
333 
335 {
336  return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 2>{0x20, 0x02});
337 }
338 
340 {
341  return IsIPv6() &&
342  HasPrefix(m_addr, std::array<uint8_t, 12>{0x00, 0x64, 0xFF, 0x9B, 0x00, 0x00,
343  0x00, 0x00, 0x00, 0x00, 0x00, 0x00});
344 }
345 
347 {
348  return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 4>{0x20, 0x01, 0x00, 0x00});
349 }
350 
352 {
353  return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 8>{0xFE, 0x80, 0x00, 0x00,
354  0x00, 0x00, 0x00, 0x00});
355 }
356 
358 {
359  return IsIPv6() && (m_addr[0] & 0xFE) == 0xFC;
360 }
361 
363 {
364  return IsIPv6() &&
365  HasPrefix(m_addr, std::array<uint8_t, 12>{0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
366  0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00});
367 }
368 
370 {
371  return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 3>{0x20, 0x01, 0x00}) &&
372  (m_addr[3] & 0xF0) == 0x10;
373 }
374 
376 {
377  return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 3>{0x20, 0x01, 0x00}) &&
378  (m_addr[3] & 0xF0) == 0x20;
379 }
380 
381 bool CNetAddr::IsHeNet() const
382 {
383  return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 4>{0x20, 0x01, 0x04, 0x70});
384 }
385 
390 bool CNetAddr::IsTor() const { return m_net == NET_ONION; }
391 
395 bool CNetAddr::IsI2P() const { return m_net == NET_I2P; }
396 
400 bool CNetAddr::IsCJDNS() const { return m_net == NET_CJDNS; }
401 
402 bool CNetAddr::IsLocal() const
403 {
404  // IPv4 loopback (127.0.0.0/8 or 0.0.0.0/8)
405  if (IsIPv4() && (m_addr[0] == 127 || m_addr[0] == 0)) {
406  return true;
407  }
408 
409  // IPv6 loopback (::1/128)
410  static const unsigned char pchLocal[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
411  if (IsIPv6() && memcmp(m_addr.data(), pchLocal, sizeof(pchLocal)) == 0) {
412  return true;
413  }
414 
415  return false;
416 }
417 
428 bool CNetAddr::IsValid() const
429 {
430  // unspecified IPv6 address (::/128)
431  unsigned char ipNone6[16] = {};
432  if (IsIPv6() && memcmp(m_addr.data(), ipNone6, sizeof(ipNone6)) == 0) {
433  return false;
434  }
435 
436  // documentation IPv6 address
437  if (IsRFC3849())
438  return false;
439 
440  if (IsInternal())
441  return false;
442 
443  if (IsIPv4()) {
444  const uint32_t addr = ReadBE32(m_addr.data());
445  if (addr == INADDR_ANY || addr == INADDR_NONE) {
446  return false;
447  }
448  }
449 
450  return true;
451 }
452 
463 {
464  return IsValid() && !(IsRFC1918() || IsRFC2544() || IsRFC3927() || IsRFC4862() || IsRFC6598() || IsRFC5737() || (IsRFC4193() && !IsTor()) || IsRFC4843() || IsRFC7343() || IsLocal() || IsInternal());
465 }
466 
473 {
474  return m_net == NET_INTERNAL;
475 }
476 
478 {
479  switch (m_net) {
480  case NET_IPV4:
481  case NET_IPV6:
482  case NET_INTERNAL:
483  return true;
484  case NET_ONION:
485  return m_addr.size() == ADDR_TORV2_SIZE;
486  case NET_I2P:
487  case NET_CJDNS:
488  return false;
489  case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE
490  case NET_MAX: // m_net is never and should not be set to NET_MAX
491  assert(false);
492  } // no default case, so the compiler can warn about missing cases
493 
494  assert(false);
495 }
496 
498 {
499  if (IsInternal())
500  return NET_INTERNAL;
501 
502  if (!IsRoutable())
503  return NET_UNROUTABLE;
504 
505  return m_net;
506 }
507 
508 static std::string IPv6ToString(Span<const uint8_t> a)
509 {
510  assert(a.size() == ADDR_IPV6_SIZE);
511  // clang-format off
512  return strprintf("%x:%x:%x:%x:%x:%x:%x:%x",
513  ReadBE16(&a[0]),
514  ReadBE16(&a[2]),
515  ReadBE16(&a[4]),
516  ReadBE16(&a[6]),
517  ReadBE16(&a[8]),
518  ReadBE16(&a[10]),
519  ReadBE16(&a[12]),
520  ReadBE16(&a[14]));
521  // clang-format on
522 }
523 
524 std::string CNetAddr::ToStringIP() const
525 {
526  switch (m_net) {
527  case NET_IPV4:
528  case NET_IPV6: {
529  CService serv(*this, 0);
530  struct sockaddr_storage sockaddr;
531  socklen_t socklen = sizeof(sockaddr);
532  if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) {
533  char name[1025] = "";
534  if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name,
535  sizeof(name), nullptr, 0, NI_NUMERICHOST))
536  return std::string(name);
537  }
538  if (m_net == NET_IPV4) {
539  return strprintf("%u.%u.%u.%u", m_addr[0], m_addr[1], m_addr[2], m_addr[3]);
540  }
541  return IPv6ToString(m_addr);
542  }
543  case NET_ONION:
544  switch (m_addr.size()) {
545  case ADDR_TORV2_SIZE:
546  return EncodeBase32(m_addr) + ".onion";
547  case ADDR_TORV3_SIZE: {
548 
549  uint8_t checksum[torv3::CHECKSUM_LEN];
550  torv3::Checksum(m_addr, checksum);
551 
552  // TORv3 onion_address = base32(PUBKEY | CHECKSUM | VERSION) + ".onion"
554  address.insert(address.end(), checksum, checksum + torv3::CHECKSUM_LEN);
555  address.insert(address.end(), torv3::VERSION, torv3::VERSION + sizeof(torv3::VERSION));
556 
557  return EncodeBase32(address) + ".onion";
558  }
559  default:
560  assert(false);
561  }
562  case NET_I2P:
563  return EncodeBase32(m_addr, false /* don't pad with = */) + ".b32.i2p";
564  case NET_CJDNS:
565  return IPv6ToString(m_addr);
566  case NET_INTERNAL:
567  return EncodeBase32(m_addr) + ".internal";
568  case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE
569  case NET_MAX: // m_net is never and should not be set to NET_MAX
570  assert(false);
571  } // no default case, so the compiler can warn about missing cases
572 
573  assert(false);
574 }
575 
576 std::string CNetAddr::ToString() const
577 {
578  return ToStringIP();
579 }
580 
581 bool operator==(const CNetAddr& a, const CNetAddr& b)
582 {
583  return a.m_net == b.m_net && a.m_addr == b.m_addr;
584 }
585 
586 bool operator<(const CNetAddr& a, const CNetAddr& b)
587 {
588  return std::tie(a.m_net, a.m_addr) < std::tie(b.m_net, b.m_addr);
589 }
590 
601 bool CNetAddr::GetInAddr(struct in_addr* pipv4Addr) const
602 {
603  if (!IsIPv4())
604  return false;
605  assert(sizeof(*pipv4Addr) == m_addr.size());
606  memcpy(pipv4Addr, m_addr.data(), m_addr.size());
607  return true;
608 }
609 
620 bool CNetAddr::GetIn6Addr(struct in6_addr* pipv6Addr) const
621 {
622  if (!IsIPv6()) {
623  return false;
624  }
625  assert(sizeof(*pipv6Addr) == m_addr.size());
626  memcpy(pipv6Addr, m_addr.data(), m_addr.size());
627  return true;
628 }
629 
631 {
632  return IsRoutable() && (IsIPv4() || IsRFC6145() || IsRFC6052() || IsRFC3964() || IsRFC4380());
633 }
634 
635 uint32_t CNetAddr::GetLinkedIPv4() const
636 {
637  if (IsIPv4()) {
638  return ReadBE32(m_addr.data());
639  } else if (IsRFC6052() || IsRFC6145()) {
640  // mapped IPv4, SIIT translated IPv4: the IPv4 address is the last 4 bytes of the address
641  return ReadBE32(MakeSpan(m_addr).last(ADDR_IPV4_SIZE).data());
642  } else if (IsRFC3964()) {
643  // 6to4 tunneled IPv4: the IPv4 address is in bytes 2-6
644  return ReadBE32(MakeSpan(m_addr).subspan(2, ADDR_IPV4_SIZE).data());
645  } else if (IsRFC4380()) {
646  // Teredo tunneled IPv4: the IPv4 address is in the last 4 bytes of the address, but bitflipped
647  return ~ReadBE32(MakeSpan(m_addr).last(ADDR_IPV4_SIZE).data());
648  }
649  assert(false);
650 }
651 
653 {
654  // Make sure that if we return NET_IPV6, then IsIPv6() is true. The callers expect that.
655 
656  // Check for "internal" first because such addresses are also !IsRoutable()
657  // and we don't want to return NET_UNROUTABLE in that case.
658  if (IsInternal()) {
659  return NET_INTERNAL;
660  }
661  if (!IsRoutable()) {
662  return NET_UNROUTABLE;
663  }
664  if (HasLinkedIPv4()) {
665  return NET_IPV4;
666  }
667  return m_net;
668 }
669 
670 uint32_t CNetAddr::GetMappedAS(const std::vector<bool> &asmap) const {
671  uint32_t net_class = GetNetClass();
672  if (asmap.size() == 0 || (net_class != NET_IPV4 && net_class != NET_IPV6)) {
673  return 0; // Indicates not found, safe because AS0 is reserved per RFC7607.
674  }
675  std::vector<bool> ip_bits(128);
676  if (HasLinkedIPv4()) {
677  // For lookup, treat as if it was just an IPv4 address (IPV4_IN_IPV6_PREFIX + IPv4 bits)
678  for (int8_t byte_i = 0; byte_i < 12; ++byte_i) {
679  for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) {
680  ip_bits[byte_i * 8 + bit_i] = (IPV4_IN_IPV6_PREFIX[byte_i] >> (7 - bit_i)) & 1;
681  }
682  }
683  uint32_t ipv4 = GetLinkedIPv4();
684  for (int i = 0; i < 32; ++i) {
685  ip_bits[96 + i] = (ipv4 >> (31 - i)) & 1;
686  }
687  } else {
688  // Use all 128 bits of the IPv6 address otherwise
689  assert(IsIPv6());
690  for (int8_t byte_i = 0; byte_i < 16; ++byte_i) {
691  uint8_t cur_byte = m_addr[byte_i];
692  for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) {
693  ip_bits[byte_i * 8 + bit_i] = (cur_byte >> (7 - bit_i)) & 1;
694  }
695  }
696  }
697  uint32_t mapped_as = Interpret(asmap, ip_bits);
698  return mapped_as;
699 }
700 
711 std::vector<unsigned char> CNetAddr::GetGroup(const std::vector<bool> &asmap) const
712 {
713  std::vector<unsigned char> vchRet;
714  uint32_t net_class = GetNetClass();
715  // If non-empty asmap is supplied and the address is IPv4/IPv6,
716  // return ASN to be used for bucketing.
717  uint32_t asn = GetMappedAS(asmap);
718  if (asn != 0) { // Either asmap was empty, or address has non-asmappable net class (e.g. TOR).
719  vchRet.push_back(NET_IPV6); // IPv4 and IPv6 with same ASN should be in the same bucket
720  for (int i = 0; i < 4; i++) {
721  vchRet.push_back((asn >> (8 * i)) & 0xFF);
722  }
723  return vchRet;
724  }
725 
726  vchRet.push_back(net_class);
727  int nBits{0};
728 
729  if (IsLocal()) {
730  // all local addresses belong to the same group
731  } else if (IsInternal()) {
732  // all internal-usage addresses get their own group
733  nBits = ADDR_INTERNAL_SIZE * 8;
734  } else if (!IsRoutable()) {
735  // all other unroutable addresses belong to the same group
736  } else if (HasLinkedIPv4()) {
737  // IPv4 addresses (and mapped IPv4 addresses) use /16 groups
738  uint32_t ipv4 = GetLinkedIPv4();
739  vchRet.push_back((ipv4 >> 24) & 0xFF);
740  vchRet.push_back((ipv4 >> 16) & 0xFF);
741  return vchRet;
742  } else if (IsTor() || IsI2P() || IsCJDNS()) {
743  nBits = 4;
744  } else if (IsHeNet()) {
745  // for he.net, use /36 groups
746  nBits = 36;
747  } else {
748  // for the rest of the IPv6 network, use /32 groups
749  nBits = 32;
750  }
751 
752  // Push our address onto vchRet.
753  const size_t num_bytes = nBits / 8;
754  vchRet.insert(vchRet.end(), m_addr.begin(), m_addr.begin() + num_bytes);
755  nBits %= 8;
756  // ...for the last byte, push nBits and for the rest of the byte push 1's
757  if (nBits > 0) {
758  assert(num_bytes < m_addr.size());
759  vchRet.push_back(m_addr[num_bytes] | ((1 << (8 - nBits)) - 1));
760  }
761 
762  return vchRet;
763 }
764 
765 std::vector<unsigned char> CNetAddr::GetAddrBytes() const
766 {
767  if (IsAddrV1Compatible()) {
768  uint8_t serialized[V1_SERIALIZATION_SIZE];
769  SerializeV1Array(serialized);
770  return {std::begin(serialized), std::end(serialized)};
771  }
772  return std::vector<unsigned char>(m_addr.begin(), m_addr.end());
773 }
774 
775 uint64_t CNetAddr::GetHash() const
776 {
777  uint256 hash = Hash(m_addr);
778  uint64_t nRet;
779  memcpy(&nRet, &hash, sizeof(nRet));
780  return nRet;
781 }
782 
783 // private extensions to enum Network, only returned by GetExtNetwork,
784 // and only used in GetReachabilityFrom
785 static const int NET_UNKNOWN = NET_MAX + 0;
786 static const int NET_TEREDO = NET_MAX + 1;
787 int static GetExtNetwork(const CNetAddr *addr)
788 {
789  if (addr == nullptr)
790  return NET_UNKNOWN;
791  if (addr->IsRFC4380())
792  return NET_TEREDO;
793  return addr->GetNetwork();
794 }
795 
797 int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
798 {
799  enum Reachability {
800  REACH_UNREACHABLE,
801  REACH_DEFAULT,
802  REACH_TEREDO,
803  REACH_IPV6_WEAK,
804  REACH_IPV4,
805  REACH_IPV6_STRONG,
806  REACH_PRIVATE
807  };
808 
809  if (!IsRoutable() || IsInternal())
810  return REACH_UNREACHABLE;
811 
812  int ourNet = GetExtNetwork(this);
813  int theirNet = GetExtNetwork(paddrPartner);
814  bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145();
815 
816  switch(theirNet) {
817  case NET_IPV4:
818  switch(ourNet) {
819  default: return REACH_DEFAULT;
820  case NET_IPV4: return REACH_IPV4;
821  }
822  case NET_IPV6:
823  switch(ourNet) {
824  default: return REACH_DEFAULT;
825  case NET_TEREDO: return REACH_TEREDO;
826  case NET_IPV4: return REACH_IPV4;
827  case NET_IPV6: return fTunnel ? REACH_IPV6_WEAK : REACH_IPV6_STRONG; // only prefer giving our IPv6 address if it's not tunnelled
828  }
829  case NET_ONION:
830  switch(ourNet) {
831  default: return REACH_DEFAULT;
832  case NET_IPV4: return REACH_IPV4; // Tor users can connect to IPv4 as well
833  case NET_ONION: return REACH_PRIVATE;
834  }
835  case NET_TEREDO:
836  switch(ourNet) {
837  default: return REACH_DEFAULT;
838  case NET_TEREDO: return REACH_TEREDO;
839  case NET_IPV6: return REACH_IPV6_WEAK;
840  case NET_IPV4: return REACH_IPV4;
841  }
842  case NET_UNKNOWN:
843  case NET_UNROUTABLE:
844  default:
845  switch(ourNet) {
846  default: return REACH_DEFAULT;
847  case NET_TEREDO: return REACH_TEREDO;
848  case NET_IPV6: return REACH_IPV6_WEAK;
849  case NET_IPV4: return REACH_IPV4;
850  case NET_ONION: return REACH_PRIVATE; // either from Tor, or don't care about our address
851  }
852  }
853 }
854 
856 {
857 }
858 
859 CService::CService(const CNetAddr& cip, uint16_t portIn) : CNetAddr(cip), port(portIn)
860 {
861 }
862 
863 CService::CService(const struct in_addr& ipv4Addr, uint16_t portIn) : CNetAddr(ipv4Addr), port(portIn)
864 {
865 }
866 
867 CService::CService(const struct in6_addr& ipv6Addr, uint16_t portIn) : CNetAddr(ipv6Addr), port(portIn)
868 {
869 }
870 
871 CService::CService(const struct sockaddr_in& addr) : CNetAddr(addr.sin_addr), port(ntohs(addr.sin_port))
872 {
873  assert(addr.sin_family == AF_INET);
874 }
875 
876 CService::CService(const struct sockaddr_in6 &addr) : CNetAddr(addr.sin6_addr, addr.sin6_scope_id), port(ntohs(addr.sin6_port))
877 {
878  assert(addr.sin6_family == AF_INET6);
879 }
880 
881 bool CService::SetSockAddr(const struct sockaddr *paddr)
882 {
883  switch (paddr->sa_family) {
884  case AF_INET:
885  *this = CService(*(const struct sockaddr_in*)paddr);
886  return true;
887  case AF_INET6:
888  *this = CService(*(const struct sockaddr_in6*)paddr);
889  return true;
890  default:
891  return false;
892  }
893 }
894 
895 uint16_t CService::GetPort() const
896 {
897  return port;
898 }
899 
900 bool operator==(const CService& a, const CService& b)
901 {
902  return static_cast<CNetAddr>(a) == static_cast<CNetAddr>(b) && a.port == b.port;
903 }
904 
905 bool operator<(const CService& a, const CService& b)
906 {
907  return static_cast<CNetAddr>(a) < static_cast<CNetAddr>(b) || (static_cast<CNetAddr>(a) == static_cast<CNetAddr>(b) && a.port < b.port);
908 }
909 
922 bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
923 {
924  if (IsIPv4()) {
925  if (*addrlen < (socklen_t)sizeof(struct sockaddr_in))
926  return false;
927  *addrlen = sizeof(struct sockaddr_in);
928  struct sockaddr_in *paddrin = (struct sockaddr_in*)paddr;
929  memset(paddrin, 0, *addrlen);
930  if (!GetInAddr(&paddrin->sin_addr))
931  return false;
932  paddrin->sin_family = AF_INET;
933  paddrin->sin_port = htons(port);
934  return true;
935  }
936  if (IsIPv6()) {
937  if (*addrlen < (socklen_t)sizeof(struct sockaddr_in6))
938  return false;
939  *addrlen = sizeof(struct sockaddr_in6);
940  struct sockaddr_in6 *paddrin6 = (struct sockaddr_in6*)paddr;
941  memset(paddrin6, 0, *addrlen);
942  if (!GetIn6Addr(&paddrin6->sin6_addr))
943  return false;
944  paddrin6->sin6_scope_id = m_scope_id;
945  paddrin6->sin6_family = AF_INET6;
946  paddrin6->sin6_port = htons(port);
947  return true;
948  }
949  return false;
950 }
951 
955 std::vector<unsigned char> CService::GetKey() const
956 {
957  auto key = GetAddrBytes();
958  key.push_back(port / 0x100); // most significant byte of our port
959  key.push_back(port & 0x0FF); // least significant byte of our port
960  return key;
961 }
962 
963 std::string CService::ToStringPort() const
964 {
965  return strprintf("%u", port);
966 }
967 
968 std::string CService::ToStringIPPort() const
969 {
970  if (IsIPv4() || IsTor() || IsI2P() || IsInternal()) {
971  return ToStringIP() + ":" + ToStringPort();
972  } else {
973  return "[" + ToStringIP() + "]:" + ToStringPort();
974  }
975 }
976 
977 std::string CService::ToString() const
978 {
979  return ToStringIPPort();
980 }
981 
983  valid(false)
984 {
985  memset(netmask, 0, sizeof(netmask));
986 }
987 
988 CSubNet::CSubNet(const CNetAddr& addr, uint8_t mask) : CSubNet()
989 {
990  valid = (addr.IsIPv4() && mask <= ADDR_IPV4_SIZE * 8) ||
991  (addr.IsIPv6() && mask <= ADDR_IPV6_SIZE * 8);
992  if (!valid) {
993  return;
994  }
995 
996  assert(mask <= sizeof(netmask) * 8);
997 
998  network = addr;
999 
1000  uint8_t n = mask;
1001  for (size_t i = 0; i < network.m_addr.size(); ++i) {
1002  const uint8_t bits = n < 8 ? n : 8;
1003  netmask[i] = (uint8_t)((uint8_t)0xFF << (8 - bits)); // Set first bits.
1004  network.m_addr[i] &= netmask[i]; // Normalize network according to netmask.
1005  n -= bits;
1006  }
1007 }
1008 
1013 static inline int NetmaskBits(uint8_t x)
1014 {
1015  switch(x) {
1016  case 0x00: return 0;
1017  case 0x80: return 1;
1018  case 0xc0: return 2;
1019  case 0xe0: return 3;
1020  case 0xf0: return 4;
1021  case 0xf8: return 5;
1022  case 0xfc: return 6;
1023  case 0xfe: return 7;
1024  case 0xff: return 8;
1025  default: return -1;
1026  }
1027 }
1028 
1029 CSubNet::CSubNet(const CNetAddr& addr, const CNetAddr& mask) : CSubNet()
1030 {
1031  valid = (addr.IsIPv4() || addr.IsIPv6()) && addr.m_net == mask.m_net;
1032  if (!valid) {
1033  return;
1034  }
1035  // Check if `mask` contains 1-bits after 0-bits (which is an invalid netmask).
1036  bool zeros_found = false;
1037  for (auto b : mask.m_addr) {
1038  const int num_bits = NetmaskBits(b);
1039  if (num_bits == -1 || (zeros_found && num_bits != 0)) {
1040  valid = false;
1041  return;
1042  }
1043  if (num_bits < 8) {
1044  zeros_found = true;
1045  }
1046  }
1047 
1048  assert(mask.m_addr.size() <= sizeof(netmask));
1049 
1050  memcpy(netmask, mask.m_addr.data(), mask.m_addr.size());
1051 
1052  network = addr;
1053 
1054  // Normalize network according to netmask
1055  for (size_t x = 0; x < network.m_addr.size(); ++x) {
1056  network.m_addr[x] &= netmask[x];
1057  }
1058 }
1059 
1061 {
1062  valid = addr.IsIPv4() || addr.IsIPv6();
1063  if (!valid) {
1064  return;
1065  }
1066 
1067  assert(addr.m_addr.size() <= sizeof(netmask));
1068 
1069  memset(netmask, 0xFF, addr.m_addr.size());
1070 
1071  network = addr;
1072 }
1073 
1078 bool CSubNet::Match(const CNetAddr &addr) const
1079 {
1080  if (!valid || !addr.IsValid() || network.m_net != addr.m_net)
1081  return false;
1082  assert(network.m_addr.size() == addr.m_addr.size());
1083  for (size_t x = 0; x < addr.m_addr.size(); ++x) {
1084  if ((addr.m_addr[x] & netmask[x]) != network.m_addr[x]) {
1085  return false;
1086  }
1087  }
1088  return true;
1089 }
1090 
1091 std::string CSubNet::ToString() const
1092 {
1093  assert(network.m_addr.size() <= sizeof(netmask));
1094 
1095  uint8_t cidr = 0;
1096 
1097  for (size_t i = 0; i < network.m_addr.size(); ++i) {
1098  if (netmask[i] == 0x00) {
1099  break;
1100  }
1101  cidr += NetmaskBits(netmask[i]);
1102  }
1103 
1104  return network.ToString() + strprintf("/%u", cidr);
1105 }
1106 
1107 bool CSubNet::IsValid() const
1108 {
1109  return valid;
1110 }
1111 
1113 {
1114  if (!(network.IsIPv4() || network.IsIPv6())) return false;
1115 
1116  for (size_t x = 0; x < network.m_addr.size(); ++x) {
1117  if (network.m_addr[x] & ~netmask[x]) return false;
1118  }
1119 
1120  return true;
1121 }
1122 
1123 bool operator==(const CSubNet& a, const CSubNet& b)
1124 {
1125  return a.valid == b.valid && a.network == b.network && !memcmp(a.netmask, b.netmask, 16);
1126 }
1127 
1128 bool operator<(const CSubNet& a, const CSubNet& b)
1129 {
1130  return (a.network < b.network || (a.network == b.network && memcmp(a.netmask, b.netmask, 16) < 0));
1131 }
1132 
1133 bool SanityCheckASMap(const std::vector<bool>& asmap)
1134 {
1135  return SanityCheckASMap(asmap, 128); // For IP address lookups, the input is 128 bits
1136 }
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:797
std::vector< unsigned char > GetGroup(const std::vector< bool > &asmap) const
Get the canonical identifier of our network group.
Definition: netaddress.cpp:711
CSHA256 & Write(const unsigned char *data, size_t len)
Definition: sha256.cpp:637
std::string ToStringPort() const
Definition: netaddress.cpp:963
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:630
bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size)
Set m_net from the provided BIP155 network id and size after validation.
Definition: netaddress.cpp:56
SHA3_256 & Write(Span< const unsigned char > data)
Definition: sha3.cpp:111
void assign(size_type n, const T &val)
Definition: prevector.h:218
bool IsLocal() const
Definition: netaddress.cpp:402
bool IsRFC4380() const
Definition: netaddress.cpp:346
uint16_t GetPort() const
Definition: netaddress.cpp:895
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:65
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:68
constexpr C * end() const noexcept
Definition: span.h:142
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:122
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
NODISCARD bool ValidAsCString(const std::string &str) noexcept
Check if a string does not contain any embedded NUL (\0) characters.
Definition: string.h:62
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:105
IPv4.
Definition: netaddress.h:49
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:273
static std::string IPv6ToString(Span< const uint8_t > a)
Definition: netaddress.cpp:508
bool IsIPv6() const
Definition: netaddress.cpp:297
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:126
static const int NET_UNKNOWN
Definition: netaddress.cpp:785
const char * prefix
Definition: rest.cpp:670
Definition: sha3.h:16
uint16_t port
Definition: netaddress.h:504
constexpr std::size_t size() const noexcept
Definition: span.h:153
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:900
static constexpr size_t OUTPUT_SIZE
Definition: sha3.h:33
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:95
std::vector< unsigned char > DecodeBase32(const char *p, bool *pf_invalid)
static const std::array< uint8_t, 6 > INTERNAL_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded "internal" address.
Definition: netaddress.h:90
static const unsigned char VERSION[]
Definition: netaddress.cpp:200
SHA3_256 & Finalize(Span< unsigned char > output)
Definition: sha3.cpp:141
bool IsInternal() const
Definition: netaddress.cpp:472
CNetAddr network
Network (base) address.
Definition: netaddress.h:456
bool IsBindAny() const
Definition: netaddress.cpp:287
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:601
std::string ToString() const
Definition: netaddress.cpp:576
Network GetNetClass() const
Definition: netaddress.cpp:652
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 address.
Definition: netaddress.cpp:620
enum Network GetNetwork() const
Definition: netaddress.cpp:497
I2P.
Definition: netaddress.h:58
bool SanityCheck() const
bool IsRFC2544() const
Definition: netaddress.cpp:307
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:137
value_type * data()
Definition: prevector.h:528
bool IsRFC4862() const
Definition: netaddress.cpp:351
uint32_t GetMappedAS(const std::vector< bool > &asmap) const
Definition: netaddress.cpp:670
bool IsValid() const
Definition: netaddress.cpp:428
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:111
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
Definition: netaddress.cpp:400
bool IsIPv4() const
Definition: netaddress.cpp:295
iterator end()
Definition: prevector.h:292
bool IsRFC5737() const
Definition: netaddress.cpp:322
bool IsI2P() const
Check whether this object represents an I2P address.
Definition: netaddress.cpp:395
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:98
static int GetExtNetwork(const CNetAddr *addr)
Definition: netaddress.cpp:787
bool IsRFC6145() const
Definition: netaddress.cpp:362
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:294
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:108
bool IsRFC6052() const
Definition: netaddress.cpp:339
static constexpr size_t ADDR_TORV2_SIZE
Size of TORv2 address (in bytes).
Definition: netaddress.h:101
static constexpr size_t CHECKSUM_LEN
Definition: netaddress.cpp:199
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
Definition: netaddress.cpp:922
std::string ToStringIP() const
Definition: netaddress.cpp:524
const char * name
Definition: rest.cpp:41
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:27
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:254
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:501
static uint16_t ReadBE16(const unsigned char *ptr)
Definition: common.h:56
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:905
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:955
static uint32_t ReadBE32(const unsigned char *ptr)
Definition: common.h:63
Network
A network type.
Definition: netaddress.h:43
uint32_t Interpret(const std::vector< bool > &asmap, const std::vector< bool > &ip)
Definition: asmap.cpp:78
static void Checksum(Span< const uint8_t > addr_pubkey, uint8_t(&checksum)[CHECKSUM_LEN])
Definition: netaddress.cpp:203
friend bool operator==(const CSubNet &a, const CSubNet &b)
bool IsRFC3849() const
Definition: netaddress.cpp:329
bool IsRoutable() const
Definition: netaddress.cpp:462
uint64_t GetHash() const
Definition: netaddress.cpp:775
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:37
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:460
std::string EncodeBase32(Span< const unsigned char > input, bool pad)
Base32 encode.
bool Match(const CNetAddr &addr) const
static constexpr size_t TOTAL_LEN
Definition: netaddress.cpp:201
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:458
static int NetmaskBits(uint8_t x)
constexpr C * begin() const noexcept
Definition: span.h:141
Network address.
Definition: netaddress.h:119
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:586
bool IsValid() const
bool IsRFC1918() const
Definition: netaddress.cpp:299
256-bit opaque blob.
Definition: uint256.h:124
bool IsRFC6598() const
Definition: netaddress.cpp:317
bool IsHeNet() const
Definition: netaddress.cpp:381
std::string ToString() const
bool IsRFC3927() const
Definition: netaddress.cpp:312
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:581
static const std::array< uint8_t, 6 > TORV2_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded TORv2 address.
Definition: netaddress.h:81
constexpr C * data() const noexcept
Definition: span.h:140
void * memcpy(void *a, const void *b, size_t c)
std::string ToStringIPPort() const
Definition: netaddress.cpp:968
static const int NET_TEREDO
Definition: netaddress.cpp:786
IPv6.
Definition: netaddress.h:52
friend bool operator<(const CSubNet &a, const CSubNet &b)
TOR (v2 or v3)
Definition: netaddress.h:55
NODISCARD bool HasPrefix(const T1 &obj, const std::array< uint8_t, PREFIX_LEN > &prefix)
Check whether a container begins with the given prefix.
Definition: string.h:83
bool SetSpecial(const std::string &strName)
Parse a TOR address and set this object to it.
Definition: netaddress.cpp:231
iterator begin()
Definition: prevector.h:290
bool IsRFC7343() const
Definition: netaddress.cpp:375
size_type size() const
Definition: prevector.h:282
std::string ToString() const
Definition: netaddress.cpp:977
bool IsRFC4843() const
Definition: netaddress.cpp:369
static const std::array< uint8_t, 12 > IPV4_IN_IPV6_PREFIX
Prefix of an IPv6 address when it contains an embedded IPv4 address.
Definition: netaddress.h:73
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:114
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:82
bool SanityCheckASMap(const std::vector< bool > &asmap)
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
Definition: hash.h:75
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:635
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:881
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:185
Network m_net
Network to which this address belongs.
Definition: netaddress.h:131
if(it !=peer.m_getdata_requests.end() &&!pfrom.fPauseSend)
A hasher class for SHA-256.
Definition: sha256.h:13
bool IsRFC4193() const
Definition: netaddress.cpp:357
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:477
CJDNS.
Definition: netaddress.h:61
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:390
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:266
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:153
std::vector< unsigned char > GetAddrBytes() const
Definition: netaddress.cpp:765
bool IsRFC3964() const
Definition: netaddress.cpp:334
Span< A > constexpr MakeSpan(A(&a)[N])
MakeSpan for arrays:
Definition: span.h:193
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
Definition: netaddress.cpp:120
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:46