本文介绍了如何检查是否设置了 TCP 结构中的标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 pcap C 库来读取数据包.目前,我使用以下方法检查并查看 struct tcphdr(此结构在 netinet/tcp.h 库中定义)中的标志是否已设置:>
I'm using the pcap C library to read packets. Currently, I use the following to check and see whether a flag in the struct tcphdr (this struct is defined in the netinet/tcp.h library) is set:
struct tcphdr *tcp = .... if(tcp->th_flags & TH_SYN) { //SYN FLAG IS SET? }这是否总是适用于检查结构中是否设置了特定标志?或者,还有更好的方法?非常感谢任何建议/提示:)
Will this always work for checking if a particular flag is set in the struct? Or is there a better way? Would greatly appreciate any advice/tips :)
推荐答案这对我来说很好.TH_SYN 是单个位,因此如果在 th_flags 中设置了该位,则表达式将为真(非零).
That looks fine to me. TH_SYN is a single bit, so that expression will be true (nonzero) if that bit is set in th_flags.
更多推荐
如何检查是否设置了 TCP 结构中的标志?
发布评论