Bitcoin Core  22.0.0
P2P Digital Currency
netaddress.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2020 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 <attributes.h>
13 #include <compat.h>
14 #include <crypto/siphash.h>
15 #include <prevector.h>
16 #include <random.h>
17 #include <serialize.h>
18 #include <tinyformat.h>
19 #include <util/strencodings.h>
20 #include <util/string.h>
21 
22 #include <array>
23 #include <cstdint>
24 #include <ios>
25 #include <string>
26 #include <vector>
27 
34 static constexpr int ADDRV2_FORMAT = 0x20000000;
35 
45 enum Network
46 {
49 
52 
55 
58 
61 
64 
68 
71 };
72 
75 static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
76  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF
77 };
78 
83 static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
84  0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43
85 };
86 
92 static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
93  0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 // 0xFD + sha256("bitcoin")[0:5].
94 };
95 
97 static constexpr size_t ADDR_IPV4_SIZE = 4;
98 
100 static constexpr size_t ADDR_IPV6_SIZE = 16;
101 
104 static constexpr size_t ADDR_TORV3_SIZE = 32;
105 
107 static constexpr size_t ADDR_I2P_SIZE = 32;
108 
110 static constexpr size_t ADDR_CJDNS_SIZE = 16;
111 
113 static constexpr size_t ADDR_INTERNAL_SIZE = 10;
114 
116 static constexpr uint16_t I2P_SAM31_PORT{0};
117 
121 class CNetAddr
122 {
123  protected:
129 
134 
139  uint32_t m_scope_id{0};
140 
141  public:
142  CNetAddr();
143  explicit CNetAddr(const struct in_addr& ipv4Addr);
144  void SetIP(const CNetAddr& ip);
145 
153 
154  bool SetInternal(const std::string& name);
155 
164  bool SetSpecial(const std::string& addr);
165 
166  bool IsBindAny() const; // INADDR_ANY equivalent
167  bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
168  bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor)
169  bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
170  bool IsRFC2544() const; // IPv4 inter-network communications (198.18.0.0/15)
171  bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10)
172  bool IsRFC5737() const; // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24)
173  bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32)
174  bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16)
175  bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16)
176  bool IsRFC4193() const; // IPv6 unique local (FC00::/7)
177  bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32)
178  bool IsRFC4843() const; // IPv6 ORCHID (deprecated) (2001:10::/28)
179  bool IsRFC7343() const; // IPv6 ORCHIDv2 (2001:20::/28)
180  bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
181  bool IsRFC6052() const; // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
182  bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in RFC2765)
183  bool IsHeNet() const; // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
184  bool IsTor() const;
185  bool IsI2P() const;
186  bool IsCJDNS() const;
187  bool IsLocal() const;
188  bool IsRoutable() const;
189  bool IsInternal() const;
190  bool IsValid() const;
191 
195  bool IsAddrV1Compatible() const;
196 
197  enum Network GetNetwork() const;
198  std::string ToString() const;
199  std::string ToStringIP() const;
200  uint64_t GetHash() 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  // The AS on the BGP path to the node we use to diversify
210  // peers in AddrMan bucketing based on the AS infrastructure.
211  // The ip->AS mapping depends on how asmap is constructed.
212  uint32_t GetMappedAS(const std::vector<bool> &asmap) const;
213 
214  std::vector<unsigned char> GetGroup(const std::vector<bool> &asmap) const;
215  std::vector<unsigned char> GetAddrBytes() const;
216  int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const;
217 
218  explicit CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
219  bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
220 
221  friend bool operator==(const CNetAddr& a, const CNetAddr& b);
222  friend bool operator!=(const CNetAddr& a, const CNetAddr& b) { return !(a == b); }
223  friend bool operator<(const CNetAddr& a, const CNetAddr& b);
224 
228  bool IsRelayable() const
229  {
230  return IsIPv4() || IsIPv6() || IsTor() || IsI2P();
231  }
232 
236  template <typename Stream>
237  void Serialize(Stream& s) const
238  {
239  if (s.GetVersion() & ADDRV2_FORMAT) {
241  } else {
243  }
244  }
245 
249  template <typename Stream>
250  void Unserialize(Stream& s)
251  {
252  if (s.GetVersion() & ADDRV2_FORMAT) {
254  } else {
256  }
257  }
258 
259  friend class CNetAddrHash;
260  friend class CSubNet;
261 
262  private:
270  bool SetTor(const std::string& addr);
271 
279  bool SetI2P(const std::string& addr);
280 
284  enum BIP155Network : uint8_t {
285  IPV4 = 1,
286  IPV6 = 2,
287  TORV2 = 3,
288  TORV3 = 4,
289  I2P = 5,
290  CJDNS = 6,
291  };
292 
296  static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
297 
303  static constexpr size_t MAX_ADDRV2_SIZE = 512;
304 
311 
319  bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size);
320 
324  void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const
325  {
326  size_t prefix_size;
327 
328  switch (m_net) {
329  case NET_IPV6:
330  assert(m_addr.size() == sizeof(arr));
331  memcpy(arr, m_addr.data(), m_addr.size());
332  return;
333  case NET_IPV4:
334  prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
335  assert(prefix_size + m_addr.size() == sizeof(arr));
336  memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
337  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
338  return;
339  case NET_INTERNAL:
340  prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
341  assert(prefix_size + m_addr.size() == sizeof(arr));
342  memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
343  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
344  return;
345  case NET_ONION:
346  case NET_I2P:
347  case NET_CJDNS:
348  break;
349  case NET_UNROUTABLE:
350  case NET_MAX:
351  assert(false);
352  } // no default case, so the compiler can warn about missing cases
353 
354  // Serialize ONION, I2P and CJDNS as all-zeros.
355  memset(arr, 0x0, V1_SERIALIZATION_SIZE);
356  }
357 
361  template <typename Stream>
362  void SerializeV1Stream(Stream& s) const
363  {
364  uint8_t serialized[V1_SERIALIZATION_SIZE];
365 
366  SerializeV1Array(serialized);
367 
368  s << serialized;
369  }
370 
374  template <typename Stream>
375  void SerializeV2Stream(Stream& s) const
376  {
377  if (IsInternal()) {
378  // Serialize NET_INTERNAL as embedded in IPv6. We need to
379  // serialize such addresses from addrman.
380  s << static_cast<uint8_t>(BIP155Network::IPV6);
383  return;
384  }
385 
386  s << static_cast<uint8_t>(GetBIP155Network());
387  s << m_addr;
388  }
389 
394  {
395  // Use SetLegacyIPv6() so that m_net is set correctly. For example
396  // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
397  SetLegacyIPv6(arr);
398  }
399 
403  template <typename Stream>
404  void UnserializeV1Stream(Stream& s)
405  {
406  uint8_t serialized[V1_SERIALIZATION_SIZE];
407 
408  s >> serialized;
409 
410  UnserializeV1Array(serialized);
411  }
412 
416  template <typename Stream>
417  void UnserializeV2Stream(Stream& s)
418  {
419  uint8_t bip155_net;
420  s >> bip155_net;
421 
422  size_t address_size;
423  s >> COMPACTSIZE(address_size);
424 
425  if (address_size > MAX_ADDRV2_SIZE) {
426  throw std::ios_base::failure(strprintf(
427  "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
428  }
429 
430  m_scope_id = 0;
431 
432  if (SetNetFromBIP155Network(bip155_net, address_size)) {
433  m_addr.resize(address_size);
434  s >> MakeSpan(m_addr);
435 
436  if (m_net != NET_IPV6) {
437  return;
438  }
439 
440  // Do some special checks on IPv6 addresses.
441 
442  // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
443  // gossiped but could be coming from addrman, when unserializing from
444  // disk.
447  memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
450  return;
451  }
452 
455  return;
456  }
457 
458  // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in V1
459  // encoding). Unserialize as !IsValid(), thus ignoring them.
460  } else {
461  // If we receive an unknown BIP155 network id (from the future?) then
462  // ignore the address - unserialize as !IsValid().
463  s.ignore(address_size);
464  }
465 
466  // Mimic a default-constructed CNetAddr object which is !IsValid() and thus
467  // will not be gossiped, but continue reading next addresses from the stream.
468  m_net = NET_IPV6;
470  }
471 };
472 
474 {
475 public:
476  size_t operator()(const CNetAddr& a) const noexcept
477  {
478  CSipHasher hasher(m_salt_k0, m_salt_k1);
479  hasher.Write(a.m_net);
480  hasher.Write(a.m_addr.data(), a.m_addr.size());
481  return static_cast<size_t>(hasher.Finalize());
482  }
483 
484 private:
485  const uint64_t m_salt_k0 = GetRand(std::numeric_limits<uint64_t>::max());
486  const uint64_t m_salt_k1 = GetRand(std::numeric_limits<uint64_t>::max());
487 };
488 
489 class CSubNet
490 {
491  protected:
495  uint8_t netmask[16];
497  bool valid;
498 
499  bool SanityCheck() const;
500 
501  public:
505  CSubNet();
506 
514  CSubNet(const CNetAddr& addr, uint8_t mask);
515 
523  CSubNet(const CNetAddr& addr, const CNetAddr& mask);
524 
529  explicit CSubNet(const CNetAddr& addr);
530 
531  bool Match(const CNetAddr &addr) const;
532 
533  std::string ToString() const;
534  bool IsValid() const;
535 
536  friend bool operator==(const CSubNet& a, const CSubNet& b);
537  friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
538  friend bool operator<(const CSubNet& a, const CSubNet& b);
539 
541  {
542  READWRITE(obj.network);
543  if (obj.network.IsIPv4()) {
544  // Before commit 102867c587f5f7954232fb8ed8e85cda78bb4d32, CSubNet used the last 4 bytes of netmask
545  // to store the relevant bytes for an IPv4 mask. For compatibility reasons, keep doing so in
546  // serialized form.
547  unsigned char dummy[12] = {0};
548  READWRITE(dummy);
549  READWRITE(MakeSpan(obj.netmask).first(4));
550  } else {
551  READWRITE(obj.netmask);
552  }
553  READWRITE(obj.valid);
554  // Mark invalid if the result doesn't pass sanity checking.
555  SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck());
556  }
557 };
558 
560 class CService : public CNetAddr
561 {
562  protected:
563  uint16_t port; // host order
564 
565  public:
566  CService();
567  CService(const CNetAddr& ip, uint16_t port);
568  CService(const struct in_addr& ipv4Addr, uint16_t port);
569  explicit CService(const struct sockaddr_in& addr);
570  uint16_t GetPort() const;
571  bool GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const;
572  bool SetSockAddr(const struct sockaddr* paddr);
573  friend bool operator==(const CService& a, const CService& b);
574  friend bool operator!=(const CService& a, const CService& b) { return !(a == b); }
575  friend bool operator<(const CService& a, const CService& b);
576  std::vector<unsigned char> GetKey() const;
577  std::string ToString() const;
578  std::string ToStringPort() const;
579  std::string ToStringIPPort() const;
580 
581  CService(const struct in6_addr& ipv6Addr, uint16_t port);
582  explicit CService(const struct sockaddr_in6& addr);
583 
585  {
586  READWRITEAS(CNetAddr, obj);
588  }
589 };
590 
591 bool SanityCheckASMap(const std::vector<bool>& asmap);
592 
593 #endif // BITCOIN_NETADDRESS_H
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:852
std::vector< unsigned char > GetGroup(const std::vector< bool > &asmap) const
Get the canonical identifier of our network group.
Definition: netaddress.cpp:766
std::string ToStringPort() const
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:685
void resize(size_type new_size)
Definition: prevector.h:316
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:49
uint64_t GetRand(uint64_t nMax) noexcept
Generate a uniform random integer in the range [0..range).
Definition: random.cpp:591
void assign(size_type n, const T &val)
Definition: prevector.h:218
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:237
bool IsLocal() const
Definition: netaddress.cpp:425
bool IsRFC4380() const
Definition: netaddress.cpp:369
uint16_t GetPort() const
Definition: netaddress.cpp:955
assert(!tx.IsCoinBase())
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:67
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:70
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:107
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:104
IPv4.
Definition: netaddress.h:51
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:303
bool IsIPv6() const
Definition: netaddress.cpp:320
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:128
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:250
#define COMPACTSIZE(obj)
Definition: serialize.h:444
bool SetTor(const std::string &addr)
Parse a Tor address and set this object to it.
Definition: netaddress.cpp:229
uint16_t port
Definition: netaddress.h:563
const uint64_t m_salt_k1
Definition: netaddress.h:486
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:960
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:97
const uint64_t m_salt_k0
Definition: netaddress.h:485
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:92
bool SetI2P(const std::string &addr)
Parse an I2P address and set this object to it.
Definition: netaddress.cpp:269
bool IsInternal() const
Definition: netaddress.cpp:500
SERIALIZE_METHODS(CSubNet, obj)
Definition: netaddress.h:540
CNetAddr network
Network (base) address.
Definition: netaddress.h:493
bool IsBindAny() const
Definition: netaddress.cpp:310
size_t operator()(const CNetAddr &a) const noexcept
Definition: netaddress.h:476
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:656
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:212
std::string ToString() const
Definition: netaddress.cpp:631
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:393
Network GetNetClass() const
Definition: netaddress.cpp:707
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:417
#define READWRITEAS(type, obj)
Definition: serialize.h:148
bool SanityCheckASMap(const std::vector< bool > &asmap)
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 address.
Definition: netaddress.cpp:675
enum Network GetNetwork() const
Definition: netaddress.cpp:524
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class...
Definition: serialize.h:440
I2P.
Definition: netaddress.h:60
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:404
bool SanityCheck() const
bool IsRFC2544() const
Definition: netaddress.cpp:330
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:139
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can&#39;t reach it ourselves.
Definition: netaddress.h:228
value_type * data()
Definition: prevector.h:528
bool IsRFC4862() const
Definition: netaddress.cpp:374
uint32_t GetMappedAS(const std::vector< bool > &asmap) const
Definition: netaddress.cpp:725
bool IsValid() const
Definition: netaddress.cpp:451
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:110
static constexpr int ADDRV2_FORMAT
A flag that is ORed into the protocol version to designate that addresses should be serialized in (un...
Definition: netaddress.h:34
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
Definition: netaddress.cpp:423
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:222
friend bool operator!=(const CSubNet &a, const CSubNet &b)
Definition: netaddress.h:537
bool IsIPv4() const
Definition: netaddress.cpp:318
bool IsRFC5737() const
Definition: netaddress.cpp:345
bool IsI2P() const
Check whether this object represents an I2P address.
Definition: netaddress.cpp:418
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:100
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:116
bool IsRFC6145() const
Definition: netaddress.cpp:385
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:324
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:107
bool IsRFC6052() const
Definition: netaddress.cpp:362
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
Definition: netaddress.cpp:982
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:574
std::string ToStringIP() const
Definition: netaddress.cpp:608
const char * name
Definition: rest.cpp:43
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:284
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:560
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:91
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:362
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:965
std::vector< unsigned char > GetKey() const
Network
A network type.
Definition: netaddress.h:45
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
Definition: siphash.cpp:76
friend bool operator==(const CSubNet &a, const CSubNet &b)
bool IsRFC3849() const
Definition: netaddress.cpp:352
bool IsRoutable() const
Definition: netaddress.cpp:490
uint64_t GetHash() const
Definition: netaddress.cpp:830
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:497
bool Match(const CNetAddr &addr) const
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:495
Network address.
Definition: netaddress.h:121
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:641
bool IsValid() const
bool IsRFC1918() const
Definition: netaddress.cpp:322
bool IsRFC6598() const
Definition: netaddress.cpp:340
bool IsHeNet() const
Definition: netaddress.cpp:404
std::string ToString() const
bool IsRFC3927() const
Definition: netaddress.cpp:335
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:636
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:83
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:375
std::string ToStringIPPort() const
CSubNet()
Construct an invalid subnet (empty, Match() always returns false).
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:472
IPv6.
Definition: netaddress.h:54
friend bool operator<(const CSubNet &a, const CSubNet &b)
TOR (v2 or v3)
Definition: netaddress.h:57
SipHash-2-4.
Definition: siphash.h:13
bool IsRFC7343() const
Definition: netaddress.cpp:398
size_type size() const
Definition: prevector.h:282
std::string ToString() const
bool IsRFC4843() const
Definition: netaddress.cpp:392
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:75
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:113
#define SER_READ(obj, code)
Definition: serialize.h:149
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:92
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:690
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:941
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:173
Network m_net
Network to which this address belongs.
Definition: netaddress.h:133
#define READWRITE(...)
Definition: serialize.h:147
bool IsRFC4193() const
Definition: netaddress.cpp:380
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:505
CJDNS.
Definition: netaddress.h:63
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:584
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:413
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:296
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:138
std::vector< unsigned char > GetAddrBytes() const
Definition: netaddress.cpp:820
bool IsRFC3964() const
Definition: netaddress.cpp:357
Span< A > constexpr MakeSpan(A(&a)[N])
MakeSpan for arrays:
Definition: span.h:222
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
Definition: netaddress.cpp:105
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:48