LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2007, 05:28 PM   #1
ahm_irf
Member
 
Registered: Feb 2007
Posts: 37

Rep: Reputation: 15
how to extract payload from struct ip *pip


I am writing a module for tcptrace. In that module I need to process payload. TCPTRACE _read function passes
struct ip *pip /* the packet */
as an argument.

how I can extract payload by using struct ip pointer.
 
Old 09-22-2007, 03:54 AM   #2
jdiggitydogg
Member
 
Registered: Sep 2007
Posts: 42

Rep: Reputation: 15
there are multiple ip header structures. see /usr/include/netinet/ip.h for the details. 'struct ip' does not include any ip header options, so make sure that is what you want.

i don't know tcptrace, but in general, this is done through pointer math. for tcp/ip, the ip payload is the tcp header. so here some psuedo code:

struct tcphdr *tcpHdr;
struct ip *ipHdr;

ipHdr = /* some code that allocates memory & reads ip packet into it */

/* start of tcp header is the ip payload */
tcpHdr = (struct tcphdr)(ipHdr + sizeof( struct ip ));
 
  


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
need to extract payload from the tcp packet ahm_irf Programming 1 07-22-2007 06:31 AM
g++ and wrong struct member addresses / struct size misreporting sonajiso Linux - General 5 05-22-2004 10:16 PM
switch statement converting struct char to struct int oceaneyes2 Programming 2 12-10-2003 04:30 PM
using struct type X as pointer in struct X. worldmagic Programming 1 10-28-2003 02:06 PM
Accessing a struct inside struct cxel91a Programming 1 09-17-2003 04:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:11 PM.

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