initial commit

This commit is contained in:
faraphel 2024-12-22 23:05:52 +01:00
commit 811f80c92c
17 changed files with 549 additions and 0 deletions

28
source/utils/address.cpp Normal file
View file

@ -0,0 +1,28 @@
#include "address.hpp"
#include <iomanip>
#include <ios>
namespace utils::address {
constexpr size_t MAC_ADDRESS_LENGTH = 6;
std::string mac_bytes_to_string(const std::uint8_t address_bytes[MAC_ADDRESS_LENGTH]) {
std::stringstream stream;
// write the mac address as a string
for (std::size_t i = 0; i < MAC_ADDRESS_LENGTH; i++) {
// format the byte
stream << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(address_bytes[i]);
// unless this is the last byte, add a separator
if (i < MAC_ADDRESS_LENGTH - 1) stream << ":";
}
return stream.str();
}
}

13
source/utils/address.hpp Normal file
View file

@ -0,0 +1,13 @@
#pragma once
#include <string>
#include <cstdint>
namespace utils::address {
std::string mac_bytes_to_string(const std::uint8_t address_bytes[6]);
}