LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 606|回复: 2

再次关于字节序的疑问,或者这个不是字节序的问题,问题内详

[复制链接]
发表于 2005-8-31 11:19:19 | 显示全部楼层 |阅读模式
我在ip.h中找到的数据结构:
  1. struct ip
  2.   {
  3. #if __BYTE_ORDER == __LITTLE_ENDIAN
  4.     unsigned int ip_hl:4;               /* header length */
  5.     unsigned int ip_v:4;                /* version */
  6. #endif
  7. #if __BYTE_ORDER == __BIG_ENDIAN
  8.     unsigned int ip_v:4;                /* version */
  9.     unsigned int ip_hl:4;               /* header length */
  10. #endif
  11.     u_int8_t ip_tos;                    /* type of service */
  12.     u_short ip_len;                     /* total length */
  13.     u_short ip_id;                      /* identification */
  14.     u_short ip_off;                     /* fragment offset field */
  15. #define IP_RF 0x8000                    /* reserved fragment flag */
  16. #define IP_DF 0x4000                    /* dont fragment flag */
  17. #define IP_MF 0x2000                    /* more fragments flag */
  18. #define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
  19.     u_int8_t ip_ttl;                    /* time to live */
  20.     u_int8_t ip_p;                      /* protocol */
  21.     u_short ip_sum;                     /* checksum */
  22.     struct in_addr ip_src, ip_dst;      /* source and dest address */
  23.   };
复制代码


看看这段:
  1. #if __BYTE_ORDER == __LITTLE_ENDIAN
  2.     unsigned int ip_hl:4;               /* header length */
  3.     unsigned int ip_v:4;                /* version */
  4. #endif
  5. #if __BYTE_ORDER == __BIG_ENDIAN
  6.     unsigned int ip_v:4;                /* version */
  7.     unsigned int ip_hl:4;               /* header length */
  8. #endif
复制代码


字节序与字节的顺序有关,在字节内部应该是无关的,为何在此会有字节内部顺序的定义?
各种计算机体系实现中字节内部顺序也有可能不同吗?
发表于 2005-8-31 12:06:07 | 显示全部楼层
Bit order usually follows the same endianness as the byte order for a given computer system. That is, in a big endian system the most significant bit is stored at the lowest bit address; in a little endian system, the least significant bit is stored at the lowest bit address.

详见:http://www.linuxjournal.com/node/6788/print
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-31 12:39:17 | 显示全部楼层
还真有bit order。。。

谢谢rickxbx
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表