Bitcoin Core  0.20.99
P2P Digital Currency
Classes | Enumerations | Functions | Variables
netaddress.h File Reference
#include <attributes.h>
#include <compat.h>
#include <prevector.h>
#include <serialize.h>
#include <tinyformat.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <array>
#include <cstdint>
#include <ios>
#include <string>
#include <vector>
Include dependency graph for netaddress.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CNetAddr
 Network address. More...
 
class  CSubNet
 
class  CService
 A combination of a network address (CNetAddr) and a (TCP) port. More...
 

Enumerations

enum  Network {
  NET_UNROUTABLE = 0, NET_IPV4, NET_IPV6, NET_ONION,
  NET_I2P, NET_CJDNS, NET_INTERNAL, NET_MAX
}
 A network type. More...
 

Functions

bool SanityCheckASMap (const std::vector< bool > &asmap)
 

Variables

static const int ADDRV2_FORMAT = 0x20000000
 A flag that is ORed into the protocol version to designate that addresses should be serialized in (unserialized from) v2 format (BIP155). More...
 
static const std::array< uint8_t, 12 > IPV4_IN_IPV6_PREFIX
 Prefix of an IPv6 address when it contains an embedded IPv4 address. More...
 
static const std::array< uint8_t, 6 > TORV2_IN_IPV6_PREFIX
 Prefix of an IPv6 address when it contains an embedded TORv2 address. More...
 
static const std::array< uint8_t, 6 > INTERNAL_IN_IPV6_PREFIX
 Prefix of an IPv6 address when it contains an embedded "internal" address. More...
 
static constexpr size_t ADDR_IPV4_SIZE = 4
 Size of IPv4 address (in bytes). More...
 
static constexpr size_t ADDR_IPV6_SIZE = 16
 Size of IPv6 address (in bytes). More...
 
static constexpr size_t ADDR_TORV2_SIZE = 10
 Size of TORv2 address (in bytes). More...
 
static constexpr size_t ADDR_TORV3_SIZE = 32
 Size of TORv3 address (in bytes). More...
 
static constexpr size_t ADDR_I2P_SIZE = 32
 Size of I2P address (in bytes). More...
 
static constexpr size_t ADDR_CJDNS_SIZE = 16
 Size of CJDNS address (in bytes). More...
 
static constexpr size_t ADDR_INTERNAL_SIZE = 10
 Size of "internal" (NET_INTERNAL) address (in bytes). More...
 

Enumeration Type Documentation

◆ Network

enum Network

A network type.

Note
An address may belong to more than one network, for example 10.0.0.1 belongs to both NET_UNROUTABLE and NET_IPV4. Keep these sequential starting from 0 and NET_MAX as the last entry. We have loops like for (int i = 0; i < NET_MAX; i++) that expect to iterate over all enum values and also GetExtNetwork() "extends" this enum by introducing standalone constants starting from NET_MAX.
Enumerator
NET_UNROUTABLE 

Addresses from these networks are not publicly routable on the global Internet.

NET_IPV4 

IPv4.

NET_IPV6 

IPv6.

NET_ONION 

TOR (v2 or v3)

NET_I2P 

I2P.

NET_CJDNS 

CJDNS.

NET_INTERNAL 

A set of addresses that represent the hash of a string or FQDN.

We use them in CAddrMan to keep track of which DNS seeds were used.

NET_MAX 

Dummy value to indicate the number of NET_* constants.

Definition at line 43 of file netaddress.h.

Function Documentation

◆ SanityCheckASMap()

bool SanityCheckASMap ( const std::vector< bool > &  asmap)

Definition at line 1133 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ADDR_CJDNS_SIZE

constexpr size_t ADDR_CJDNS_SIZE = 16
static

Size of CJDNS address (in bytes).

Definition at line 111 of file netaddress.h.

◆ ADDR_I2P_SIZE

constexpr size_t ADDR_I2P_SIZE = 32
static

Size of I2P address (in bytes).

Definition at line 108 of file netaddress.h.

◆ ADDR_INTERNAL_SIZE

constexpr size_t ADDR_INTERNAL_SIZE = 10
static

Size of "internal" (NET_INTERNAL) address (in bytes).

Definition at line 114 of file netaddress.h.

◆ ADDR_IPV4_SIZE

constexpr size_t ADDR_IPV4_SIZE = 4
static

Size of IPv4 address (in bytes).

Definition at line 95 of file netaddress.h.

◆ ADDR_IPV6_SIZE

constexpr size_t ADDR_IPV6_SIZE = 16
static

Size of IPv6 address (in bytes).

Definition at line 98 of file netaddress.h.

◆ ADDR_TORV2_SIZE

constexpr size_t ADDR_TORV2_SIZE = 10
static

Size of TORv2 address (in bytes).

Definition at line 101 of file netaddress.h.

◆ ADDR_TORV3_SIZE

constexpr size_t ADDR_TORV3_SIZE = 32
static

Size of TORv3 address (in bytes).

This is the length of just the address as used in BIP155, without the checksum and the version byte.

Definition at line 105 of file netaddress.h.

◆ ADDRV2_FORMAT

const int ADDRV2_FORMAT = 0x20000000
static

A flag that is ORed into the protocol version to designate that addresses should be serialized in (unserialized from) v2 format (BIP155).

Make sure that this does not collide with any of the values in version.h or with SERIALIZE_TRANSACTION_NO_WITNESS.

Definition at line 32 of file netaddress.h.

◆ INTERNAL_IN_IPV6_PREFIX

const std::array<uint8_t, 6> INTERNAL_IN_IPV6_PREFIX
static
Initial value:
{
0xFD, 0x6B, 0x88, 0xC0, 0x87, 0x24
}

Prefix of an IPv6 address when it contains an embedded "internal" address.

Used when (un)serializing addresses in ADDRv1 format (pre-BIP155). The prefix comes from 0xFD + SHA256("bitcoin")[0:5]. Such dummy IPv6 addresses are guaranteed to not be publicly routable as they fall under RFC4193's fc00::/7 subnet allocated to unique-local addresses.

Definition at line 90 of file netaddress.h.

◆ IPV4_IN_IPV6_PREFIX

const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX
static
Initial value:
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF
}

Prefix of an IPv6 address when it contains an embedded IPv4 address.

Used when (un)serializing addresses in ADDRv1 format (pre-BIP155).

Definition at line 73 of file netaddress.h.

◆ TORV2_IN_IPV6_PREFIX

const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX
static
Initial value:
{
0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43
}

Prefix of an IPv6 address when it contains an embedded TORv2 address.

Used when (un)serializing addresses in ADDRv1 format (pre-BIP155). Such dummy IPv6 addresses are guaranteed to not be publicly routable as they fall under RFC4193's fc00::/7 subnet allocated to unique-local addresses.

Definition at line 81 of file netaddress.h.