如何从c中的TCP头获取SYN标志? [英] How to get SYN flag from TCP header in c?
本文介绍了如何从c中的TCP头获取SYN标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果TCP SYN数据包到达,我想打印SYN标志。怎么做?
/ *************************** *********** /
I want to print "SYN flag" if TCP SYN packets arrived. And how to do it?
/**************************************/
if(((ip->ip_p)==IPPROTO_TCP)==TH_SYN)
{
printf("SYN flag")
}
我上面写的..但它不起作用。
/ ************************************** /
这是C中的TCP标题。
I wrote above.. But it's not working.
/**************************************/
It's the TCP header in C.
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.. :))
推荐答案
您需要检查一个单独的位,而不是整个值。它应该是
You need to check a separate bit, not the whole value. It should be
if ((someValue & TH_SYN) != 0) {
// then bit is set
}
这篇关于如何从c中的TCP头获取SYN标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文