- Posts: 1
- Thank you received: 0
bigendian-littleendian
- basarajesh
- Topic Author
- Offline
- New Member
Less
More
21 years 4 months ago #206
by basarajesh
bigendian-littleendian was created by basarajesh
The structure of IP-header is like this in /usr/include/netinet/ip.h.Can somebody explain me why the header length and version fields are interchanged in bigendian and little endian.I know that bigendian means Higher order byte will come first.But here he is interchanging the nibbles(4-bit fields).
struct iphdr
[code:1]
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int ihl:4;
unsigned int version:4;
#elif __BYTE_ORDER == __BIG_ENDIAN
unsigned int version:4;
unsigned int ihl:4;
#else
#else
# error "Please fix <bits/endian.h>"
#endif
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
/*The options start here. */
};
[/code:1]
struct iphdr
[code:1]
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int ihl:4;
unsigned int version:4;
#elif __BYTE_ORDER == __BIG_ENDIAN
unsigned int version:4;
unsigned int ihl:4;
#else
#else
# error "Please fix <bits/endian.h>"
#endif
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
/*The options start here. */
};
[/code:1]
Time to create page: 0.106 seconds