From 6fc8d28368b8de624c7d1e7e42db29bb4dceed96 Mon Sep 17 00:00:00 2001 From: Seiya Nuta Date: Mon, 19 Jun 2023 11:30:50 +0000 Subject: icmp: Handle ICMP packets as IPPROTO_IP on BSD In macOS, as already commented in this source file as well, packets from SOCK_DGRAM + IPPROTO_ICMP sockets include IP header while Linux doesn't not prepend the header. Due to the discrepancy, in macOS, we need to handle received ICMP packets as if they are IP packets so that its IPv4 header gets stripped. As pointed out in review comments, it appears CONFIG_BSD is no longer propagated from QEMU. This patch fixes the issue by detecting BSD (including macOS) by ourselves. --- src/ip_icmp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ip_icmp.c b/src/ip_icmp.c index 6ae523c..755fa3d 100644 --- a/src/ip_icmp.c +++ b/src/ip_icmp.c @@ -34,6 +34,8 @@ #include "slirp.h" #include "ip_icmp.h" +#include + #ifndef WITH_ICMP_ERROR_MSG #define WITH_ICMP_ERROR_MSG 0 #endif @@ -100,7 +102,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen) * isn't possible to detect this difference at runtime, so we must use an * #ifdef to determine if we need to remove the IP header. */ -#ifdef CONFIG_BSD +#if defined(BSD) && !defined(__GNU__) so->so_type = IPPROTO_IP; #else so->so_type = IPPROTO_ICMP; -- cgit v1.1