Bitcoin Core  26.1.0
P2P Digital Currency
netaddress.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_NETADDRESS_H
6 #define BITCOIN_NETADDRESS_H
7 
8 #if defined(HAVE_CONFIG_H)
10 #endif
11 
12 #include <compat/compat.h>
13 #include <crypto/siphash.h>
14 #include <prevector.h>
15 #include <random.h>
16 #include <serialize.h>
17 #include <tinyformat.h>
18 #include <util/strencodings.h>
19 #include <util/string.h>
20 
21 #include <array>
22 #include <cstdint>
23 #include <ios>
24 #include <string>
25 #include <vector>
26 
36 enum Network {
39 
42 
45 
48 
51 
54 
58 
61 };
62 
65 static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
66  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF};
67 
72 static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
73  0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43};
74 
80 static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
81  0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 // 0xFD + sha256("bitcoin")[0:5].
82 };
83 
86 static constexpr uint8_t CJDNS_PREFIX{0xFC};
87 
89 static constexpr size_t ADDR_IPV4_SIZE = 4;
90 
92 static constexpr size_t ADDR_IPV6_SIZE = 16;
93 
96 static constexpr size_t ADDR_TORV3_SIZE = 32;
97 
99 static constexpr size_t ADDR_I2P_SIZE = 32;
100 
102 static constexpr size_t ADDR_CJDNS_SIZE = 16;
103 
105 static constexpr size_t ADDR_INTERNAL_SIZE = 10;
106 
108 static constexpr uint16_t I2P_SAM31_PORT{0};
109 
110 std::string OnionToString(Span<const uint8_t> addr);
111 
115 class CNetAddr
116 {
117 protected:
123 
128 
133  uint32_t m_scope_id{0};
134 
135 public:
136  CNetAddr();
137  explicit CNetAddr(const struct in_addr& ipv4Addr);
138  void SetIP(const CNetAddr& ip);
139 
147 
148  bool SetInternal(const std::string& name);
149 
158  bool SetSpecial(const std::string& addr);
159 
160  bool IsBindAny() const; // INADDR_ANY equivalent
161  [[nodiscard]] bool IsIPv4() const { return m_net == NET_IPV4; } // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
162  [[nodiscard]] bool IsIPv6() const { return m_net == NET_IPV6; } // IPv6 address (not mapped IPv4, not Tor)
163  bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
164  bool IsRFC2544() const; // IPv4 inter-network communications (198.18.0.0/15)
165  bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10)
166  bool IsRFC5737() const; // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24)
167  bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32)
168  bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16)
169  bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16)
170  bool IsRFC4193() const; // IPv6 unique local (FC00::/7)
171  bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32)
172  bool IsRFC4843() const; // IPv6 ORCHID (deprecated) (2001:10::/28)
173  bool IsRFC7343() const; // IPv6 ORCHIDv2 (2001:20::/28)
174  bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
175  bool IsRFC6052() const; // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
176  bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in RFC2765)
177  bool IsHeNet() const; // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
178  [[nodiscard]] bool IsTor() const { return m_net == NET_ONION; }
179  [[nodiscard]] bool IsI2P() const { return m_net == NET_I2P; }
180  [[nodiscard]] bool IsCJDNS() const { return m_net == NET_CJDNS; }
181  [[nodiscard]] bool HasCJDNSPrefix() const { return m_addr[0] == CJDNS_PREFIX; }
182  bool IsLocal() const;
183  bool IsRoutable() const;
184  bool IsInternal() const;
185  bool IsValid() const;
186 
192  [[nodiscard]] bool IsPrivacyNet() const { return IsTor() || IsI2P(); }
193 
197  bool IsAddrV1Compatible() const;
198 
199  enum Network GetNetwork() const;
200  std::string ToStringAddr() const;
201  bool GetInAddr(struct in_addr* pipv4Addr) const;
202  Network GetNetClass() const;
203 
205  uint32_t GetLinkedIPv4() const;
207  bool HasLinkedIPv4() const;
208 
209  std::vector<unsigned char> GetAddrBytes() const;
210  int GetReachabilityFrom(const CNetAddr& paddrPartner) const;
211 
212  explicit CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
213  bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
214 
215  friend bool operator==(const CNetAddr& a, const CNetAddr& b);
216  friend bool operator!=(const CNetAddr& a, const CNetAddr& b) { return !(a == b); }
217  friend bool operator<(const CNetAddr& a, const CNetAddr& b);
218 
222  bool IsRelayable() const
223  {
224  return IsIPv4() || IsIPv6() || IsTor() || IsI2P() || IsCJDNS();
225  }
226 
227  enum class Encoding {
228  V1,
229  V2,
230  };
231  struct SerParams {
232  const Encoding enc;
234  };
235  static constexpr SerParams V1{Encoding::V1};
236  static constexpr SerParams V2{Encoding::V2};
237 
241  template <typename Stream>
242  void Serialize(Stream& s) const
243  {
244  if (s.GetParams().enc == Encoding::V2) {
246  } else {
248  }
249  }
250 
254  template <typename Stream>
255  void Unserialize(Stream& s)
256  {
257  if (s.GetParams().enc == Encoding::V2) {
259  } else {
261  }
262  }
263 
264  friend class CSubNet;
265 
266 private:
274  bool SetTor(const std::string& addr);
275 
283  bool SetI2P(const std::string& addr);
284 
288  enum BIP155Network : uint8_t {
289  IPV4 = 1,
290  IPV6 = 2,
291  TORV2 = 3,
292  TORV3 = 4,
293  I2P = 5,
294  CJDNS = 6,
295  };
296 
300  static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
301 
307  static constexpr size_t MAX_ADDRV2_SIZE = 512;
308 
315 
323  bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size);
324 
328  void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const
329  {
330  size_t prefix_size;
331 
332  switch (m_net) {
333  case NET_IPV6:
334  assert(m_addr.size() == sizeof(arr));
335  memcpy(arr, m_addr.data(), m_addr.size());
336  return;
337  case NET_IPV4:
338  prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
339  assert(prefix_size + m_addr.size() == sizeof(arr));
340  memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
341  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
342  return;
343  case NET_INTERNAL:
344  prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
345  assert(prefix_size + m_addr.size() == sizeof(arr));
346  memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
347  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
348  return;
349  case NET_ONION:
350  case NET_I2P:
351  case NET_CJDNS:
352  break;
353  case NET_UNROUTABLE:
354  case NET_MAX:
355  assert(false);
356  } // no default case, so the compiler can warn about missing cases
357 
358  // Serialize ONION, I2P and CJDNS as all-zeros.
359  memset(arr, 0x0, V1_SERIALIZATION_SIZE);
360  }
361 
365  template <typename Stream>
366  void SerializeV1Stream(Stream& s) const
367  {
368  uint8_t serialized[V1_SERIALIZATION_SIZE];
369 
370  SerializeV1Array(serialized);
371 
372  s << serialized;
373  }
374 
378  template <typename Stream>
379  void SerializeV2Stream(Stream& s) const
380  {
381  if (IsInternal()) {
382  // Serialize NET_INTERNAL as embedded in IPv6. We need to
383  // serialize such addresses from addrman.
384  s << static_cast<uint8_t>(BIP155Network::IPV6);
387  return;
388  }
389 
390  s << static_cast<uint8_t>(GetBIP155Network());
391  s << m_addr;
392  }
393 
404  {
405  // Use SetLegacyIPv6() so that m_net is set correctly. For example
406  // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
407  SetLegacyIPv6(arr);
408  }
409 
413  template <typename Stream>
414  void UnserializeV1Stream(Stream& s)
415  {
416  uint8_t serialized[V1_SERIALIZATION_SIZE];
417 
418  s >> serialized;
419 
420  UnserializeV1Array(serialized);
421  }
422 
426  template <typename Stream>
427  void UnserializeV2Stream(Stream& s)
428  {
429  uint8_t bip155_net;
430  s >> bip155_net;
431 
432  size_t address_size;
433  s >> COMPACTSIZE(address_size);
434 
435  if (address_size > MAX_ADDRV2_SIZE) {
436  throw std::ios_base::failure(strprintf(
437  "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
438  }
439 
440  m_scope_id = 0;
441 
442  if (SetNetFromBIP155Network(bip155_net, address_size)) {
443  m_addr.resize(address_size);
444  s >> Span{m_addr};
445 
446  if (m_net != NET_IPV6) {
447  return;
448  }
449 
450  // Do some special checks on IPv6 addresses.
451 
452  // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
453  // gossiped but could be coming from addrman, when unserializing from
454  // disk.
457  memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
460  return;
461  }
462 
465  return;
466  }
467 
468  // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in V1
469  // encoding). Unserialize as !IsValid(), thus ignoring them.
470  } else {
471  // If we receive an unknown BIP155 network id (from the future?) then
472  // ignore the address - unserialize as !IsValid().
473  s.ignore(address_size);
474  }
475 
476  // Mimic a default-constructed CNetAddr object which is !IsValid() and thus
477  // will not be gossiped, but continue reading next addresses from the stream.
478  m_net = NET_IPV6;
480  }
481 };
482 
483 class CSubNet
484 {
485 protected:
489  uint8_t netmask[16];
491  bool valid;
492 
493 public:
497  CSubNet();
498 
506  CSubNet(const CNetAddr& addr, uint8_t mask);
507 
515  CSubNet(const CNetAddr& addr, const CNetAddr& mask);
516 
521  explicit CSubNet(const CNetAddr& addr);
522 
523  bool Match(const CNetAddr& addr) const;
524 
525  std::string ToString() const;
526  bool IsValid() const;
527 
528  friend bool operator==(const CSubNet& a, const CSubNet& b);
529  friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
530  friend bool operator<(const CSubNet& a, const CSubNet& b);
531 };
532 
534 class CService : public CNetAddr
535 {
536 protected:
537  uint16_t port; // host order
538 
539 public:
540  CService();
541  CService(const CNetAddr& ip, uint16_t port);
542  CService(const struct in_addr& ipv4Addr, uint16_t port);
543  explicit CService(const struct sockaddr_in& addr);
544  uint16_t GetPort() const;
545  bool GetSockAddr(struct sockaddr* paddr, socklen_t* addrlen) const;
546  bool SetSockAddr(const struct sockaddr* paddr);
547  friend bool operator==(const CService& a, const CService& b);
548  friend bool operator!=(const CService& a, const CService& b) { return !(a == b); }
549  friend bool operator<(const CService& a, const CService& b);
550  std::vector<unsigned char> GetKey() const;
551  std::string ToStringAddrPort() const;
552 
553  CService(const struct in6_addr& ipv6Addr, uint16_t port);
554  explicit CService(const struct sockaddr_in6& addr);
555 
557  {
558  READWRITE(AsBase<CNetAddr>(obj), Using<BigEndianFormatter<2>>(obj.port));
559  }
560 
561  friend class CServiceHash;
562  friend CService MaybeFlipIPv6toCJDNS(const CService& service);
563 };
564 
566 {
567 public:
569  : m_salt_k0{GetRand<uint64_t>()},
570  m_salt_k1{GetRand<uint64_t>()}
571  {
572  }
573 
574  CServiceHash(uint64_t salt_k0, uint64_t salt_k1) : m_salt_k0{salt_k0}, m_salt_k1{salt_k1} {}
575 
576  size_t operator()(const CService& a) const noexcept
577  {
578  CSipHasher hasher(m_salt_k0, m_salt_k1);
579  hasher.Write(a.m_net);
580  hasher.Write(a.port);
581  hasher.Write(a.m_addr);
582  return static_cast<size_t>(hasher.Finalize());
583  }
584 
585 private:
586  const uint64_t m_salt_k0;
587  const uint64_t m_salt_k1;
588 };
589 
590 #endif // BITCOIN_NETADDRESS_H
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:653
void resize(size_type new_size)
Definition: prevector.h:325
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:45
bool HasCJDNSPrefix() const
Definition: netaddress.h:181
void assign(size_type n, const T &val)
Definition: prevector.h:220
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:242
bool IsLocal() const
Definition: netaddress.cpp:399
bool IsRFC4380() const
Definition: netaddress.cpp:359
uint16_t GetPort() const
Definition: netaddress.cpp:821
assert(!tx.IsCoinBase())
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:57
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data It is treated as if this was the little-endian interpretation of ...
Definition: siphash.cpp:28
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:60
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:103
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:96
IPv4.
Definition: netaddress.h:41
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:307
bool IsIPv6() const
Definition: netaddress.h:162
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:122
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:255
#define COMPACTSIZE(obj)
Definition: serialize.h:523
bool SetTor(const std::string &addr)
Parse a Tor address and set this object to it.
Definition: netaddress.cpp:225
uint16_t port
Definition: netaddress.h:537
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:826
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:89
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:80
bool SetI2P(const std::string &addr)
Parse an I2P address and set this object to it.
Definition: netaddress.cpp:264
bool IsInternal() const
Definition: netaddress.cpp:473
CNetAddr network
Network (base) address.
Definition: netaddress.h:487
bool IsBindAny() const
Definition: netaddress.cpp:304
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:624
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:208
bool IsPrivacyNet() const
Whether this object is a privacy network.
Definition: netaddress.h:192
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:403
Network GetNetClass() const
Definition: netaddress.cpp:675
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:427
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 (or CJDNS) address.
Definition: netaddress.cpp:643
int GetReachabilityFrom(const CNetAddr &paddrPartner) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:714
enum Network GetNetwork() const
Definition: netaddress.cpp:497
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class...
Definition: serialize.h:519
I2P.
Definition: netaddress.h:50
std::string ToStringAddrPort() const
Definition: netaddress.cpp:889
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:414
bool IsRFC2544() const
Definition: netaddress.cpp:320
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:133
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can&#39;t reach it ourselves.
Definition: netaddress.h:222
value_type * data()
Definition: prevector.h:527
bool IsRFC4862() const
Definition: netaddress.cpp:364
std::string ToStringAddr() const
Definition: netaddress.cpp:581
bool IsValid() const
Definition: netaddress.cpp:425
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:102
bool IsCJDNS() const
Definition: netaddress.h:180
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:216
friend bool operator!=(const CSubNet &a, const CSubNet &b)
Definition: netaddress.h:529
bool IsIPv4() const
Definition: netaddress.h:161
bool IsRFC5737() const
Definition: netaddress.cpp:335
bool IsI2P() const
Definition: netaddress.h:179
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:92
friend CService MaybeFlipIPv6toCJDNS(const CService &service)
If an IPv6 address belongs to the address range used by the CJDNS network and the CJDNS network is re...
Definition: netbase.cpp:779
const uint64_t m_salt_k0
Definition: netaddress.h:586
static constexpr uint16_t I2P_SAM31_PORT
SAM 3.1 and earlier do not support specifying ports and force the port to 0.
Definition: netaddress.h:108
bool IsRFC6145() const
Definition: netaddress.cpp:375
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:328
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:99
bool IsRFC6052() const
Definition: netaddress.cpp:352
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
Definition: netaddress.cpp:848
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:548
const char * name
Definition: rest.cpp:45
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:23
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:288
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:534
std::string OnionToString(Span< const uint8_t > addr)
Definition: netaddress.cpp:570
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:121
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:366
static constexpr SerParams V1
Definition: netaddress.h:235
const Encoding enc
Definition: netaddress.h:232
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:831
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:881
#define SER_PARAMS_OPFUNC
Helper macro for SerParams structs.
Definition: serialize.h:1205
Network
A network type.
Definition: netaddress.h:36
static CService ip(uint32_t i)
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
Definition: siphash.cpp:77
friend bool operator==(const CSubNet &a, const CSubNet &b)
bool IsRFC3849() const
Definition: netaddress.cpp:342
bool IsRoutable() const
Definition: netaddress.cpp:463
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:491
static constexpr uint8_t CJDNS_PREFIX
All CJDNS addresses start with 0xFC.
Definition: netaddress.h:86
bool Match(const CNetAddr &addr) const
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:489
Network address.
Definition: netaddress.h:115
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:609
bool IsValid() const
bool IsRFC1918() const
Definition: netaddress.cpp:312
bool IsRFC6598() const
Definition: netaddress.cpp:330
const uint64_t m_salt_k1
Definition: netaddress.h:587
bool IsHeNet() const
Definition: netaddress.cpp:394
std::string ToString() const
bool IsRFC3927() const
Definition: netaddress.cpp:325
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:604
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:72
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:379
BIP155 encoding.
CSubNet()
Construct an invalid subnet (empty, Match() always returns false).
Definition: netaddress.cpp:900
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:551
IPv6.
Definition: netaddress.h:44
friend bool operator<(const CSubNet &a, const CSubNet &b)
TOR (v2 or v3)
Definition: netaddress.h:47
SipHash-2-4.
Definition: siphash.h:14
bool IsRFC7343() const
Definition: netaddress.cpp:388
size_type size() const
Definition: prevector.h:291
static constexpr SerParams V2
Definition: netaddress.h:236
bool IsRFC4843() const
Definition: netaddress.cpp:382
size_t operator()(const CService &a) const noexcept
Definition: netaddress.h:576
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:65
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:105
A Span is an object that can refer to a contiguous sequence of objects.
Definition: solver.h:20
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:658
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:807
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:169
Network m_net
Network to which this address belongs.
Definition: netaddress.h:127
#define READWRITE(...)
Definition: serialize.h:169
bool IsRFC4193() const
Definition: netaddress.cpp:370
CServiceHash(uint64_t salt_k0, uint64_t salt_k1)
Definition: netaddress.h:574
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:478
CJDNS.
Definition: netaddress.h:53
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:556
bool IsTor() const
Definition: netaddress.h:178
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:300
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:134
std::vector< unsigned char > GetAddrBytes() const
Definition: netaddress.cpp:693
bool IsRFC3964() const
Definition: netaddress.cpp:347
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:38