【问题标题】:How to find whether the MORE FRAGMENTS field is set or no?如何查找是否设置了 MORE FRAGMENTS 字段?
【发布时间】:2010-01-23 18:34:45
【问题描述】:

鉴于此标头,我如何查找是否设置了 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 */
};

【问题讨论】:

    标签: c network-programming header protocols packet-sniffers


    【解决方案1】:
    struct sniff_ip ip_hdr; 
    ...
    if(ip_hdr.ip_off & IP_MF) {
      //more fragments bit is set.
    }
    

    【讨论】:

    • ...并且,如果ip_hdr 中的字段按照它们在网络上的顺序排列(例如,如果这是从网络捕获的数据包或从捕获文件中读取的数据包)使用 libpcap/WinPcap,且未修改),记得先将其从网络字节顺序转换为主机字节顺序,ntohs()
    猜你喜欢
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    • 2011-03-16
    • 1970-01-01
    相关资源
    最近更新 更多