netdev
[Top] [All Lists]

Re: Function to read IP address in dot format

To: linux lover <linux_lover2004@xxxxxxxxx>
Subject: Re: Function to read IP address in dot format
From: Arnaldo Carvalho de Melo <arnaldo.melo@xxxxxxxxx>
Date: Mon, 11 Apr 2005 11:07:46 -0300
Cc: netdev@xxxxxxxxxxx
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=gJzs8WcU7smRlsl1zP5PtyPTsKG37EY5GL88gshXrdrCMZMYd/ZDHYPxS1K8geFUL9V7fIeOi6R7VrKHHWvk9p+IKViU3Rtgbbsph5ztdF9nRj38Dm/shKR6QHam+0vzVSXOl7Q+yuY52N7+beSKP4wkjMo9Gvi5fEn09KR1/vY=
In-reply-to: <20050411060510.12208.qmail@web52201.mail.yahoo.com>
References: <20050411060510.12208.qmail@web52201.mail.yahoo.com>
Reply-to: acme@xxxxxxxxxxxxxxxx
Sender: netdev-bounce@xxxxxxxxxxx
On Apr 11, 2005 3:05 AM, linux lover <linux_lover2004@xxxxxxxxx> wrote:
> 
> Hello,
>           what is the function to read IP address in
> kernel code as human readable dot quad format? IP
> address are unsigned int's in ip.h file as
>         __u32   saddr;
>         __u32   daddr;
>          In ip_build_xmit ip header gets IP addresses
> from rtable struct as
> iph->saddr=rt->rt_src;
> iph->daddr=rt->rt_dst;
>            Now if i want to know to which ip current
> packet is being sent i am using printks but it prints
> iph->saddr in int format not in user readable format.
> how to do that?
> regards,

Use NIPQUAD, as in the example below:

        printk(KERN_DEBUG "dccp rx: packet=%s, "
                          "source=%u.%u.%u.%u@%d, "
                          "dest=%u.%u.%u.%u@%d\n",
               dccp_packet_name(dh->dccph_type),
               NIPQUAD(skb->nh.iph->saddr),
               ntohs(dh->dccph_sport),
               NIPQUAD(skb->nh.iph->daddr),
               ntohs(dh->dccph_dport));

- Arnaldo

<Prev in Thread] Current Thread [Next in Thread>