如何检查是否设置了 TCP 结构中的标志? [英] How to check if flag in TCP struct is set?

查看:59
本文介绍了如何检查是否设置了 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 结构中的标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆