- 论坛徽章:
- 0
|
"big endian"和"little endian"的区别是在按字节存储顺序上。比如0x12345678
在"little endian"上表示为(假设基址为0x100):
0x100 0x78 (01111000)
0x101 0x56
0x102 0x34
0x103 0x12
在“big endian"上表示为:
0x100 0x12
0x101 0x34
0x102 0x56
0x103 0x78 (01111000)
它们字节中的位存储还是相同的,所以我对Linux中,这段代码中为什么要把它们的位域定义成相反的顺序?小弟不懂,请指教。
struct tcphdr {
__u16 source;
__u16 dest;
__u32 seq;
__u32 ack_seq;
#if defined(__LITTLE_ENDIAN_BITFIELD)
__u16 res1:4,
doff:4,
fin:1,
syn:1,
rst:1,
psh:1,
ack:1,
urg:1,
ece:1,
cwr:1;
#elif defined(__BIG_ENDIAN_BITFIELD)
__u16 doff:4,
res1:4,
cwr:1,
ece:1,
urg:1,
ack:1,
psh:1,
rst:1,
syn:1,
fin:1;
#else
#error "Adjust your <asm/byteorder.h> defines"
#endif
__u16 window;
__u16 check;
__u16 urg_ptr;
}; |
|