Add dlogf printf formatting, ipv4::to_string helper, clean up string building
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user