48using MacAddress = std::array<std::uint8_t, macAddressLength>;
57std::string
Hex4(std::uint16_t value);
62std::string
Hex2(std::uint8_t value);
67std::vector<std::uint8_t>
ToVec(
const std::string& input);
74std::string
HexFallback(
const char* widthPrefix, std::uint32_t value,
int digitWidth);
96std::string
ToHex(
const std::uint8_t* data, std::size_t len);
101std::string
ToHex(
const std::vector<std::uint8_t>& data);
118std::string
Mac2String(
const std::uint8_t* macBytes, std::size_t len);
124std::string
String2Ip(std::span<const std::uint8_t> ipBytes);
131std::string
String2Ip(
const std::uint8_t* ipBytes, std::size_t len);
137std::array<std::uint8_t, 4>
Ip2String(
const std::string& ipStr);
143std::string
DecodeBytes(
const std::uint8_t* data, std::size_t len);
148std::string
DecodeBytes(
const std::vector<std::uint8_t>& data);
220 static_assert(std::is_integral_v<T>,
"ByteSwap requires an integral type");
221 static_assert(!std::is_same_v<T, bool>,
"ByteSwap does not support bool");
223 using UnsignedT = std::make_unsigned_t<T>;
225 auto input =
static_cast<UnsignedT
>(value);
226 UnsignedT result = 0;
228 for (std::size_t i = 0U; i <
sizeof(T); ++i)
230 result =
static_cast<UnsignedT
>((result << 8U) | (input & 0xFFU));
234 return static_cast<T
>(result);
244[[nodiscard]]
constexpr std::uint8_t
ByteAt(T value, std::size_t index)
246 static_assert(std::is_integral_v<T>,
"ByteAt requires an integral type");
247 static_assert(!std::is_same_v<T, bool>,
"ByteAt does not support bool");
249 using UnsignedT = std::make_unsigned_t<T>;
250 const auto unsignedValue =
static_cast<UnsignedT
>(value);
252 return static_cast<std::uint8_t
>(
253 (unsignedValue >> (index * 8U)) & 0xFFU);
272 :
dieAfter(std::chrono::steady_clock::now() +
273 std::chrono::duration_cast<std::chrono::steady_clock::duration>(seconds))
281 return std::chrono::steady_clock::now() >
dieAfter;
286 [[nodiscard]] std::chrono::duration<double>
Remaining()
const
288 auto rem =
dieAfter - std::chrono::steady_clock::now();
289 auto secs = std::chrono::duration<double>(rem);
290 return secs.count() > 0 ? secs : std::chrono::duration<double>(0);
Provides the MAC address of a network interface.
virtual MacAddress GetMac(const std::string &interface)=0
Get the MAC address of a network interface.
virtual ~IMacAddressProvider()=default
Production implementation of IMacAddressProvider.
MacAddress GetMac(const std::string &interface) override
Get the MAC address of a network interface.
Time-limited-operation helper.
MaxTimeout(std::chrono::duration< double > seconds)
Start a countdown of the given duration.
std::chrono::steady_clock::time_point dieAfter
Time point at which TimedOut() will start returning true.
bool TimedOut() const
Whether the countdown has elapsed.
std::chrono::duration< double > Remaining() const
Time left before the countdown elapses.
std::string Hex2(std::uint8_t value)
Format an 8-bit unsigned integer as a 2-digit hexadecimal string.
constexpr std::uint16_t VLAN_ETHERTYPE
EtherType value identifying an 802.1Q VLAN tag (0x8100).
constexpr int uuidLenght
Constant lenght of a UUID.
MacAddress GetInterfaceMac(const std::string &interface)
Get the MAC address assigned to a network interface.
std::vector< std::uint8_t > ToVec(const std::string &input)
Convert a string into a vector of raw bytes.
std::string String2Ip(std::span< const std::uint8_t > ipBytes)
Format raw IPv4 address bytes as a dotted string.
std::array< std::uint8_t, macAddressLength > MacAddress
A 6-byte Ethernet MAC address.
std::array< std::uint8_t, 4 > Ip2String(const std::string &ipStr)
Parse a dotted-decimal IPv4 address string.
std::filesystem::path GetExecutableDirectory()
Retrieves the absolute directory path of the currently running executable.
constexpr std::uint16_t IP_ETHERTYPE
EtherType value identifying IP frames (0x8000).
constexpr T ByteSwap(T value)
MacAddress String2Mac(const std::string &macStr)
Parse a colon-separated MAC address string.
constexpr std::size_t MAX_ETHERNET_FRAME
Maximum PROFINET Ethernet frame size in bytes (including VLAN tag headroom).
std::size_t SkipVlanTags(std::span< const std::uint8_t > frame) noexcept
Return the byte offset of the real EtherType in a raw Ethernet frame.
constexpr int macAddressLength
Constant lenght of a mac address.
std::string ToHex(const std::uint8_t *data, std::size_t len)
Hex-encode a byte buffer.
constexpr std::uint16_t PROFINET_ETHERTYPE
EtherType value identifying PROFINET frames (0x8892).
std::string Hex4(std::uint16_t value)
Format a 16-bit unsigned integer as a 4-digit hexadecimal string.
std::string HexFallback(const char *widthPrefix, std::uint32_t value, int digitWidth)
Format a hexadecimal string with a custom prefix and dynamic width.
constexpr std::size_t RECEIVE_BUFFER_LENGTH
Receive buffer length.
std::string Mac2String(const MacAddress &mac)
Format a MAC address as a colon-separated string.
std::string DecodeBytes(const std::uint8_t *data, std::size_t len)
Decode bytes to a UTF-8 string, stripping trailing NUL bytes.
constexpr std::uint8_t ByteAt(T value, std::size_t index)
Return one byte from an integral value.