Subject: Re: Is there any function similar to inet_ntoa() in Kernel or NetFilter ?

From: Roar Bjørgum Rotvik <[email-masked]>
Date: Thu, 20 Nov 2008 10:34:18 +0100

Kunsheng Chen wrote:
> Hello, everyone,
> 
> I am doing a project similar to iptable using netfilter, currently I want to convert a IP address from 'long int' back to dotted address.
> 
> I don't know whether there is some functions inside kernel or netfilter that could make that like using inet_ntoa() in <arpa/inet.h>

How about NIPQUAD and NIPQUAD_FMT (for IPv4):
http://lxr.linux.no/linux+v2.6.27.6/include/linux/kernel.h#L324
http://lxr.linux.no/linux+v2.6.27.6/include/linux/kernel.h#L319

Example on how to use:
http://lxr.linux.no/linux+v2.6.27.6/net/ipv4/ipconfig.c#L1184

printk("my address is " NIPQUAD_FMT "\n", NIPQUAD(ic_myaddr));

-- 
Roar Bjørgum Rotvik