LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to extract payload from struct ip *pip (https://www.linuxquestions.org/questions/programming-9/how-to-extract-payload-from-struct-ip-%2Apip-586184/)

ahm_irf 09-20-2007 05:28 PM

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.

jdiggitydogg 09-22-2007 03:54 AM

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 ));


All times are GMT -5. The time now is 02:58 AM.