[Click] Accessing port values from header
Michael Gellman
m.gellman at imperial.ac.uk
Thu Apr 6 13:33:42 EDT 2006
On Thu, 2006-04-06 at 18:03 +0100, Daniel Braund wrote:
> Hi. I am running in circles trying to figure out how to extract the port value
> for a packet in a similar manner to the way I extract a packets source and
> destination addresses:
>
> packet_src=iph->ip_src.s_addr;
> packet_dst=iph->ip_dst.s_addr;
>
> essentially I want to know if I can do something like
>
> packet_port=iph->ip_dst.port;
>
IP Headers don't have ports -- but TCP and UDP headers do. For UDP, you
would access the ports of a Packet p using:
p->udp_header()->uh_sport
p->udp_header()->uh_dport
assuming the transport header has been set in the packet.
> I have looked, but cannot find a list or description of what values I can plug
> into here to gain the data I want. Does one exist somewhere? Also, s_addr I
> assume implies string, is there a binary/hex variant?
s_addr is a 32-bit integer. It is the only member of the in_addr struct
which is defined in <linux/in.h> under Linux.
Michael Gellman
--
Intelligent Systems & Networks Group
Dept of Electrical & Electronic Engineering
Imperial College London
London SW7 2BT
More information about the click
mailing list