aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeiya Nuta <nuta@seiya.me>2023-06-19 11:30:50 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-06-19 11:30:50 +0000
commit6fc8d28368b8de624c7d1e7e42db29bb4dceed96 (patch)
tree2209a9e1338f055e1b1097ae82d2258afe4f56bc
parent26be815b86e8d49add8c9a8b320239b9594ff03d (diff)
downloadslirp-6fc8d28368b8de624c7d1e7e42db29bb4dceed96.zip
slirp-6fc8d28368b8de624c7d1e7e42db29bb4dceed96.tar.gz
slirp-6fc8d28368b8de624c7d1e7e42db29bb4dceed96.tar.bz2
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.
-rw-r--r--src/ip_icmp.c4
1 files changed, 3 insertions, 1 deletions
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 <sys/param.h>
+
#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;