Re: Infering Packet Type

From: Joe Eykholt
Date: Sun Nov 09 2008 - 12:42:25 EST


"G" wrote:
Hi

I have developed a kernel module which receives packet from the linux
kernel. It receives by adding a hook in the netif_recieve_skb()
function. My kernel module which receives the packet is an IP packet.
How do i get to know whether its a TCP packet or UDP packet. There are
separate headers for TCP and UDP processing but how do i typecast the
skb to tcp or udp. or rather how do i know to which header should i
typecast the socket buffer to. Which field says that its a TCP packet
or UDP packet ?

Cheers,
Balaji
--
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html

Look at the IP header protocol field. If it is IPPROTO_TCP (6) it's TCP, if it's IPPROTO_UDP (17), it's UDP, etc. I assume you already
know it's an IP packet and not ARP or IPv6 or something else.

There are several issues your question brings up, such as how you added your hook, whether you used the dev_add_pack() interface or did it some new way.

This is a pretty basic question to ask this large list. You should use some reference book like Stevens to get familiar with the IP protocol before digging into the higher layers.

Joe
--
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html