|
Botan 3.12.0
Crypto and TLS for C&
|
#include <ipv4_address.h>
Public Member Functions | |
| const IPv4Address & | address () const |
| The network address (host bits already zeroed). | |
| bool | contains (const IPv4Address &ip) const |
True iff ip falls within this subnet. | |
| IPv4Subnet (IPv4Address address, size_t prefix_length) | |
| bool | is_host () const |
| True iff prefix_length() == 32. | |
| size_t | prefix_length () const |
| Prefix length in [0, 32]. | |
| std::vector< uint8_t > | serialize () const |
| std::string | to_string () const |
| CIDR-style "10.0.0.0/8". | |
Static Public Member Functions | |
| static std::optional< IPv4Subnet > | from_address_and_mask (std::span< const uint8_t, 8 > addr_and_mask) |
| static std::optional< IPv4Subnet > | from_address_and_mask (uint32_t addr, uint32_t mask) |
| static std::optional< IPv4Subnet > | from_string (std::string_view str) |
| static IPv4Subnet | host (IPv4Address address) |
Friends | |
| bool | operator== (const IPv4Subnet &, const IPv4Subnet &)=default |
An IPv4 subnet in CIDR form: a network address paired with a prefix length
Definition at line 65 of file ipv4_address.h.
| Botan::IPv4Subnet::IPv4Subnet | ( | IPv4Address | address, |
| size_t | prefix_length ) |
Construct from a network address and a prefix length in [0, 32]. Host bits of address are cleared.
Throws Invalid_Argument if prefix_length > 32.
Definition at line 54 of file ipv4_address.cpp.
References address(), and prefix_length().
Referenced by from_address_and_mask(), from_string(), host(), and operator==.
|
inline |
The network address (host bits already zeroed).
Definition at line 103 of file ipv4_address.h.
Referenced by host(), and IPv4Subnet().
| bool Botan::IPv4Subnet::contains | ( | const IPv4Address & | ip | ) | const |
True iff ip falls within this subnet.
Definition at line 110 of file ipv4_address.cpp.
References Botan::IPv4Address::netmask().
|
static |
Construct from a network address and a netmask (4 bytes each) Returns nullopt if netmask is not a valid contiguous CIDR prefix.
Definition at line 69 of file ipv4_address.cpp.
References IPv4Subnet(), Botan::load_be(), and Botan::IPv4Address::prefix_length().
Referenced by Botan::GeneralName::decode_from(), from_address_and_mask(), and Botan::GeneralName::ipv4_address().
|
static |
Construct from a network address and a netmask (4 bytes each) Returns nullopt if netmask is not a valid contiguous CIDR prefix.
Definition at line 61 of file ipv4_address.cpp.
References from_address_and_mask(), and Botan::store_be().
|
static |
Parse CIDR-style form "10.0.0.0/8".
The "/N" suffix is required: bare addresses should be parsed via IPv4Address::from_string and wrapped with IPv4Subnet::host if needed.
Returns nullopt on parse failure or out-of-range prefix length.
Definition at line 81 of file ipv4_address.cpp.
References Botan::IPv4Address::from_string(), and IPv4Subnet().
|
inlinestatic |
A single-host subnet (prefix length 32) covering exactly address.
Definition at line 100 of file ipv4_address.h.
References address(), and IPv4Subnet().
Referenced by Botan::GeneralName::ipv4_address().
|
inline |
True iff prefix_length() == 32.
Definition at line 109 of file ipv4_address.h.
Referenced by serialize().
|
inline |
Prefix length in [0, 32].
Definition at line 106 of file ipv4_address.h.
Referenced by IPv4Subnet().
| std::vector< uint8_t > Botan::IPv4Subnet::serialize | ( | ) | const |
Bytes for use in a DER-encoded GeneralName iPAddress field:
Definition at line 118 of file ipv4_address.cpp.
References is_host(), Botan::IPv4Address::netmask(), and Botan::store_be().
| std::string Botan::IPv4Subnet::to_string | ( | ) | const |
CIDR-style "10.0.0.0/8".
Definition at line 114 of file ipv4_address.cpp.
References Botan::fmt().
|
friend |
References IPv4Subnet().