LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-02-2008, 04:34 AM   #1
iamjayanth
Member
 
Registered: Oct 2008
Posts: 51

Rep: Reputation: 15
tcp_header=(struct tcphdr *)(skbuff->data+(skbuff->nh.iph->ihl*4)); How?


tcp_header=(struct tcphdr *)(skbuff->data+(skbuff->nh.iph->ihl*4));
Means =>data_address + ipheader_length = tcp_header_address
How it's possible???
 
Old 12-02-2008, 11:34 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,642
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
Well, let's take a closer look at each part of this statement:

Code:
tcp_header=(struct tcphdr *)(skbuff->data+(skbuff->nh.iph->ihl*4));
(1) The first part says that you are assigning a value to a variable ("tcp_header"), and that the value which you're assigning is to be interpreted as "a pointer to a structure of type 'tcphdr.' "

(2) The remainder of the statement is the calculation of the address in question.

(3) We know that there must be a pointer-variable "skbuff," which points to a thing which contans (perhaps among other things) a pointer named "data" and a structure named "nh" which contains an element named "iph" which is, in turn, "a pointer to something (else)." Within that structure there's an element called "ihl." We're grabbing that value and multiplying it by 4, then adding it to the value of the "data" pointer.

(4) If it were me, I'd re-write that statement!

But yes... the statement could, and probably does, match your verbal description. If "data" is the location of the start of the buffer, and "nh.iph" points to some kind of table of offsets-and-lengths, then this rather tricky-to-understand statement is probably correct.

Personally, I like statements that are "abundantly clear." Modern compilers are great at generating good code... but "C" programmers are still accustomed to coding for compilers that needed a lot of help. I'd write one, or several, statements to calculate the address ... in a way that is "abundantly clear." The compiler will generate tight and efficient code regardless of how you write it.
 
Old 12-02-2008, 11:52 AM   #3
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
I think your confusing yourself on the data part. what's stored in the skbuff->data section is normally a full packet including an outer layer that is for the link layer (like ethernet) so to get to the tcp packet you need to skip over the the encapsulating layers. The kernel has macros and functions to make it easier to access the various levels like ip_hdr() and skb_header_pointer().
 
Old 12-06-2008, 12:33 AM   #4
iamjayanth
Member
 
Registered: Oct 2008
Posts: 51

Original Poster
Rep: Reputation: 15
But these macros are only for higher version. .. We have to use the above expressions for kernel versions 2.4 .
 
Old 02-25-2011, 04:07 AM   #5
kalloc
LQ Newbie
 
Registered: Feb 2011
Posts: 20

Rep: Reputation: 0
but how to extract application layer data from skbuff in POST ROUTING HOOK

DEar estabroo

WHile i am using a pre-routing hook i can capture data by passing pointer shifted by 52 bytes ( ip + tcp), but while i am in a post routing hook i see the total length of packet as correct, but when i try to access the data the same way as i did in pre routing hook i don't get anything. where does the data sits while packet is going out of machine and how to access that area.
thx

Quote:
Originally Posted by estabroo View Post
I think your confusing yourself on the data part. what's stored in the skbuff->data section is normally a full packet including an outer layer that is for the link layer (like ethernet) so to get to the tcp packet you need to skip over the the encapsulating layers. The kernel has macros and functions to make it easier to access the various levels like ip_hdr() and skb_header_pointer().
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
skbuff shrishailnk Linux - Networking 0 05-11-2006 12:43 AM
about skbuff shrishailnk Linux - Networking 0 05-11-2006 12:31 AM
skbuff venkatesh111 Linux From Scratch 1 03-21-2006 02:44 AM
problem related to skbuff.h shrishailnk Linux - Networking 7 03-20-2006 12:42 PM
Why skbuff.h different for 2.4 and 2.6 kernels? linux_lover2005 Programming 1 03-20-2006 04:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 12:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration