IP 标头有帮助吗?
为什么在 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
Little endian 和 big endianess 只影响多字节值。为什么我们将ip_hl
存储在ip_v
之前,ip_hl
不应该在ip_v
之后传输?
Why in struct ip is defined like
#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
Little endian and big endianess only affects multibyte values. Why are we storing ip_hl
before ip_v
, shouldn't ip_hl
be transmitted after ip_v
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Endianess 还会影响编译器将位域字段(末尾的“:4”意味着它只有 4 位值)放入结果结构的字节中的方式。对于大尾数法,这些位从最高有效位开始填充。对于小尾数法,这些位从最低有效位开始填充。
Endianess also affects the way the compiler puts bit-field fields (the ":4" at the end means it's only 4 bits worth of the value) within bytes of the resulting structure. For big-endian, the bits populate from the most-significant. For little-endian, the bits populate from the least-significant.