Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 19:26

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: tcp format/checksum?
PostPosted: 19 Apr 2008 15:30 

Joined: 19 Apr 2008 00:59
Posts: 42
I see on the site you have the information on udp packets. The format/checksum. But what about tcp? I have googled and googled and can't find anything on tcp. I can find some on tcp format but everyone i find is different from the last.


Top
 Profile  
 
 
 Post subject:
PostPosted: 19 Apr 2008 17:30 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
I think to have understood about what you refer, the RFC 793 should have anything you need to know.

A good help about the format of the TCP packets can come also from Wireshark or any other sniffer which shows you all the fields.

The following code should give you an "idea" of the format and the usage:
Code:
typedef struct {
    uint16_t    source;
    uint16_t    dest;
    uint32_t    seq;
    uint32_t    ack_seq;
    uint8_t     doff;
    uint8_t     flags;
    uint16_t    window;
    uint16_t    check;
    uint16_t    urg_ptr;
} tcph;

    tcp.source  = htons(src_port);
    tcp.dest    = htons(dst_port);
    tcp.seq     = htonl(*seq1);
    tcp.ack_seq = htonl(*ack1);
    tcp.doff    = sizeof(tcph) << 2;
    tcp.flags   = TH_SYN;
    tcp.window  = htons(65535);
    tcp.check   = htons(0);
    tcp.urg_ptr = htons(0);
    // now calculate the checksum


If you have doubts about specific fields post here.


Top
 Profile  
 
 Post subject:
PostPosted: 19 Apr 2008 17:36 

Joined: 19 Apr 2008 00:59
Posts: 42
Well how do you preform the checksum?

Also if I were to convert the struct to bytes I would just stick data after it?


http://www.faqs.org/rfcs/rfc793.html
I guess I got some reading to do.


Top
 Profile  
 
 Post subject:
PostPosted: 19 Apr 2008 19:08 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
the attached code will solve any doubt you have about building TCP packets (included the option field which is just all the additional data between the TCP structure and the data) and calculating the checksum


Attachments:
tcpcksumcrc.c [2.83 KiB]
Downloaded 93 times


Last edited by aluigi on 25 Apr 2008 13:31, edited 1 time in total.
Top
 Profile  
 
 Post subject:
PostPosted: 19 Apr 2008 19:13 

Joined: 19 Apr 2008 00:59
Posts: 42
aluigi wrote:
the attached code will solve any doubt you have about building TCP packets (included the option TCP field) and calculating the checksum


Thank you very much, exactly what I wanted :D.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron