I am writing a kernel module which registers a netfilter hook. I am trying to get the ip address of the caller by using the sk_buff->saddr member. Is there a way I can get the IP in human readable i.e. x.x.x.x format?
I found the function inet_ntop() but it doesn’t seem to be available in kernel headers. How do I convert \xC0\xA8\x00\x01 to 192.168.0.1 ?
There are two macros defined in include/linux/kernel.h
NIPQUAD for ipv4 addresses and NIP6 for ipv6 addresses.
There are ample examples in the kernel sources that make use of these to print ip addresses in human-readable format. For instance:
Hope this helps.