libtins
4.0
|
Represents a hardware address. More...
#include <hw_address.h>
Public Types | |
typedef uint8_t | storage_type |
The type of the elements stored in the hardware address. | |
typedef storage_type * | iterator |
The random access iterator type. | |
typedef const storage_type * | const_iterator |
Const iterator type. | |
Public Member Functions | |
HWAddress (const storage_type *ptr=0) | |
Constructor from a const storage_type*. More... | |
HWAddress (const std::string &address) | |
Constructs an address from a hex-notation address. More... | |
template<size_t i> | |
HWAddress (const char(&address)[i]) | |
Overload provided basically for string literals. More... | |
template<size_t i> | |
HWAddress (const HWAddress< i > &rhs) | |
Copy construct from a HWAddress of length i. More... | |
iterator | begin () |
Retrieves an iterator pointing to the begining of the address. More... | |
const_iterator | begin () const |
Retrieves a const iterator pointing to the begining of the address. More... | |
iterator | end () |
Retrieves an iterator pointing one-past-the-end of the address. More... | |
const_iterator | end () const |
Retrieves a const iterator pointing one-past-the-end of the address. More... | |
bool | operator== (const HWAddress &rhs) const |
Compares this HWAddress for equality. More... | |
bool | operator!= (const HWAddress &rhs) const |
Compares this HWAddress for in-equality. More... | |
bool | operator< (const HWAddress &rhs) const |
Compares this HWAddress for less-than inequality. More... | |
bool | operator<= (const HWAddress &rhs) const |
Compares this HWAddress for less-than equality. More... | |
bool | operator> (const HWAddress &rhs) const |
Compares this HWAddress for greater-than inequality. More... | |
bool | operator>= (const HWAddress &rhs) const |
Compares this HWAddress for greater-than equality. More... | |
HWAddress | operator& (const HWAddress &mask) const |
Apply a mask to this address. More... | |
HWAddress | operator| (const HWAddress &mask) const |
Apply a mask to this address. More... | |
HWAddress | operator~ () const |
not operator More... | |
size_t | size () const |
Retrieves the size of this address. More... | |
bool | is_broadcast () const |
Indicates whether this is a broadcast address. | |
bool | is_multicast () const |
Indicates whether this is a multicast address. | |
bool | is_unicast () const |
Indicates whether this is an unicast address. | |
std::string | to_string () const |
Convert this address to a hex-notation std::string address. More... | |
storage_type | operator[] (size_t i) const |
Retrieves the i-th storage_type in this address. More... | |
storage_type & | operator[] (size_t i) |
Retrieves the i-th storage_type in this address. More... | |
template<typename OutputIterator > | |
OutputIterator | copy (OutputIterator output) const |
Helper function which copies the address into an output iterator. More... | |
Static Public Attributes | |
static const size_t | address_size = n |
Non-member constant indicating the amount of storage_type elements in this address. | |
static const HWAddress< n > | broadcast = make_broadcast_address() |
The broadcast address. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const HWAddress &addr) |
Writes this HWAddress in hex-notation to a std::ostream. More... | |
Represents a hardware address.
This class represents a hardware (MAC) address. It can be constructed from it's string representation and you can iterate over the bytes that compose it.
For example:
|
inline |
Constructor from a const storage_type*.
If no pointer or a null pointer is provided, the address is initialized to 00:00:00:00:00:00.
This constructor is very usefull when passing zero initialized addresses as arguments to other functions. You can use a literal 0, which will be implicitly converted to the empty address.
If a pointer is provided, address_size storage_type elements are copied from the pointer, into the internal address representation.
ptr | The pointer from which to construct this address. |
|
inline |
Constructs an address from a hex-notation address.
This constructor will parse strings in the form:
"00:01:da:fa:..."
And initialize the internal representation accordingly.
address | The hex-notation address to be parsed. |
|
inline |
Overload provided basically for string literals.
This constructor takes a const char array of i elements in hex-notation.
This is mostly used when providing string literals. If this where a const char*, then there would be an ambiguity when providing a null pointer.
address | The array of chars containing the hex-notation cstring to be parsed. |
|
inline |
Copy construct from a HWAddress of length i.
If i is lower or equal than address_size, then i storage_type elements are copied, and the last (n - i) are initialized to the default storage_type value(0 most of the times).
If i is larger than address_size, then only the first address_size elements are copied.
rhs | The HWAddress to be constructed from. |
|
inline |
Retrieves an iterator pointing to the begining of the address.
|
inline |
Retrieves a const iterator pointing to the begining of the address.
|
inline |
Helper function which copies the address into an output iterator.
This is the same as:
std::copy(begin(), end(), iter);
But since some PDUs return a HWAddress<> by value, this function can be used to avoid temporaries.
output | The output iterator in which to store this address. |
|
inline |
Retrieves an iterator pointing one-past-the-end of the address.
|
inline |
Retrieves a const iterator pointing one-past-the-end of the address.
|
inline |
|
inline |
Apply a mask to this address.
mask | The mask to be applied |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Retrieves the i-th storage_type in this address.
i | The element to retrieve. |
|
inline |
Retrieves the i-th storage_type in this address.
i | The element to retrieve. |
|
inline |
Apply a mask to this address.
mask | The mask to be applied |
|
inline |
not operator
|
inline |
Retrieves the size of this address.
This effectively returns the address_size constant.
|
inline |
Convert this address to a hex-notation std::string address.
|
friend |
Writes this HWAddress in hex-notation to a std::ostream.
os | The stream in which to write the address. |
addr | The parameter to be written. |