I'm trying to create an IP header in C.
typedef struct header
{
//IP-Header
unsigned char ip_v:4, ip_hl:4;/* this means that each member is 4 bits */
unsigned char ip_tos; //1 Byte
unsigned short int ip_len; //2 Byte
unsigned short int ip_id; //2 Byte
unsigned short int ip_off; //2 Byte
unsigned char ip_ttl; //1 Byte
unsigned char ip_p; //1 Byte
unsigned short int ip_sum; //2 Byte
unsigned int ip_src; //4 Byte
unsigned int ip_dst; //4 Byte
} __attribute__((packed)) ipheader;
Now I would like to use the struct and save hex values in the variables.
int main()
{
ipheader iph;
iph.ip_v='\x4';
iph.ip_hl='\x5';
iph.ip_tos='\x00';
return 0;
}
How can I write 103C into iph.ip_len? And is this structure a good way to store an IP header?