Bitcoin ABC  0.24.7
P2P Digital Currency
netaddress.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2016 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)
9 #include <config/bitcoin-config.h>
10 #endif
11 
12 #include <attributes.h>
13 #include <compat.h>
14 #include <prevector.h>
15 #include <serialize.h>
16 #include <util/strencodings.h>
17 #include <util/string.h>
18 
19 #include <tinyformat.h>
20 
21 #include <array>
22 #include <cstdint>
23 #include <ios>
24 #include <string>
25 #include <vector>
26 
32 static const int ADDRV2_FORMAT = 0x20000000;
33 
43 enum Network {
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 
80 static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{
81  {0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43}};
82 
88 static const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX{
89  // 0xFD + sha256("bitcoin")[0:5].
90  {0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24}};
91 
93 static constexpr size_t ADDR_IPV4_SIZE = 4;
94 
96 static constexpr size_t ADDR_IPV6_SIZE = 16;
97 
99 static constexpr size_t ADDR_TORV2_SIZE = 10;
100 
103 static constexpr size_t ADDR_TORV3_SIZE = 32;
104 
106 static constexpr size_t ADDR_I2P_SIZE = 32;
107 
109 static constexpr size_t ADDR_CJDNS_SIZE = 16;
110 
112 static constexpr size_t ADDR_INTERNAL_SIZE = 10;
113 
117 class CNetAddr {
118 protected:
124 
129 
134  uint32_t m_scope_id{0};
135 
136 public:
137  CNetAddr();
138  explicit CNetAddr(const struct in_addr &ipv4Addr);
139  void SetIP(const CNetAddr &ip);
140 
148 
149  bool SetInternal(const std::string &name);
150 
151  // for Tor addresses
152  bool SetSpecial(const std::string &strName);
153  // INADDR_ANY equivalent
154  bool IsBindAny() const;
155  // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
156  bool IsIPv4() const;
157  // IPv6 address (not mapped IPv4, not Tor)
158  bool IsIPv6() const;
159  // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
160  bool IsRFC1918() const;
161  // IPv4 inter-network communications (198.18.0.0/15)
162  bool IsRFC2544() const;
163  // IPv4 ISP-level NAT (100.64.0.0/10)
164  bool IsRFC6598() const;
165  // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24,
166  // 203.0.113.0/24)
167  bool IsRFC5737() const;
168  // IPv6 documentation address (2001:0DB8::/32)
169  bool IsRFC3849() const;
170  // IPv4 autoconfig (169.254.0.0/16)
171  bool IsRFC3927() const;
172  // IPv6 6to4 tunnelling (2002::/16)
173  bool IsRFC3964() const;
174  // IPv6 unique local (FC00::/7)
175  bool IsRFC4193() const;
176  // IPv6 Teredo tunnelling (2001::/32)
177  bool IsRFC4380() const;
178  // IPv6 ORCHID (deprecated) (2001:10::/28)
179  bool IsRFC4843() const;
180  // IPv6 ORCHIDv2 (2001:20::/28)
181  bool IsRFC7343() const;
182  // IPv6 autoconfig (FE80::/64)
183  bool IsRFC4862() const;
184  // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
185  bool IsRFC6052() const;
186  // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in
187  // RFC2765)
188  bool IsRFC6145() const;
189  // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
190  bool IsHeNet() const;
191  bool IsTor() const;
192  bool IsI2P() const;
193  bool IsCJDNS() const;
194  bool IsLocal() const;
195  bool IsRoutable() const;
196  bool IsInternal() const;
197  bool IsValid() const;
198 
203  bool IsAddrV1Compatible() const;
204 
205  enum Network GetNetwork() const;
206  std::string ToString() const;
207  std::string ToStringIP() const;
208  uint64_t GetHash() const;
209  bool GetInAddr(struct in_addr *pipv4Addr) const;
210  Network GetNetClass() const;
211 
214  uint32_t GetLinkedIPv4() const;
216  bool HasLinkedIPv4() const;
217 
218  // The AS on the BGP path to the node we use to diversify
219  // peers in AddrMan bucketing based on the AS infrastructure.
220  // The ip->AS mapping depends on how asmap is constructed.
221  uint32_t GetMappedAS(const std::vector<bool> &asmap) const;
222 
223  std::vector<uint8_t> GetGroup(const std::vector<bool> &asmap) const;
224  std::vector<uint8_t> GetAddrBytes() const;
225  int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const;
226 
227  explicit CNetAddr(const struct in6_addr &pipv6Addr,
228  const uint32_t scope = 0);
229  bool GetIn6Addr(struct in6_addr *pipv6Addr) const;
230 
231  friend bool operator==(const CNetAddr &a, const CNetAddr &b);
232  friend bool operator!=(const CNetAddr &a, const CNetAddr &b) {
233  return !(a == b);
234  }
235  friend bool operator<(const CNetAddr &a, const CNetAddr &b);
236 
241  bool IsRelayable() const { return IsIPv4() || IsIPv6() || IsTor(); }
242 
246  template <typename Stream> void Serialize(Stream &s) const {
247  if (s.GetVersion() & ADDRV2_FORMAT) {
249  } else {
251  }
252  }
253 
257  template <typename Stream> void Unserialize(Stream &s) {
258  if (s.GetVersion() & ADDRV2_FORMAT) {
260  } else {
262  }
263  }
264 
265  friend class CSubNet;
266 
267 private:
271  enum BIP155Network : uint8_t {
272  IPV4 = 1,
273  IPV6 = 2,
274  TORV2 = 3,
275  TORV3 = 4,
276  I2P = 5,
277  CJDNS = 6,
278  };
279 
283  static constexpr size_t V1_SERIALIZATION_SIZE = ADDR_IPV6_SIZE;
284 
290  static constexpr size_t MAX_ADDRV2_SIZE = 512;
291 
298 
309  bool SetNetFromBIP155Network(uint8_t possible_bip155_net,
310  size_t address_size);
311 
315  void SerializeV1Array(uint8_t (&arr)[V1_SERIALIZATION_SIZE]) const {
316  size_t prefix_size;
317 
318  switch (m_net) {
319  case NET_IPV6:
320  assert(m_addr.size() == sizeof(arr));
321  memcpy(arr, m_addr.data(), m_addr.size());
322  return;
323  case NET_IPV4:
324  prefix_size = sizeof(IPV4_IN_IPV6_PREFIX);
325  assert(prefix_size + m_addr.size() == sizeof(arr));
326  memcpy(arr, IPV4_IN_IPV6_PREFIX.data(), prefix_size);
327  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
328  return;
329  case NET_ONION:
330  if (m_addr.size() == ADDR_TORV3_SIZE) {
331  break;
332  }
333  prefix_size = sizeof(TORV2_IN_IPV6_PREFIX);
334  assert(prefix_size + m_addr.size() == sizeof(arr));
335  memcpy(arr, TORV2_IN_IPV6_PREFIX.data(), prefix_size);
336  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
337  return;
338  case NET_INTERNAL:
339  prefix_size = sizeof(INTERNAL_IN_IPV6_PREFIX);
340  assert(prefix_size + m_addr.size() == sizeof(arr));
341  memcpy(arr, INTERNAL_IN_IPV6_PREFIX.data(), prefix_size);
342  memcpy(arr + prefix_size, m_addr.data(), m_addr.size());
343  return;
344  case NET_I2P:
345  break;
346  case NET_CJDNS:
347  break;
348  case NET_UNROUTABLE:
349  case NET_MAX:
350  assert(false);
351  } // no default case, so the compiler can warn about missing cases
352 
353  // Serialize TORv3, I2P and CJDNS as all-zeros.
354  memset(arr, 0x0, V1_SERIALIZATION_SIZE);
355  }
356 
360  template <typename Stream> void SerializeV1Stream(Stream &s) const {
361  uint8_t serialized[V1_SERIALIZATION_SIZE];
362 
363  SerializeV1Array(serialized);
364 
365  s << serialized;
366  }
367 
371  template <typename Stream> void SerializeV2Stream(Stream &s) const {
372  if (IsInternal()) {
373  // Serialize NET_INTERNAL as embedded in IPv6. We need to
374  // serialize such addresses from addrman.
375  s << static_cast<uint8_t>(BIP155Network::IPV6);
378  return;
379  }
380 
381  s << static_cast<uint8_t>(GetBIP155Network());
382  s << m_addr;
383  }
384 
389  // Use SetLegacyIPv6() so that m_net is set correctly. For example
390  // ::FFFF:0102:0304 should be set as m_net=NET_IPV4 (1.2.3.4).
391  SetLegacyIPv6(arr);
392  }
393 
397  template <typename Stream> void UnserializeV1Stream(Stream &s) {
398  uint8_t serialized[V1_SERIALIZATION_SIZE];
399 
400  s >> serialized;
401 
402  UnserializeV1Array(serialized);
403  }
404 
408  template <typename Stream> void UnserializeV2Stream(Stream &s) {
409  uint8_t bip155_net;
410  s >> bip155_net;
411 
412  size_t address_size;
413  s >> COMPACTSIZE(address_size);
414 
415  if (address_size > MAX_ADDRV2_SIZE) {
416  throw std::ios_base::failure(strprintf(
417  "Address too long: %u > %u", address_size, MAX_ADDRV2_SIZE));
418  }
419 
420  m_scope_id = 0;
421 
422  if (SetNetFromBIP155Network(bip155_net, address_size)) {
423  m_addr.resize(address_size);
424  s >> MakeSpan(m_addr);
425 
426  if (m_net != NET_IPV6) {
427  return;
428  }
429 
430  // Do some special checks on IPv6 addresses.
431 
432  // Recognize NET_INTERNAL embedded in IPv6, such addresses are not
433  // gossiped but could be coming from addrman, when unserializing
434  // from disk.
437  memmove(m_addr.data(),
441  return;
442  }
443 
446  return;
447  }
448 
449  // IPv4 and TORv2 are not supposed to be embedded in IPv6 (like in
450  // V1 encoding). Unserialize as !IsValid(), thus ignoring them.
451  } else {
452  // If we receive an unknown BIP155 network id (from the future?)
453  // then ignore the address - unserialize as !IsValid().
454  s.ignore(address_size);
455  }
456 
457  // Mimic a default-constructed CNetAddr object which is !IsValid() and
458  // thus will not be gossiped, but continue reading next addresses from
459  // the stream.
460  m_net = NET_IPV6;
462  }
463 };
464 
465 class CSubNet {
466 protected:
470  uint8_t netmask[16];
472  bool valid;
473 
474  bool SanityCheck() const;
475 
476 public:
477  CSubNet();
478  CSubNet(const CNetAddr &addr, uint8_t mask);
479  CSubNet(const CNetAddr &addr, const CNetAddr &mask);
480 
481  // constructor for single ip subnet (<ipv4>/32 or <ipv6>/128)
482  explicit CSubNet(const CNetAddr &addr);
483 
484  bool Match(const CNetAddr &addr) const;
485 
486  std::string ToString() const;
487  bool IsValid() const;
488 
489  friend bool operator==(const CSubNet &a, const CSubNet &b);
490  friend bool operator!=(const CSubNet &a, const CSubNet &b) {
491  return !(a == b);
492  }
493  friend bool operator<(const CSubNet &a, const CSubNet &b);
494 
496  READWRITE(obj.network);
497  if (obj.network.IsIPv4()) {
498  // Before D9176, CSubNet used the last 4 bytes of netmask to store
499  // the relevant bytes for an IPv4 mask. For compatiblity reasons,
500  // keep doing so in serialized form.
501  uint8_t dummy[12] = {0};
502  READWRITE(dummy);
503  READWRITE(MakeSpan(obj.netmask).first(4));
504  } else {
505  READWRITE(obj.netmask);
506  }
507  READWRITE(obj.valid);
508  // Mark invalid if the result doesn't pass sanity checking.
509  SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck());
510  }
511 };
512 
514 class CService : public CNetAddr {
515 protected:
516  // host order
517  uint16_t port;
518 
519 public:
520  CService();
521  CService(const CNetAddr &ip, uint16_t port);
522  CService(const struct in_addr &ipv4Addr, uint16_t port);
523  explicit CService(const struct sockaddr_in &addr);
524  uint16_t GetPort() const;
525  bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const;
526  bool SetSockAddr(const struct sockaddr *paddr);
527  friend bool operator==(const CService &a, const CService &b);
528  friend bool operator!=(const CService &a, const CService &b) {
529  return !(a == b);
530  }
531  friend bool operator<(const CService &a, const CService &b);
532  std::vector<uint8_t> GetKey() const;
533  std::string ToString() const;
534  std::string ToStringPort() const;
535  std::string ToStringIPPort() const;
536 
537  CService(const struct in6_addr &ipv6Addr, uint16_t port);
538  explicit CService(const struct sockaddr_in6 &addr);
539 
541  READWRITEAS(CNetAddr, obj);
543  }
544 };
545 
546 bool SanityCheckASMap(const std::vector<bool> &asmap);
547 
548 #endif // BITCOIN_NETADDRESS_H
CNetAddr::IsIPv6
bool IsIPv6() const
Definition: netaddress.cpp:305
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:514
CService::GetSockAddr
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const
Obtain the IPv4/6 socket address this represents.
Definition: netaddress.cpp:961
CService::operator!=
friend bool operator!=(const CService &a, const CService &b)
Definition: netaddress.h:528
ADDRV2_FORMAT
static const 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
NET_UNROUTABLE
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
Definition: netaddress.h:46
NET_IPV4
@ NET_IPV4
IPv4.
Definition: netaddress.h:49
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:59
CNetAddr::m_addr
prevector< ADDR_IPV6_SIZE, uint8_t > m_addr
Raw representation of the network address.
Definition: netaddress.h:123
CNetAddr::SetLegacyIPv6
void SetLegacyIPv6(Span< const uint8_t > ipv6)
Set from a legacy IPv6 address.
Definition: netaddress.cpp:156
CNetAddr::GetNetClass
Network GetNetClass() const
Definition: netaddress.cpp:670
CSubNet::SERIALIZE_METHODS
SERIALIZE_METHODS(CSubNet, obj)
Definition: netaddress.h:495
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:80
CNetAddr::IsRFC3964
bool IsRFC3964() const
Definition: netaddress.cpp:339
CNetAddr::GetIn6Addr
bool GetIn6Addr(struct in6_addr *pipv6Addr) const
Try to get our IPv6 address.
Definition: netaddress.cpp:638
CNetAddr::GetReachabilityFrom
int GetReachabilityFrom(const CNetAddr *paddrPartner=nullptr) const
Calculates a metric for how reachable (*this) is from a given partner.
Definition: netaddress.cpp:818
string.h
CNetAddr
Network address.
Definition: netaddress.h:117
NET_MAX
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
Definition: netaddress.h:68
CNetAddr::IsRFC2544
bool IsRFC2544() const
Definition: netaddress.cpp:315
CNetAddr::IsRFC4862
bool IsRFC4862() const
Definition: netaddress.cpp:355
CNetAddr::ToString
std::string ToString() const
Definition: netaddress.cpp:597
CNetAddr::UnserializeV1Array
void UnserializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE])
Unserialize from a pre-ADDRv2/BIP155 format from an array.
Definition: netaddress.h:388
CSubNet::valid
bool valid
Is this value valid? (only used to signal parse errors)
Definition: netaddress.h:472
CSubNet::operator!=
friend bool operator!=(const CSubNet &a, const CSubNet &b)
Definition: netaddress.h:490
CustomUintFormatter
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:623
CNetAddr::UnserializeV1Stream
void UnserializeV1Stream(Stream &s)
Unserialize from a pre-ADDRv2/BIP155 format from a stream.
Definition: netaddress.h:397
READWRITEAS
#define READWRITEAS(type, obj)
Definition: serialize.h:180
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:241
CNetAddr::IsRFC6145
bool IsRFC6145() const
Definition: netaddress.cpp:365
CNetAddr::IsInternal
bool IsInternal() const
Definition: netaddress.cpp:485
CService::ToStringIPPort
std::string ToStringIPPort() const
Definition: netaddress.cpp:1012
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:290
CSubNet::Match
bool Match(const CNetAddr &addr) const
Definition: netaddress.cpp:1127
CNetAddr::IsBindAny
bool IsBindAny() const
Definition: netaddress.cpp:293
CNetAddr::GetGroup
std::vector< uint8_t > GetGroup(const std::vector< bool > &asmap) const
Get the canonical identifier of our network group.
Definition: netaddress.cpp:732
CNetAddr::GetInAddr
bool GetInAddr(struct in_addr *pipv4Addr) const
Try to get our IPv4 address.
Definition: netaddress.cpp:619
CNetAddr::GetBIP155Network
BIP155Network GetBIP155Network() const
Get the BIP155 network id of this address.
Definition: netaddress.cpp:28
CNetAddr::ToStringIP
std::string ToStringIP() const
Definition: netaddress.cpp:537
tinyformat.h
CNetAddr::Unserialize
void Unserialize(Stream &s)
Unserialize from a stream.
Definition: netaddress.h:257
IPV6
@ IPV6
Definition: netbase.cpp:326
CNetAddr::IsIPv4
bool IsIPv4() const
Definition: netaddress.cpp:301
Span
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:83
ADDR_INTERNAL_SIZE
static constexpr size_t ADDR_INTERNAL_SIZE
Size of "internal" (NET_INTERNAL) address (in bytes).
Definition: netaddress.h:112
strencodings.h
CNetAddr::IsI2P
bool IsI2P() const
Check whether this object represents an I2P address.
Definition: netaddress.cpp:401
NET_I2P
@ NET_I2P
I2P.
Definition: netaddress.h:58
CNetAddr::GetNetwork
enum Network GetNetwork() const
Definition: netaddress.cpp:510
CService::ToString
std::string ToString() const
Definition: netaddress.cpp:1020
CNetAddr::m_scope_id
uint32_t m_scope_id
Scope id if scoped/link-local IPV6 address.
Definition: netaddress.h:134
CSubNet::network
CNetAddr network
Network (base) address.
Definition: netaddress.h:468
ADDR_TORV3_SIZE
static constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition: netaddress.h:103
CService::SetSockAddr
bool SetSockAddr(const struct sockaddr *paddr)
Definition: netaddress.cpp:919
CService::GetKey
std::vector< uint8_t > GetKey() const
Definition: netaddress.cpp:999
CNetAddr::UnserializeV2Stream
void UnserializeV2Stream(Stream &s)
Unserialize from a ADDRv2 / BIP155 format.
Definition: netaddress.h:408
CNetAddr::IsRFC3849
bool IsRFC3849() const
Definition: netaddress.cpp:334
compat.h
CNetAddr::IsRoutable
bool IsRoutable() const
Definition: netaddress.cpp:473
CNetAddr::GetHash
uint64_t GetHash() const
Definition: netaddress.cpp:796
CNetAddr::SerializeV1Stream
void SerializeV1Stream(Stream &s) const
Serialize in pre-ADDRv2/BIP155 format to a stream.
Definition: netaddress.h:360
CService::SERIALIZE_METHODS
SERIALIZE_METHODS(CService, obj)
Definition: netaddress.h:540
CService::ToStringPort
std::string ToStringPort() const
Definition: netaddress.cpp:1008
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:591
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:88
CNetAddr::CJDNS
@ CJDNS
Definition: netaddress.h:277
CNetAddr::SerializeV1Array
void SerializeV1Array(uint8_t(&arr)[V1_SERIALIZATION_SIZE]) const
Serialize in pre-ADDRv2/BIP155 format to an array.
Definition: netaddress.h:315
CNetAddr::GetMappedAS
uint32_t GetMappedAS(const std::vector< bool > &asmap) const
Definition: netaddress.cpp:688
CNetAddr::IsRFC6052
bool IsRFC6052() const
Definition: netaddress.cpp:343
CSubNet::operator<
friend bool operator<(const CSubNet &a, const CSubNet &b)
Definition: netaddress.cpp:1178
CNetAddr::IsValid
bool IsValid() const
Definition: netaddress.cpp:438
CNetAddr::GetAddrBytes
std::vector< uint8_t > GetAddrBytes() const
Definition: netaddress.cpp:787
CNetAddr::IsRFC1918
bool IsRFC1918() const
Definition: netaddress.cpp:309
CNetAddr::IsRFC6598
bool IsRFC6598() const
Definition: netaddress.cpp:323
CSubNet
Definition: netaddress.h:465
HasPrefix
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:80
CNetAddr::IsHeNet
bool IsHeNet() const
Definition: netaddress.cpp:384
CNetAddr::IsCJDNS
bool IsCJDNS() const
Check whether this object represents a CJDNS address.
Definition: netaddress.cpp:408
CNetAddr::operator!=
friend bool operator!=(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.h:232
READWRITE
#define READWRITE(...)
Definition: serialize.h:179
CNetAddr::IsRFC5737
bool IsRFC5737() const
Definition: netaddress.cpp:327
CNetAddr::operator==
friend bool operator==(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:601
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:1183
CService::GetPort
uint16_t GetPort() const
Definition: netaddress.cpp:934
attributes.h
CNetAddr::BIP155Network
BIP155Network
BIP155 network ids recognized by this software.
Definition: netaddress.h:271
CNetAddr::I2P
@ I2P
Definition: netaddress.h:276
name
const char * name
Definition: rest.cpp:43
prevector::resize
void resize(size_type new_size)
Definition: prevector.h:416
CSubNet::netmask
uint8_t netmask[16]
Netmask, in network byte order.
Definition: netaddress.h:470
CService::operator==
friend bool operator==(const CService &a, const CService &b)
Definition: netaddress.cpp:938
prevector< ADDR_IPV6_SIZE, uint8_t >
CNetAddr::SetSpecial
bool SetSpecial(const std::string &strName)
Parse a TOR address and set this object to it.
Definition: netaddress.cpp:234
prevector::assign
void assign(size_type n, const T &val)
Definition: prevector.h:326
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
CNetAddr::SerializeV2Stream
void SerializeV2Stream(Stream &s) const
Serialize as ADDRv2 / BIP155.
Definition: netaddress.h:371
ADDR_IPV6_SIZE
static constexpr size_t ADDR_IPV6_SIZE
Size of IPv6 address (in bytes).
Definition: netaddress.h:96
ADDR_IPV4_SIZE
static constexpr size_t ADDR_IPV4_SIZE
Size of IPv4 address (in bytes).
Definition: netaddress.h:93
CSubNet::operator==
friend bool operator==(const CSubNet &a, const CSubNet &b)
Definition: netaddress.cpp:1173
CNetAddr::GetLinkedIPv4
uint32_t GetLinkedIPv4() const
For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv...
Definition: netaddress.cpp:652
CSubNet::ToString
std::string ToString() const
Definition: netaddress.cpp:1140
CNetAddr::operator<
friend bool operator<(const CNetAddr &a, const CNetAddr &b)
Definition: netaddress.cpp:605
ADDR_I2P_SIZE
static constexpr size_t ADDR_I2P_SIZE
Size of I2P address (in bytes).
Definition: netaddress.h:106
CService::port
uint16_t port
Definition: netaddress.h:517
prevector::data
value_type * data()
Definition: prevector.h:610
CNetAddr::IPV6
@ IPV6
Definition: netaddress.h:273
NET_ONION
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:55
CNetAddr::IsRFC4193
bool IsRFC4193() const
Definition: netaddress.cpp:361
CNetAddr::IsRFC7343
bool IsRFC7343() const
Definition: netaddress.cpp:378
prevector::size
size_type size() const
Definition: prevector.h:386
CNetAddr::IsTor
bool IsTor() const
Check whether this object represents a TOR address.
Definition: netaddress.cpp:394
CNetAddr::TORV3
@ TORV3
Definition: netaddress.h:275
ADDR_CJDNS_SIZE
static constexpr size_t ADDR_CJDNS_SIZE
Size of CJDNS address (in bytes).
Definition: netaddress.h:109
CSubNet::IsValid
bool IsValid() const
Definition: netaddress.cpp:1155
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:188
CNetAddr::m_net
Network m_net
Network to which this address belongs.
Definition: netaddress.h:128
COMPACTSIZE
#define COMPACTSIZE(obj)
Definition: serialize.h:597
prevector.h
CNetAddr::CNetAddr
CNetAddr()
Construct an unspecified IPv6 network address (::/128).
Definition: netaddress.cpp:123
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:489
CNetAddr::IsRFC3927
bool IsRFC3927() const
Definition: netaddress.cpp:319
CNetAddr::HasLinkedIPv4
bool HasLinkedIPv4() const
Whether this address has a linked IPv4 address (see GetLinkedIPv4()).
Definition: netaddress.cpp:647
SER_READ
#define SER_READ(obj, code)
Definition: serialize.h:182
CNetAddr::IsRFC4843
bool IsRFC4843() const
Definition: netaddress.cpp:372
CNetAddr::IPV4
@ IPV4
Definition: netaddress.h:272
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:283
CSubNet::CSubNet
CSubNet()
Definition: netaddress.cpp:1024
MakeSpan
constexpr Span< A > MakeSpan(A(&a)[N])
MakeSpan for arrays:
Definition: span.h:229
CNetAddr::Serialize
void Serialize(Stream &s) const
Serialize to a stream.
Definition: netaddress.h:246
CNetAddr::IsLocal
bool IsLocal() const
Definition: netaddress.cpp:412
CNetAddr::TORV2
@ TORV2
Definition: netaddress.h:274
CNetAddr::IsRFC4380
bool IsRFC4380() const
Definition: netaddress.cpp:350
CService::CService
CService()
Definition: netaddress.cpp:897
CNetAddr::SetIP
void SetIP(const CNetAddr &ip)
Definition: netaddress.cpp:125
ADDR_TORV2_SIZE
static constexpr size_t ADDR_TORV2_SIZE
Size of TORv2 address (in bytes).
Definition: netaddress.h:99
CService::operator<
friend bool operator<(const CService &a, const CService &b)
Definition: netaddress.cpp:943
CSubNet::SanityCheck
bool SanityCheck() const
Definition: netaddress.cpp:1159