69,373
社区成员
发帖
与我相关
我的任务
分享
#ifndef _IPV4_H
#define _IPV4_H
struct ipv4_h {
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int hlen :4;
unsigned int ver :4;
#elif __BYTE_ORDER == __BIG_ENDIAN
unsigned int ver :4;
unsigned int hlen :4;
#else
#error "please fix <bits/endian.h>"
#endif
uint8_t tos;
uint16_t tot_len;
uint16_t id;
#if __BYTE_ORDER == __LITTLE_ENDIAN
uint16_t frag_off1 :5;
uint16_t mf :1;
uint16_t df :1;
uint16_t res :1;
uint16_t frag_off2 :8;
#define IP_SET_FRAGOFF(ip,v) {(ip)->frag_off1=((v)&0x1f00)>>8; (ip)->frag_off2=(v)&0x00ff;}
#elif __BYTE_ORDER == __BIG_ENDIAN
uint16_t res :1;
uint16_t df :1;
uint16_t mf :1;
uint16_t frag_off :13;
#define IP_SET_FRAGOFF(ip,v) (ip)->frag_off=(v)
#else
#error "please fix <bits/endian.h>"
#endif
uint8_t ttl;
uint8_t protocol;
uint16_t checksum;
uint32_t saddr;
uint32_t daddr;
};
#endif
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#ifndef _IPV4_H
#define _IPV4_H
struct ipv4_h {
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int hlen :4;
unsigned int ver :4;
#elif __BYTE_ORDER == __BIG_ENDIAN
unsigned int ver :4;
unsigned int hlen :4;
#else
#error "please fix <bits/endian.h>"
#endif
uint8_t tos;
uint16_t tot_len;
uint16_t id;
#if __BYTE_ORDER == __LITTLE_ENDIAN
uint16_t frag_off1 :5;
uint16_t mf :1;
uint16_t df :1;
uint16_t res :1;
uint16_t frag_off2 :8;
#define IP_SET_FRAGOFF(ip,v) {(ip)->frag_off1=((v)&0x1f00)>>8; (ip)->frag_off2=(v)&0x00ff;}
#elif __BYTE_ORDER == __BIG_ENDIAN
uint16_t res :1;
uint16_t df :1;
uint16_t mf :1;
uint16_t frag_off :13;
#define IP_SET_FRAGOFF(ip,v) (ip)->frag_off=(v)
#else
#error "please fix <bits/endian.h>"
#endif
uint8_t ttl;
uint8_t protocol;
uint16_t checksum;
uint32_t saddr;
uint32_t daddr;
};
#endif