There are several threads about how to convert the ip-adresses in struct iphdr
to strings (like 127.0.0.1
) with the same method, for example:
Convert source IP address from struct iphdr* to string equivalent using Linux netfilter
But somehow they aren't working for me:
char daddr_str[16];
struct iphdr *iph = (struct iphdr*)(buf);
snprintf(daddr_str, sizeof(daddr_str), "%pI4", &iph->daddr);
printf("IP: %s\n", daddr_str);
And I get:
IP: 0x7f5870621020I
Any ideas what I did wrong?