Add dlogf printf formatting, ipv4::to_string helper, clean up string building

This commit is contained in:
Ian Gulliver
2026-04-11 08:21:59 +09:00
parent c35c1de76a
commit 3a3c5873c3
5 changed files with 32 additions and 7 deletions

View File

@@ -1,8 +1,10 @@
#pragma once
#include <array>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <span>
#include <string>
#include "eth.h"
#include "span_writer.h"
@@ -10,6 +12,12 @@ namespace ipv4 {
using ip4_addr = std::array<uint8_t, 4>;
inline std::string to_string(const ip4_addr& ip) {
char buf[16];
snprintf(buf, sizeof(buf), "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
return buf;
}
struct __attribute__((packed)) header {
eth::header eth;
uint8_t ver_ihl;