Generic network address. More...
#include <wipal/tool/addr.hh>
Public Member Functions | |
addr () | |
addr (const void *a) | |
addr (const std::string &) | |
addr (std::istream &) | |
std::istream & | read (std::istream &) |
void | dump (void *) const |
size_t | size () const |
Comparison operators | |
bool | operator< (const addr &) const |
bool | operator== (const addr &) const |
bool | operator!= (const addr &) const |
Address' bytes access | |
ValueType & | operator[] (unsigned) |
const ValueType & | operator[] (unsigned) const |
Static Public Member Functions | |
static const addr & | null () |
static const addr & | broadcast () |
Generic network address.
Protocol-agnostic network address, considered as a sequence of N
values of type ValueType
. For instance, IPv4 addresses are 4 uint8_t, MAC addresses are 6 uint8_t, and IPv6 addresses are 8 uint16_t. HexNotation
indicates whether the address' string representation uses hexadecimal or decimal values. SepNotation
is the character one should use to separate bytes in the string representation.
wpl::tool::addr< VT, N, HN, SN >::addr | ( | const void * | a | ) | [inline] |
Construct an address from a memory location.
An alternative to using this constructor is to static_cast
the memory location:
typedef addr< // ... > addr_t; void* p = // To some memory containing an address. std::cout << *static_cast<addr_t*> (p) << std::endl;
wpl::tool::addr< VT, N, HN, SN >::addr | ( | const std::string & | str | ) | [inline] |
Construct an address from a string representation.
Example:
addr<uint8_t, 6, true, ':'> mac (std::string ("00:16:ec:92:84:b8")); addr<uint8_t, 4, false, '.'> ip4 (std::string ("192.168.1.1"));
wpl::tool::addr< VT, N, HN, SN >::addr | ( | std::istream & | is | ) | [inline] |
Construct an address from a stream (the address appears in the stream as a string representation).
addr<uint8_t, 6, true, ':'> a (std::cin); // E.g. with 00:16:ec:92:84:b8 // on standard input.
size_t wpl::tool::addr< VT, N, HN, SN >::size | ( | ) | const [inline] |
Return the size of an address.
Return the size of an address, i.e.:
N * sizeof (ValueType)