[PATCH 5/9] batctl: tcpdump: print the unreachable host for ICMP port unreachable
Sven Eckelmann <[email protected]> Sun, 05 Jul 2026 19:30:08 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
When decoding an ICMP port-unreachable message, tcpdump prints the
destination of the ICMP repply packet. The actual relevant IP (the original
destination) is only in the inner IP header.
The destinatin IP from the already validated tmp_udphdr must be used
instead.
Fixes: f08a28dcffb1 ("batctl: tcpdump - fix IP header parsing")
Signed-off-by: Sven Eckelmann <[email protected]>
---
tcpdump.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tcpdump.c b/tcpdump.c
index b01581e..c532ad1 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -714,6 +714,7 @@ static void dump_ip(unsigned char *packet_buff, ssize_t buff_len,
int time_printed)
{
static const char ip_string[] = "IP";
+ char ipinner[INET_ADDRSTRLEN];
char ipsrc[INET_ADDRSTRLEN];
char ipdst[INET_ADDRSTRLEN];
struct udphdr *tmp_udphdr;
@@ -770,9 +771,15 @@ static void dump_ip(unsigned char *packet_buff, ssize_t buff_len,
tmp_udphdr = (struct udphdr *)(((char *)tmp_iphdr) + (tmp_iphdr->ihl * 4));
+ if (!inet_ntop(AF_INET, &tmp_iphdr->daddr, ipinner,
+ sizeof(ipinner))) {
+ fprintf(stderr, "Cannot decode unreachable destination IP\n");
+ return;
+ }
+
printf("%s: ICMP ", ipdst);
printf("%s udp port %hu unreachable, length %zu\n",
- ipdst, ntohs(tmp_udphdr->dest),
+ ipinner, ntohs(tmp_udphdr->dest),
(size_t)buff_len - (iphdr->ihl * 4));
break;
default:
--
2.47.3