Bitcoin Core  21.99.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 <prevector.h>
15 #include <serialize.h>
16 #include <tinyformat.h>
17 #include <util/strencodings.h>
18 #include <util/string.h>
19 
20 #include <array>
21 #include <cstdint>
22 #include <ios>
23 #include <string>
24 #include <vector>
25 
32 static constexpr int ADDRV2_FORMAT = 0x20000000;
33 
43 enum Network
44 {
47 
50 
53 
56 
59 
62 
66 
69 };
70 
73 static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{
74  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF
75 };
76 
81 static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
82  0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43
83 };
84 
90 static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
91  0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24 // 0xFD + sha256("bitcoin")[0:5].
92 };
93 
95 static constexpr size_t ADDR_IPV4_SIZE = 4;
96 
98 static constexpr size_t ADDR_IPV6_SIZE = 16;
99 
101 static constexpr size_t ADDR_TORV2_SIZE = 10;
102 
105 static constexpr size_t ADDR_TORV3_SIZE = 32;
106 
108 static constexpr size_t ADDR_I2P_SIZE = 32;
109 
111 static constexpr size_t ADDR_CJDNS_SIZE = 16;
112 
114 static constexpr size_t ADDR_INTERNAL_SIZE = 10;
115 
119 class CNetAddr
120 {
121  protected:
127 
132 
137  uint32_t m_scope_id{0};
138 
139  public:
140  CNetAddr();
141  explicit CNetAddr(const struct in_addr& ipv4Addr);
142  void SetIP(const CNetAddr& ip);
143 
151 
152  bool SetInternal(const std::string& name);
153 
162  bool SetSpecial(const std::string& addr);
163 
164  bool IsBindAny() const; // INADDR_ANY equivalent
165  bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
166  bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor)
167  bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
168  bool IsRFC2544() const; // IPv4 inter-network communications (198.18.0.0/15)
169  bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10)
170  bool IsRFC5737() const; // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24)
171  bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32)
172  bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16)
173  bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16)
174  bool IsRFC4193() const; // IPv6 unique local (FC00::/7)
175  bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32)
176  bool IsRFC4843() const; // IPv6 ORCHID (deprecated) (2001:10::/28)
177  bool IsRFC7343() const; // IPv6 ORCHIDv2 (2001:20::/28)
178  bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64)
179  bool IsRFC6052() const; // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
180  bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in RFC2765)
181  bool IsHeNet() const; // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
182  bool IsTor() const;
183  bool IsI2P() const;
184  bool IsCJDNS() const;
185  bool IsLocal() const;
186  bool IsRoutable() const;
187  bool IsInternal() const;
188  bool IsValid() const;
189 
193  bool IsAddrV1Compatible() const;
194 
195  enum Network GetNetwork() const;
196  std::string ToString() const;
197  std::string ToStringIP() const;
198  uint64_t GetHash() const;
199  bool GetInAddr(struct in_addr* pipv4Addr) const;
200  Network GetNetClass() const;
201 
203  uint32_t GetLinkedIPv4() const;
205  bool HasLinkedIPv4() const;
206 
207  // The AS on the BGP path to the node we use to diversify
208  // peers in AddrMan bucketing based on the AS infrastructure.
209  // The ip->AS mapping depends on how asmap is constructed.
210  uint32_t GetMappedAS(const std::vector<bool> &asmap) const;
211 
212  std::vector<unsigned char> GetGroup(const std::vector<bool> &asmap) const;
213  std::vector<unsigned char> GetAddrBytes() const;
214  int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const;
215 
216  explicit CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
217  bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
218 
219  friend bool operator==(const CNetAddr& a, const CNetAddr& b);
220  friend bool operator!=(const CNetAddr& a, const CNetAddr& b) { return !(a == b); }
221  friend bool operator<(const CNetAddr& a, const CNetAddr& b);
222 
226  bool IsRelayable() const
227  {
228  return IsIPv4() || IsIPv6() || IsTor();
229  }
230 
234  template <typename Stream>
235  void Serialize(Stream& s) const
236  {
237  if (s.GetVersion() & ADDRV2_FORMAT) {
239  } else {
241  }
242  }
243 
247  template <typename Stream>
248  void Unserialize(Stream& s)
249  {
250  if (s.GetVersion() & ADDRV2_FORMAT) {
252  } else {
254  }
255  }
256 
257  friend class CSubNet;
258 
259  private:
268  bool SetTor(const std::string& addr);
269 
277  bool SetI2P(const std::string& addr);
278 
282  enum BIP155Network : uint8_t {
283  IPV4 = 1,
284  IPV6 = 2,
285  TORV2 = 3,
286  TORV3 = 4,
287  I2P = 5,
288  CJDNS = 6,
289  };
290 
294  static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
295 
301  static constexpr size_t MAX_ADDRV2_SIZE = 512;
302 
309 
317  bool SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size);
318 
322  void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const
323  {
324  size_t prefix_size;
325 
326  switch (m_net) {
327  case NET_IPV6:
328  assert(m_addr.size() == sizeof(arr));
329  memcpy(arr, m_addr.data(), m_addr.size());
330  return;
331  case NET_IPV4:
332  prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
333  assert(prefix_size + m_addr.size() == sizeof(arr));
334  memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
335  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
336  return;
337  case NET_ONION:
338  if (m_addr.size() == ADDR_TORV3_SIZE) {
339  break;
340  }
341  prefix_size = sizeof(TORV2_IN_IPV6_PREFIX);
342  assert(prefix_size + m_addr.size() == sizeof(arr));
343  memcpy(arr, TORV2_IN_IPV6_PREFIX.data(), prefix_size);
344  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
345  return;
346  case NET_INTERNAL:
347  prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
348  assert(prefix_size + m_addr.size() == sizeof(arr));
349  memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
350  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
351  return;
352  case NET_I2P:
353  break;
354  case NET_CJDNS:
355  break;
356  case NET_UNROUTABLE:
357  case NET_MAX:
358  assert(false);
359  } // no default case, so the compiler can warn about missing cases
360 
361  // Serialize TORv3, I2P and CJDNS as all-zeros.
362  memset(arr, 0x0, V1_SERIALIZATION_SIZE);
363  }
364 
368  template <typename Stream>
369  void SerializeV1Stream(Stream& s) const
370  {
371  uint8_t serialized[V1_SERIALIZATION_SIZE];
372 
373  SerializeV1Array(serialized);
374 
375  s << serialized;
376  }
377 
381  template <typename Stream>
382  void SerializeV2Stream(Stream& s) const
383  {
384  if (IsInternal()) {
385  // Serialize NET_INTERNAL as embedded in IPv6. We need to
386  // serialize such addresses from addrman.
387  s << static_cast<uint8_t>(BIP155Network::IPV6);
390  return;
391  }
392 
393  s << static_cast<uint8_t>(GetBIP155Network());
394  s << m_addr;
395  }
396 
401  {
402  // Use SetLegacyIPv6() so that m_net is set correctly. For example
403  // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
404  SetLegacyIPv6(arr);
405  }
406 
410  template <typename Stream>
411  void UnserializeV1Stream(Stream& s)
412  {
413  uint8_t serialized[V1_SERIALIZATION_SIZE];
414 
415  s >> serialized;
416 
417  UnserializeV1Array(serialized);
418  }
419 
423  template <typename Stream>
424  void UnserializeV2Stream(Stream& s)
425  {
426  uint8_t bip155_net;
427  s >> bip155_net;
428 
429  size_t address_size;
430  s >> COMPACTSIZE(address_size);
431 
432  if (address_size > MAX_ADDRV2_SIZE) {
433  throw std::ios_base::failure(strprintf(
434  "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
435  }
436 
437  m_scope_id = 0;
438 
439  if (SetNetFromBIP155Network(bip155_net, address_size)) {
440  m_addr.resize(address_size);
441  s >> MakeSpan(m_addr);
442 
443  if (m_net != NET_IPV6) {
444  return;
445  }
446 
447  // Do some special checks on IPv6 addresses.
448 
449  // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
450  // gossiped but could be coming from addrman, when unserializing from
451  // disk.
454  memmove(m_addr.data(), m_addr.data() + INTERNAL_IN_IPV6_PREFIX.size(),
457  return;
458  }
459 
462  return;
463  }
464 
465  // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in V1
466  // encoding). Unserialize as !IsValid(), thus ignoring them.
467  } else {
468  // If we receive an unknown BIP155 network id (from the future?) then
469  // ignore the address - unserialize as !IsValid().
470  s.ignore(address_size);
471  }
472 
473  // Mimic a default-constructed CNetAddr object which is !IsValid() and thus
474  // will not be gossiped, but continue reading next addresses from the stream.
475  m_net = NET_IPV6;
477  }
478 };
479 
480 class CSubNet
481 {
482  protected:
486  uint8_t netmask[16];
488  bool valid;
489 
490  bool SanityCheck() const;
491 
492  public:
496  CSubNet();
497 
505  CSubNet(const CNetAddr& addr, uint8_t mask);
506 
514  CSubNet(const CNetAddr& addr, const CNetAddr& mask);
515 
520  explicit CSubNet(const CNetAddr& addr);
521 
522  bool Match(const CNetAddr &addr) const;
523 
524  std::string ToString() const;
525  bool IsValid() const;
526 
527  friend bool operator==(const CSubNet& a, const CSubNet& b);
528  friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
529  friend bool operator<(const CSubNet& a, const CSubNet& b);
530 
532  {
533  READWRITE(obj.network);
534  if (obj.network.IsIPv4()) {
535  // Before commit 102867c587f5f7954232fb8ed8e85cda78bb4d32, CSubNet used the last 4 bytes of netmask
536  // to store the relevant bytes for an IPv4 mask. For compatibility reasons, keep doing so in
537  // serialized form.
538  unsigned char dummy[12] = {0};
539  READWRITE(dummy);
540  READWRITE(MakeSpan(obj.netmask).first(4));
541  } else {
542  READWRITE(obj.netmask);
543  }
544  READWRITE(obj.valid);
545  // Mark invalid if the result doesn't pass sanity checking.
546  SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck());
547  }
548 };
549 
551 class CService : public CNetAddr
552 {
553  protected:
554  uint16_t port; // host order
555 
556  public:
557  CService();
558  CService(const CNetAddr& ip, uint16_t port);
559  CService(const struct in_addr& ipv4Addr, uint16_t port);
560  explicit CService(const struct sockaddr_in& addr);
561  uint16_t GetPort() const;
562  bool GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const;
563  bool SetSockAddr(const struct sockaddr* paddr);
564  friend bool operator==(const CService& a, const CService& b);
565  friend bool operator!=(const CService& a, const CService& b) { return !(a == b); }
566  friend bool operator<(const CService& a, const CService& b);
567  std::vector<unsigned char> GetKey() const;
568  std::string ToString() const;
569  std::string ToStringPort() const;
570  std::string ToStringIPPort() const;
571 
572  CService(const struct in6_addr& ipv6Addr, uint16_t port);
573  explicit CService(const struct sockaddr_in6& addr);
574 
576  {
577  READWRITEAS(CNetAddr, obj);
579  }
580 };
581 
582 bool SanityCheckASMap(const std::vector<bool>& asmap);
583 
584 #endif // BITCOIN_NETADDRESS_H
CNetAddr::IsIPv6
bool IsIPv6() const
Definition: netaddress.cpp:338
ADDRV2_FORMAT
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:32
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:551
CService::GetSockAddr
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
Definition: netaddress.cpp:973
CService::operator!=
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:565
NET_UNROUTABLE
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:46
CNetAddr::GetGroup
std::vector< unsigned char > GetGroup(const std::vector< bool > &asmap) const
Get the canonical identifier of our network group.
Definition: netaddress.cpp:757
NET_IPV4
@ NET_IPV4
IPv4.
Definition: netaddress.h:49
CNetAddr::SetI2P
bool SetI2P(const std::string &addr)
Parse an I2P address and set this object to it.
Definition: netaddress.cpp:287
CNetAddr::SetNetFromBIP155Network
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
CNetAddr::m_addr
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:126
CNetAddr::GetAddrBytes
std::vector< unsigned char > GetAddrBytes() const
Definition: netaddress.cpp:811
CNetAddr::SetLegacyIPv6
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:153
CNetAddr::GetNetClass
Network GetNetClass() const
Definition: netaddress.cpp:698
CSubNet::SERIALIZE_METHODS
SERIALIZE_METHODS(CSubNet, obj)
Definition: netaddress.h:531
NET_INTERNAL
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:65
TORV2_IN_IPV6_PREFIX
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
CNetAddr::IsRFC3964
bool IsRFC3964() const
Definition: netaddress.cpp:375
CNetAddr::GetIn6Addr
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 address.
Definition: netaddress.cpp:666
CNetAddr::GetReachabilityFrom
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:843
string.h
CNetAddr
Network address.
Definition: netaddress.h:119
NET_MAX
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:68
HasPrefix
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
CNetAddr::IsRFC2544
bool IsRFC2544() const
Definition: netaddress.cpp:348
CNetAddr::IsRFC4862
bool IsRFC4862() const
Definition: netaddress.cpp:392
CNetAddr::ToString
std::string ToString() const
Definition: netaddress.cpp:622
CNetAddr::UnserializeV1Array
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:400
CNetAddr::SetTor
bool SetTor(const std::string &addr)
Parse a Tor address and set this object to it.
Definition: netaddress.cpp:241
CSubNet::valid
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:488
bitcoin-config.h
CSubNet::operator!=
friend bool operator!=(const CSubNet &a, const CSubNet &b)
Definition: netaddress.h:528
CustomUintFormatter
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:508
CNetAddr::UnserializeV1Stream
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:411
READWRITEAS
#define READWRITEAS(type, obj)
Definition: serialize.h:176
Network
Network
A network type.
Definition: netaddress.h:43
CNetAddr::IsRelayable
bool IsRelayable() const
Whether this address should be relayed to other peers even if we can't reach it ourselves.
Definition: netaddress.h:226
CNetAddr::IsRFC6145
bool IsRFC6145() const
Definition: netaddress.cpp:403
CNetAddr::IsInternal
bool IsInternal() const
Definition: netaddress.cpp:518
CService::ToStringIPPort
std::string ToStringIPPort() const
Definition: netaddress.cpp:1019
CNetAddr::MAX_ADDRV2_SIZE
static constexpr size_t MAX_ADDRV2_SIZE
Maximum size of an address as defined in BIP155 (in bytes).
Definition: netaddress.h:301
CSubNet::Match
bool Match(const CNetAddr &addr) const
Definition: netaddress.cpp:1138
CNetAddr::IsBindAny
bool IsBindAny() const
Definition: netaddress.cpp:328
CNetAddr::GetInAddr
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:647
CNetAddr::GetBIP155Network
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:27
CNetAddr::ToStringIP
std::string ToStringIP() const
Definition: netaddress.cpp:570
tinyformat.h
CNetAddr::Unserialize
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:248
IPV6
@ IPV6
Definition: netbase.cpp:280
CNetAddr::IsIPv4
bool IsIPv4() const
Definition: netaddress.cpp:336
Span
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:92
ADDR_INTERNAL_SIZE
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:114
strencodings.h
CNetAddr::IsI2P
bool IsI2P() const
Check whether this object represents an I2P address.
Definition: netaddress.cpp:436
NET_I2P
@ NET_I2P
I2P.
Definition: netaddress.h:58
CNetAddr::GetNetwork
enum Network GetNetwork() const
Definition: netaddress.cpp:543
CService::ToString
std::string ToString() const
Definition: netaddress.cpp:1028
CNetAddr::m_scope_id
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:137
CSubNet::network
CNetAddr network
Network (base) address.
Definition: netaddress.h:484
ADDR_TORV3_SIZE
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:105
CNetAddr::SetSpecial
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:224
CService::SetSockAddr
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:932
CNetAddr::UnserializeV2Stream
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:424
CNetAddr::IsRFC3849
bool IsRFC3849() const
Definition: netaddress.cpp:370
compat.h
CNetAddr::IsRoutable
bool IsRoutable() const
Definition: netaddress.cpp:508
CNetAddr::GetHash
uint64_t GetHash() const
Definition: netaddress.cpp:821
CNetAddr::SerializeV1Stream
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:369
CService::SERIALIZE_METHODS
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:575
CService::ToStringPort
std::string ToStringPort() const
Definition: netaddress.cpp:1014
INTERNAL_IN_IPV6_PREFIX
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
CNetAddr::CJDNS
@ CJDNS
Definition: netaddress.h:288
CNetAddr::SerializeV1Array
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:322
CNetAddr::GetMappedAS
uint32_t GetMappedAS(const std::vector< bool > &asmap) const
Definition: netaddress.cpp:716
CNetAddr::IsRFC6052
bool IsRFC6052() const
Definition: netaddress.cpp:380
CSubNet::operator<
friend bool operator<(const CSubNet &a, const CSubNet &b)
Definition: netaddress.cpp:1232
CNetAddr::IsValid
bool IsValid() const
Definition: netaddress.cpp:469
CNetAddr::IsRFC1918
bool IsRFC1918() const
Definition: netaddress.cpp:340
CNetAddr::IsRFC6598
bool IsRFC6598() const
Definition: netaddress.cpp:358
CSubNet
Definition: netaddress.h:480
CNetAddr::IsHeNet
bool IsHeNet() const
Definition: netaddress.cpp:422
CNetAddr::IsCJDNS
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
Definition: netaddress.cpp:441
CNetAddr::operator!=
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:220
READWRITE
#define READWRITE(...)
Definition: serialize.h:175
CNetAddr::IsRFC5737
bool IsRFC5737() const
Definition: netaddress.cpp:363
CNetAddr::operator==
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:627
IPV4_IN_IPV6_PREFIX
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
SanityCheckASMap
bool SanityCheckASMap(const std::vector< bool > &asmap)
Definition: netaddress.cpp:1237
CService::GetPort
uint16_t GetPort() const
Definition: netaddress.cpp:946
attributes.h
CNetAddr::BIP155Network
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:282
CNetAddr::I2P
@ I2P
Definition: netaddress.h:287
name
const char * name
Definition: rest.cpp:42
prevector::resize
void resize(size_type new_size)
Definition: prevector.h:316
CSubNet::netmask
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:486
CService::operator==
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:951
prevector< ADDR_IPV6_SIZE, uint8_t >
prevector::assign
void assign(size_type n, const T &val)
Definition: prevector.h:218
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
CNetAddr::SerializeV2Stream
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:382
ADDR_IPV6_SIZE
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:98
ADDR_IPV4_SIZE
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:95
CSubNet::operator==
friend bool operator==(const CSubNet &a, const CSubNet &b)
Definition: netaddress.cpp:1227
CNetAddr::GetLinkedIPv4
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:681
CSubNet::ToString
std::string ToString() const
Definition: netaddress.cpp:1166
CNetAddr::operator<
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:632
ADDR_I2P_SIZE
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:108
CService::port
uint16_t port
Definition: netaddress.h:554
prevector::data
value_type * data()
Definition: prevector.h:528
CNetAddr::IPV6
@ IPV6
Definition: netaddress.h:284
NET_ONION
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:55
CNetAddr::IsRFC4193
bool IsRFC4193() const
Definition: netaddress.cpp:398
CNetAddr::IsRFC7343
bool IsRFC7343() const
Definition: netaddress.cpp:416
prevector::size
size_type size() const
Definition: prevector.h:282
CNetAddr::IsTor
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:431
CNetAddr::TORV3
@ TORV3
Definition: netaddress.h:286
ADDR_CJDNS_SIZE
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:111
CSubNet::IsValid
bool IsValid() const
Definition: netaddress.cpp:1199
serialize.h
NET_IPV6
@ NET_IPV6
IPv6.
Definition: netaddress.h:52
CNetAddr::SetInternal
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:185
CNetAddr::m_net
Network m_net
Network to which this address belongs.
Definition: netaddress.h:131
COMPACTSIZE
#define COMPACTSIZE(obj)
Definition: serialize.h:480
prevector.h
CNetAddr::CNetAddr
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
Definition: netaddress.cpp:120
NET_CJDNS
@ NET_CJDNS
CJDNS.
Definition: netaddress.h:61
CNetAddr::IsAddrV1Compatible
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:523
CNetAddr::IsRFC3927
bool IsRFC3927() const
Definition: netaddress.cpp:353
CNetAddr::HasLinkedIPv4
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:676
SER_READ
#define SER_READ(obj, code)
Definition: serialize.h:177
CNetAddr::IsRFC4843
bool IsRFC4843() const
Definition: netaddress.cpp:410
CNetAddr::IPV4
@ IPV4
Definition: netaddress.h:283
CNetAddr::V1_SERIALIZATION_SIZE
static constexpr size_t V1_SERIALIZATION_SIZE
Size of CNetAddr when serialized as ADDRv1 (pre-BIP155) (in bytes).
Definition: netaddress.h:294
Using
static Wrapper< Formatter, T & > Using(T &&t)
Cause serialization/deserialization of an object to be done using a specified formatter class.
Definition: serialize.h:476
CSubNet::CSubNet
CSubNet()
Construct an invalid subnet (empty, Match() always returns false).
Definition: netaddress.cpp:1033
MakeSpan
constexpr Span< A > MakeSpan(A(&a)[N])
MakeSpan for arrays:
Definition: span.h:222
CNetAddr::Serialize
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:235
CNetAddr::IsLocal
bool IsLocal() const
Definition: netaddress.cpp:443
assert
assert(std::addressof(::ChainstateActive().CoinsTip())==std::addressof(coins_cache))
CNetAddr::TORV2
@ TORV2
Definition: netaddress.h:285
CNetAddr::IsRFC4380
bool IsRFC4380() const
Definition: netaddress.cpp:387
CService::CService
CService()
Definition: netaddress.cpp:906
CNetAddr::SetIP
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:122
ADDR_TORV2_SIZE
static constexpr size_t ADDR_TORV2_SIZE
Size of TORv2 address (in bytes).
Definition: netaddress.h:101
CService::GetKey
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:1006
CService::operator<
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:956
CSubNet::SanityCheck
bool SanityCheck() const
Definition: netaddress.cpp:1204