免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1092 | 回复: 0
打印 上一主题 下一主题

[网络] ip头部长度的问题,困惑了好久,求解答 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-07-02 20:31 |只看该作者 |倒序浏览

struct ip
  {
#if __BYTE_ORDER == __LITTLE_ENDIAN
    unsigned int ip_hl:4;                /* header length */
    unsigned int ip_v:4;                /* version
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
    unsigned int ip_v:4;                /* version */
    unsigned int ip_hl:4;                /* header length */
#endif

上面是linux的系统源文件定义的ip头部的一部分,我想问的是:既然字节序对一个字节没有影响,为什么还要分大端、小端哪?
如果我自己定义的ip头结构如下:
struct ip_header{
        u_int8_t ip_verlen;
        u_int8_t ip_tos;
        u_int16_t ip_len;
        u_int16_t ip_id;
        u_int16_t ip_off;          //包括三位标志和13位偏移m
        u_int8_t  ip_ttl;
        u_int8_t  ip_protocal;    //标识ICMP、IGMP、UDP、 TCP
        u_int16_t   ip_checksum;
        struct in_addr ip_source_address;
        struct in_addr ip_dst_address;
};
ip的头部长度为什么不是取高4位哪??而是ip_header_len = (ipHeader->ip_verlen & 0x0f)<<2;,取低4位
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP