-3
我有一个结构,我可以使用两个定义IP_V(ip)
和IP_HL(ip)
来读取,但我也需要写入它们。给定结构struct pkt_ip ip;
,写入ip_vhl
中较低和较高位的语法是什么?使用定义(C)写入结构偏移
struct pkt_ip
{
uint8_t ip_vhl; /* header length, version */
#define IP_V(ip) (((ip)->ip_vhl & 0xf0) >> 4)
#define IP_HL(ip) ((ip)->ip_vhl & 0x0f)
uint8_t ip_tos; /* type of service */
#define IP_DSCP(ip) (((ip)->ip_tos & 0xfc) >> 4)
#define IP_ECN(ip) ((ip)->ip_tos & 0x3f)
uint16_t ip_len; /* total length */
uint16_t ip_id; /* identification */
uint16_t ip_off; /* fragment offset field */
#define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
uint8_t ip_ttl; /* time to live */
uint8_t ip_p; /* protocol */
uint16_t ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
} __attribute__ ((__packed__));