[Click] how to get the source ip address and destination ip address ?

Beyers Cronje bcronje at gmail.com
Wed Aug 12 11:49:40 EDT 2009


Hi,

You can access an IP packet's source/destination addresses by accessing the
IP header directly:

click_ip *iph = p->ip_header();
uint32_t src = ntohl(iph->ip_src.s_addr);
uint32_t dst = ntohl(iph->ip_dst.s_addr);

See  click/include/clicknet/ip.h

Note before you can you p->ip_header() you have to filter for IP packets AND
set the IP Header annotation using MarkIPHeader of CheckIPHeader elements as
per configuration examples.

Beyers


On Wed, Aug 12, 2009 at 4:50 PM, 束传军 <shuchuanjun at gmail.com> wrote:

> I want to get the both source ip address and destination ip address from a
> packet received from FromDevice in click router? It is possible to do it
> using the Annotaions of a Packet or another possible method? I have tried
> to
> study the struct of the Anno, but unfortunately I failed to find anything
> that can help me except that I got to know that it has 48-byte size ! So, I
> turn to the click mail list, hoping that sombody can help me!
> PS: I want to get both IPv4 and IPv6 addresses. And I am afraid that it
> needs diferent jobs to get the two different types of ip addresses.
> Best Regards!
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>


More information about the click mailing list