[Click] inet_ntoa()

Joonwoo Park joonwpark81 at gmail.com
Tue Oct 23 03:54:39 EDT 2007


Hi,

2007/10/23, Kurtis Heimerl <munncha at gmail.com>:
> Hi, I've got a little problem I thought this list might be able to help me
> with.
>
> I've begun modifying LinearIPLookup.cc for my own uses. The first thing I've
> begun doing is printing the IP and port of the incoming packets.
>
> The IP I am able to get in long format via the ip->ip_src.s_addr. I need it
> in dot. The normal way to do this is with the  inet_ntoa() function  in
> either the
> netinet/in.h or arpa/inet.h
> libraries.
>
> However, the inclusion of either causes the element to fail to compile.
> What's the proper way to do this in click?

'printf("%s\n", inet_ntoa(iph->ip_src));' would work just only for userlevel.
(
Please make sure you don't pass one more inet_ntoa's return value to
single printf, it would print nonsensical out
(eg. printf("%s %s\n", inet_ntoa(ip_src), inet_ntoa(ip_dst))
)

IPAddress ipaddr(iph->ip_src.s_addr);
click_chatter("%s", ipaddr.unparse().c_str());
is the way of the click.
It works for all platform.

>
> Another question is about the TCP header. The port I am pulling out seems to
> be nonsensical, at least compared to the ones TCP dump are providing. A
> brief code snippet:
> const click_tcp* tcp = p->tcp_header();
> printf("%d\n", tcp->th_sport);

On the little endian machine, It should be 'printf("%d\n",
ntohs(tcp->th_sport));'

Thanks.

Joonwoo Park

>
> Am I doing anything wrong?
>
> Thanks!
> ****
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>


More information about the click mailing list