LIBWIRE
Next-generation C++17 networking library.
|
IPv4/IPv6 address structure. More...
#include <address.hpp>
Public Member Functions | |
address ()=default | |
Uninitialized address value, is_invalid() = true. More... | |
address (const memory_view &) noexcept | |
Construct IP address from raw bytes in network byte order (big endian). More... | |
address (uint8_t, uint8_t, uint8_t, uint8_t) noexcept | |
Construct IPv4 address from 4 bytes in network byte order (big endian). More... | |
address (uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t) noexcept | |
Construct IPv6 address from 16 bytes in network byte order (big endian). More... | |
address (const std::string &text_ip, ip assume_ipver=ip(0)) noexcept(!LIBWIRE_EXCEPTIONS_ENABLED_BOOL) | |
Parse IP address from string. More... | |
bool | is_invalid () const noexcept |
bool | operator!= (const address &) const noexcept |
bool | operator== (const address &) const noexcept |
std::string | to_string () const noexcept |
Convert address object to string representation. More... | |
Public Attributes | |
std::array< uint8_t, 16 > | parts {} |
ip | version = ip(0) |
Static Public Attributes | |
static const address | invalid |
IPv4/IPv6 address structure.
As you expect it can store both IPv6 and IPv4 addresses to make library interface IP-version agnostic as much as possible.
Address stored in as set of unsigned 8-bit numbers in parts array. If IP version is IPv4 then only first 4 elements is used to store 4 corresponding parts of address. For 127.0.0.1 parts array will contain {127, 0, 0, 1, 0, ...}. Remaining bytes will be filled with zeros. If IPv6 address used then all parts will be used as you expect.
If you have some hardcoded address then it's better to specify it using initializer list e.g. {127, 0, 0, 1}. This will avoid runtime overhead of string parsing.
Definition at line 63 of file address.hpp.
|
default |
Uninitialized address value, is_invalid() = true.
|
noexcept |
Construct IP address from raw bytes in network byte order (big endian).
Size of view must be either 4 or 16 bytes.
|
noexcept |
Construct IPv4 address from 4 bytes in network byte order (big endian).
Thus 127.0.0.1 => {127, 0, 0, 1}
|
noexcept |
Construct IPv6 address from 16 bytes in network byte order (big endian).
Thus ::1 => {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1}
Parse IP address from string.
supports both IPv4 and IPv6, use version member variable to determine address version.
If exceptions are enabled - will throw std::invalid_argument, otherwise constructed address will have is_invalid() = true.
assume_ipver can be used to accept only one IP version (only IPv4 addresses or only IPv6).
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
Convert address object to string representation.
For IPv6 it gives correctly compacted version.
|
static |
Definition at line 125 of file address.hpp.
std::array<uint8_t, 16> libwire::address::parts {} |
Definition at line 123 of file address.hpp.
Definition at line 122 of file address.hpp.