OpenVPN 3 Core Library
Loading...
Searching...
No Matches
macaddr.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_ADDR_MACADDR_H
13#define OPENVPN_ADDR_MACADDR_H
14
15#include <string>
16#include <array>
17
20
21namespace openvpn {
22
23// Fundamental class for representing an ethernet MAC address.
24
26{
27 public:
28 MACAddr() = default;
29
30 MACAddr(const unsigned char *addr)
31 {
32 reset(addr);
33 }
34
35 void reset(const unsigned char *addr)
36 {
37 std::copy_n(addr, addr_.size(), addr_.begin());
38 }
39
40 std::string to_string() const
41 {
42 return render_hex_sep(addr_.data(), addr_.size(), ':');
43 }
44
45 private:
46 std::array<unsigned char, 6> addr_{};
47};
48
49OPENVPN_OSTREAM(MACAddr, to_string)
50
51} // namespace openvpn
52
53#endif // OPENVPN_ADDR_MACADDR_H
std::array< unsigned char, 6 > addr_
Definition macaddr.hpp:46
MACAddr(const unsigned char *addr)
Definition macaddr.hpp:30
std::string to_string() const
Definition macaddr.hpp:40
void reset(const unsigned char *addr)
Definition macaddr.hpp:35
MACAddr()=default
std::string render_hex_sep(const unsigned char *data, size_t size, const char sep, const bool caps=false)
Definition hexstr.hpp:180
#define OPENVPN_OSTREAM(TYPE, METH)
Definition ostream.hpp:21