30#ifndef TINS_HWADDRESS_H
31#define TINS_HWADDRESS_H
37#include <tins/cxxstd.h>
38#include <tins/macros.h>
51TINS_API std::string hw_address_to_string(
const uint8_t* ptr,
size_t count);
53TINS_API
void string_to_hw_address(
const std::string& hw_addr, uint8_t* output,
56TINS_API
bool hw_address_equal_compare(
const uint8_t* start1,
const uint8_t* end1,
57 const uint8_t* start2);
59TINS_API
bool hw_address_lt_compare(
const uint8_t* start1,
const uint8_t* end1,
60 const uint8_t* start2,
const uint8_t* end2);
62TINS_API
bool hw_address_gt_compare(
const uint8_t* start1,
const uint8_t* end1,
63 const uint8_t* start2,
const uint8_t* end2);
155 Internals::string_to_hw_address(address, buffer_, n);
173 Internals::string_to_hw_address(address, buffer_, n);
190 size_t copy_threshold = i < n ? i : n;
191 for (
size_t index = 0; index < n; ++index) {
192 if (index < copy_threshold) {
193 buffer_[index] = rhs[index];
249 return Internals::hw_address_equal_compare(
begin(),
end(), rhs.begin());
260 return !(*
this == rhs);
271 return Internals::hw_address_lt_compare(
begin(),
end(), rhs.begin(), rhs.end());
293 return Internals::hw_address_gt_compare(
begin(),
end(), rhs.begin(), rhs.end());
315 for (
size_t i = 0; i < n; ++i) {
316 output[i] = output[i] & mask[i];
329 for (
size_t i = 0; i < n; ++i) {
330 output[i] = output[i] | mask[i];
341 for (
size_t i = 0; i < n; ++i) {
342 output[i] = ~output[i];
367 return (*
begin() & 0x01);
383 return Internals::hw_address_to_string(buffer_,
size());
412 return os << addr.to_string();
430 template<
typename OutputIterator>
431 OutputIterator
copy(OutputIterator output)
const {
441 for (
size_t i = 0; i < n; ++i) {
460struct hash<
Tins::HWAddress<n>> {
462 return std::hash<std::string>()(addr.
to_string());
Represents a hardware address.
Definition resolve_utils.h:43
const_iterator end() const
Retrieves a const iterator pointing one-past-the-end of the address.
Definition hw_address.h:237
iterator end()
Retrieves an iterator pointing one-past-the-end of the address.
Definition hw_address.h:227
bool is_multicast() const
Indicates whether this is a multicast address.
Definition hw_address.h:366
const storage_type * const_iterator
Const iterator type.
Definition hw_address.h:106
OutputIterator copy(OutputIterator output) const
Helper function which copies the address into an output iterator.
Definition hw_address.h:431
bool operator>(const HWAddress &rhs) const
Compares this HWAddress for greater-than inequality.
Definition hw_address.h:292
static const size_t address_size
Non-member constant indicating the amount of storage_type elements in this address.
Definition hw_address.h:112
bool operator>=(const HWAddress &rhs) const
Compares this HWAddress for greater-than equality.
Definition hw_address.h:303
bool operator==(const HWAddress &rhs) const
Compares this HWAddress for equality.
Definition hw_address.h:248
const_iterator begin() const
Retrieves a const iterator pointing to the begining of the address.
Definition hw_address.h:217
bool operator<=(const HWAddress &rhs) const
Compares this HWAddress for less-than equality.
Definition hw_address.h:281
friend std::ostream & operator<<(std::ostream &os, const HWAddress &addr)
Writes this HWAddress in hex-notation to a std::ostream.
Definition hw_address.h:411
HWAddress operator|(const HWAddress &mask) const
Apply a mask to this address.
Definition hw_address.h:327
bool is_broadcast() const
Indicates whether this is a broadcast address.
Definition hw_address.h:359
bool is_unicast() const
Indicates whether this is an unicast address.
Definition hw_address.h:373
bool operator!=(const HWAddress &rhs) const
Compares this HWAddress for in-equality.
Definition hw_address.h:259
uint8_t storage_type
The type of the elements stored in the hardware address.
Definition hw_address.h:96
size_t size() const
Retrieves the size of this address.
Definition hw_address.h:352
HWAddress operator~() const
not operator
Definition hw_address.h:339
HWAddress operator&(const HWAddress &mask) const
Apply a mask to this address.
Definition hw_address.h:313
storage_type * iterator
The random access iterator type.
Definition hw_address.h:101
std::string to_string() const
Convert this address to a hex-notation std::string address.
Definition hw_address.h:382
bool operator<(const HWAddress &rhs) const
Compares this HWAddress for less-than inequality.
Definition hw_address.h:270
HWAddress(const HWAddress< i > &rhs)
Copy construct from a HWAddress of length i.
Definition hw_address.h:189
storage_type operator[](size_t i) const
Retrieves the i-th storage_type in this address.
Definition hw_address.h:391
iterator begin()
Retrieves an iterator pointing to the begining of the address.
Definition hw_address.h:207
storage_type & operator[](size_t i)
Retrieves the i-th storage_type in this address.
Definition hw_address.h:400
HWAddress(const char(&address)[i])
Overload provided basically for string literals.
Definition hw_address.h:172
HWAddress(const storage_type *ptr=0)
Constructor from a const storage_type*.
Definition hw_address.h:134
static const HWAddress< n > broadcast
The broadcast address.
Definition hw_address.h:117
HWAddress(const std::string &address)
Constructs an address from a hex-notation address.
Definition hw_address.h:154
The Tins namespace.
Definition address_range.h:38