From 0cc1ce7d67cdd87ae771bff0a68997294a822a60 Mon Sep 17 00:00:00 2001 From: Leonard Ossa Date: Tue, 27 Aug 2024 15:42:58 +0200 Subject: [PATCH] addr/macaddr: Refactor to modern C++ Remove unused include directives. Change internal member C-style array to std::arry for better safety. Adjust methods to use std::array. Default constructor. Use std::copy_n algorithm to clearly express intention. Signed-off-by: Leonard Ossa --- openvpn/addr/macaddr.hpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/openvpn/addr/macaddr.hpp b/openvpn/addr/macaddr.hpp index 508fc9005..d9ab073f1 100644 --- a/openvpn/addr/macaddr.hpp +++ b/openvpn/addr/macaddr.hpp @@ -22,11 +22,9 @@ #ifndef OPENVPN_ADDR_MACADDR_H #define OPENVPN_ADDR_MACADDR_H -#include -#include #include +#include -#include #include #include @@ -37,10 +35,7 @@ namespace openvpn { class MACAddr { public: - MACAddr() - { - std::memset(addr_, 0, sizeof(addr_)); - } + MACAddr() = default; MACAddr(const unsigned char *addr) { @@ -49,16 +44,16 @@ class MACAddr void reset(const unsigned char *addr) { - std::memcpy(addr_, addr, sizeof(addr_)); + std::copy_n(addr, addr_.size(), addr_.begin()); } std::string to_string() const { - return render_hex_sep(addr_, sizeof(addr_), ':'); + return render_hex_sep(addr_.data(), addr_.size(), ':'); } private: - unsigned char addr_[6]; + std::array addr_{}; }; OPENVPN_OSTREAM(MACAddr, to_string)