Thread: Accessing TCP flags in TCP packets on Linux using C !!

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    2

    Accessing TCP flags in TCP packets on Linux using C !!

    Hi to all,

    i would like some help regarding the following:

    I'm trying myself at network programming and I want to access the TCP flags in a TCP packet. I know that in C programming language, the TCP header can be accessed in the following manner:

    Code:
    const struct ethernet_header *ethernet;
    const struct tcp_header *tcp;
    const u_char *packet;
    ethernet = (struct ethernet_header*) (packet)
    tcp = (struct tcp_header*) (packet + size_ethernet + size_ip)
    We kind of skip past the ethernet frame and IP packet headers. But I'm having problems with how to access the TCP flags (SYN, ACK, URG, FIN...).

    Can anyone help me with this? Any help will be very much appreciated.

    Warm regards,
    Visham

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Generally, use bit masking -- something like this.
    Code:
    if ( tcp->th_flags & TH_SYN )
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2
    Many thx for the reply Dave_Sinkula..i'll try it and see how it goes.

    Warm regards,
    Visham

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 11:03 AM
  2. Accessing and editing packets of other applications
    By Inder in forum Linux Programming
    Replies: 1
    Last Post: 09-01-2006, 12:00 PM
  3. Accessing printer & touchscreen in Linux
    By g4j31a5 in forum C++ Programming
    Replies: 5
    Last Post: 08-08-2006, 02:04 AM
  4. establish a connection using TCP and capture the incoming packets
    By shraddha in forum Networking/Device Communication
    Replies: 12
    Last Post: 10-22-2005, 02:15 AM
  5. UDP and TCP packets on port 6112
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 01-19-2004, 11:21 AM