Convert source IP address from struct iphdr* to string equivalent using Linux netfilter
The kernel's family of printf()
functions has a special format specifier for IP-addresses (%pI4
for IPv4-addresses, %pI6
for IPv6).
So with IPv4, you could use something like:
char source[16];
snprintf(source, 16, "%pI4", &ip_header->saddr); // Mind the &!
Or write to dynamically allocated memory.
If you simply want to print debug-output, you can also use printk()
. For the many other features of %p
, see this document.