Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to print "SYN flag" if TCP SYN packets arrived. And how to do it?

/**************************************/
C++
if(((ip->ip_p)==IPPROTO_TCP)==TH_SYN)
{
printf("SYN flag")
}


I wrote above.. But it's not working.
/**************************************/
It's the TCP header in C.

CSS
typedef u_int tcp_seq;

struct sniff_tcp {
        u_short th_sport;               /* source port */
        u_short th_dport;               /* destination port */
        tcp_seq th_seq;                 /* sequence number */
        tcp_seq th_ack;                 /* acknowledgement number */
        u_char  th_offx2;               /* data offset, rsvd */
#define TH_OFF(th)      (((th)->th_offx2 & 0xf0) >> 4)
        u_char  th_flags;
        #define TH_FIN  0x01
        #define TH_SYN  0x02
        #define TH_RST  0x04
        #define TH_PUSH 0x08
        #define TH_ACK  0x10
        #define TH_URG  0x20
        #define TH_ECE  0x40
        #define TH_CWR  0x80
        #define TH_FLAGS        (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
        u_short th_win;                 /* window */
        u_short th_sum;                 /* checksum */
        u_short th_urp;                 /* urgent pointer */

};


Help me please.. :))
Posted

1 solution

You need to check a separate bit, not the whole value. It should be
C++
if ((someValue & TH_SYN) != 0) {
   // then bit is set
}


—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900