Thread: packet analyzer in c

  1. #16
    Registered User
    Join Date
    Jul 2004
    Posts
    14
    Hay,
    I am still looking around for help. Thax alot for the good work from Sang-drax

    Now, I have :
    u_long SEQ_N // sequence # in a tcp header
    I need to extract that from the tcp header having known the packet pointer tcp_ptr;

    This is my code :
    Code:
    SEQ_N=*tcp_ptr <<8 //extract the 1st byte.
    *tcp_ptr ++; // goto next byte.
    SEQ_N=SEQ_N | *tcp_ptr;
    *tcp_ptr++; // 3rd byte.
    SEQ_N=SEQ_N | *tcp_ptr;
    *tcp_ptr++; // 4th byte
    SEQ_N = SEQ_N | *tcp_ptr;
    ...
    ...
    ..
    Well, I am not sure if this would work! Have I done right ? would any one follow the code and tell me if I got the SEQ_N value right ?!1

    Apreciated and kind of help.


    Ahmed.

  2. #17
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Assuming tcp_ptr points to the first byte of the sequence number (first in the TCP package is the port numbers):
    Code:
    SEQ_N=*tcp_ptr;//extract the 1st byte.
    *tcp_ptr ++; // goto next byte.
    SEQ_N|= *tcp_ptr << 8;
    *tcp_ptr++; // 3rd byte.
    SEQ_N|= *tcp_ptr << 16;
    *tcp_ptr++; // 4th byte
    SEQ_N |= *tcp_ptr << 24;
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Packet processing in Socket programming, please help
    By pumpkin in forum Networking/Device Communication
    Replies: 5
    Last Post: 05-28-2009, 01:33 AM
  2. Replies: 4
    Last Post: 05-05-2009, 05:35 AM
  3. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  4. Raw Packet (sorry tripple weird Post)
    By Coder87C in forum Networking/Device Communication
    Replies: 6
    Last Post: 03-04-2006, 11:34 AM
  5. packet analyzer in c
    By althagafi in forum C Programming
    Replies: 1
    Last Post: 07-26-2004, 11:46 PM