c - 如何查找是否设置了 MORE FRAGMENTS 字段?

标签 c network-programming header protocols packet-sniffers

给定这个 header ,我如何找到是否设置了 MORE FRAGMENTS 字段..

struct sniff_ip {
        u_char  ip_vhl;                 /* version << 4 | header length >> 2 */
        u_char  ip_tos;                 /* type of service */
        u_short ip_len;                 /* total length */
        u_short ip_id;                  /* identification */
        u_short ip_off;                 /* fragment offset field */
        #define IP_RF 0x8000            /* reserved fragment flag */
        #define IP_DF 0x4000            /* dont fragment flag */
        #define IP_MF 0x2000            /* more fragments flag */
        #define IP_OFFMASK 0x1fff       /* mask for fragmenting bits */
        u_char  ip_ttl;                 /* time to live */
        u_char  ip_p;                   /* protocol */
        u_short ip_sum;                 /* checksum */
        struct  in_addr ip_src,ip_dst;  /* source and dest address */
};

最佳答案

struct sniff_ip ip_hdr; 
...
if(ip_hdr.ip_off & IP_MF) {
  //more fragments bit is set.
}

关于c - 如何查找是否设置了 MORE FRAGMENTS 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2124214/

相关文章:

c++ - C++1y 模式下的 Clang >= 3.3 无法解析 <cstdio> header

c - Postgres API 的可为空列

c - 如何在C中使函数返回二维整数点

c++ - 如何在同步 Dart native 扩展中处理对于 uint64_t 来说太大的整数?

python - 在本地局域网中看不到页面

c# - asp.net 中的 GridView 标题文本

php - 从 HTTP 到 HTTPS 的安全重定向

c - 这两个指针声明有什么区别?

c - 为什么在未设置 DBUS_SESSION_BUS_ADDRESS 时 g_file_copy 返回 Operation not supported

c - 删除 skb 或扩展传出 skb