How to check if flag in TCP struct is set?

房东的猫 提交于 2019-12-31 06:52:06

问题


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 :)


回答1:


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.



来源:https://stackoverflow.com/questions/35388217/how-to-check-if-flag-in-tcp-struct-is-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!