#pragma once #include #include #include #include "eth.h" #include "ipv4.h" #include "span_writer.h" namespace icmp { struct __attribute__((packed)) echo { uint8_t type; uint8_t code; uint16_t checksum; uint16_t id; uint16_t seq; }; static_assert(sizeof(echo) == 8); void handle(std::span frame, span_writer& tx, eth::mac_addr our_mac, ipv4::ip4_addr our_ip, std::function)> send_raw); template void prepend_echo_request(Buf& buf, eth::mac_addr src_mac, ipv4::ip4_addr src_ip, eth::mac_addr dst_mac, ipv4::ip4_addr dst_ip, uint16_t id, uint16_t seq) { auto* e = buf.template prepend(); e->type = 8; e->code = 0; e->checksum = 0; e->id = id; e->seq = seq; e->checksum = ipv4::checksum(e, sizeof(echo)); ipv4::prepend(buf, dst_mac, src_mac, src_ip, dst_ip, 1, sizeof(echo)); } bool parse_echo_reply(std::span frame, ipv4::ip4_addr& src_ip, uint16_t expected_id); } // namespace icmp