From 778011dac60d87446940c4ae183b7eb00d818e50 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 31 Oct 2020 11:38:00 +0100 Subject: [PATCH] ping: Account for raw sockets now receiving IPv4 headers --- Userland/ping.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Userland/ping.cpp b/Userland/ping.cpp index d8248cb094..bbe7282665 100644 --- a/Userland/ping.cpp +++ b/Userland/ping.cpp @@ -114,11 +114,17 @@ int main(int argc, char** argv) char msg[64 - sizeof(struct icmphdr)]; }; + struct PongPacket { + // FIXME: IPv4 headers are not actually fixed-size, handle other sizes. + char ip_header[20]; + struct icmphdr header; + char msg[64 - sizeof(struct icmphdr)]; + }; + uint16_t seq = 1; for (;;) { PingPacket ping_packet; - PingPacket pong_packet; memset(&ping_packet, 0, sizeof(PingPacket)); ping_packet.header.type = 8; // Echo request @@ -142,8 +148,9 @@ int main(int argc, char** argv) } for (;;) { + PongPacket pong_packet; socklen_t peer_address_size = sizeof(peer_address); - rc = recvfrom(fd, &pong_packet, sizeof(PingPacket), 0, (struct sockaddr*)&peer_address, &peer_address_size); + rc = recvfrom(fd, &pong_packet, sizeof(PongPacket), 0, (struct sockaddr*)&peer_address, &peer_address_size); if (rc < 0) { if (errno == EAGAIN) { printf("Request (seq=%u) timed out.\n", ntohs(ping_packet.header.un.echo.sequence));