Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Enumerations | Functions | Variables
netaddress.h File Reference
#include <compat/compat.h>
#include <crypto/siphash.h>
#include <prevector.h>
#include <random.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...
 
struct  CNetAddr::SerParams
 
class  CSubNet
 
class  CService
 A combination of a network address (CNetAddr) and a (TCP) port. More...
 
class  CServiceHash
 

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

std::string OnionToString (Span< const uint8_t > addr)
 

Variables

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 uint8_t CJDNS_PREFIX {0xFC}
 All CJDNS addresses start with 0xFC. 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_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...
 
static constexpr uint16_t I2P_SAM31_PORT {0}
 SAM 3.1 and earlier do not support specifying ports and force the port to 0. 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 AddrMan to keep track of which DNS seeds were used.

NET_MAX 

Dummy value to indicate the number of NET_* constants.

Definition at line 32 of file netaddress.h.

Function Documentation

◆ OnionToString()

std::string OnionToString ( Span< const uint8_t >  addr)

Definition at line 573 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
staticconstexpr

Size of CJDNS address (in bytes).

Definition at line 98 of file netaddress.h.

◆ ADDR_I2P_SIZE

constexpr size_t ADDR_I2P_SIZE = 32
staticconstexpr

Size of I2P address (in bytes).

Definition at line 95 of file netaddress.h.

◆ ADDR_INTERNAL_SIZE

constexpr size_t ADDR_INTERNAL_SIZE = 10
staticconstexpr

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

Definition at line 101 of file netaddress.h.

◆ ADDR_IPV4_SIZE

constexpr size_t ADDR_IPV4_SIZE = 4
staticconstexpr

Size of IPv4 address (in bytes).

Definition at line 85 of file netaddress.h.

◆ ADDR_IPV6_SIZE

constexpr size_t ADDR_IPV6_SIZE = 16
staticconstexpr

Size of IPv6 address (in bytes).

Definition at line 88 of file netaddress.h.

◆ ADDR_TORV3_SIZE

constexpr size_t ADDR_TORV3_SIZE = 32
staticconstexpr

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 92 of file netaddress.h.

◆ CJDNS_PREFIX

constexpr uint8_t CJDNS_PREFIX {0xFC}
staticconstexpr

All CJDNS addresses start with 0xFC.

See https://github.com/cjdelisle/cjdns/blob/master/doc/Whitepaper.md#pulling-it-all-together

Definition at line 82 of file netaddress.h.

◆ I2P_SAM31_PORT

constexpr uint16_t I2P_SAM31_PORT {0}
staticconstexpr

SAM 3.1 and earlier do not support specifying ports and force the port to 0.

Definition at line 104 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 76 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 61 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 68 of file netaddress.h.