netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harvey Harrison <harvey.harrison@gmail.com>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: Julius Volz <julius.volz@gmail.com>, netdev@vger.kernel.org
Subject: Re: Is there any function similar to inet_ntoa() in Kernel or NetFilter ?
Date: Mon, 24 Nov 2008 22:01:50 -0800	[thread overview]
Message-ID: <1227592910.5511.38.camel@brick> (raw)
In-Reply-To: <AAF075CA-ECF9-440C-AF33-3845544A284D@oracle.com>

On Mon, 2008-11-24 at 21:03 -0500, Chuck Lever wrote:
> On Nov 21, 2008, at Nov 21, 2008, 6:08 PM, Julius Volz wrote:
> > On Thu, Nov 20, 2008 at 10:34 AM, Roar Bjørgum Rotvik <roarbr@tihlde.org 
> > > wrote:
> >> Kunsheng Chen wrote:
> >>> 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
> >
> > In the latest tree, there are now "%pI4" and "%pI6" format options  
> > for printk.
> >
> > For example:
> >
> > printk(KERN_DEBUG "Address: %pI4\n", &v4_addr);
> 
> I've been watching this with some interest.  Is this API stable now?
> 
> Is there a way to pass a pointer to a sockaddr and get printk() to  
> figure out whether it's is an AF_INET or AF_INET6 address, and display  
> it appropriately?

Nope, they're fixed-format currently.  They are pretty simple format
specifiers at this point.  I'm not sure if adding more dynamic behavior
is a good idea.

> 
> Does it handle IPv6 scope IDs correctly?

Define correctly? ;-)

> 
> Does it convert IPv6 mapped IPv4 addresses to dotted quad automatically?
> 

Nope.

Quick summary:
%pI4 prints 4 decimal separated decimal numbers

%pI6 prints 8 16-bit hex numbers colon-separated 
%pi6 omits the colons.

Harvey


  reply	other threads:[~2008-11-25  6:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-20  0:03 Is there any function similar to inet_ntoa() in Kernel or NetFilter ? Kunsheng Chen
2008-11-20  9:34 ` Roar Bjørgum Rotvik
2008-11-21 23:08   ` Julius Volz
2008-11-25  2:03     ` Chuck Lever
2008-11-25  6:01       ` Harvey Harrison [this message]
2008-11-25 16:44         ` Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1227592910.5511.38.camel@brick \
    --to=harvey.harrison@gmail.com \
    --cc=chuck.lever@oracle.com \
    --cc=julius.volz@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).