title: Create IP Header in C
body: <p>I'm trying to create an IP header in C.</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>Now I would like to use the struct and save hex values in the variables. </p>
  
  <pre><code>int main()
  {
      ipheader iph;
  
      iph.ip_v='\x4';
      iph.ip_hl='\x5';
      iph.ip_tos='\x00';
  
      return 0;
  }
  </code></pre>
  
  <p>How can I write <strong>103C into iph.ip_len</strong>? And is this structure a good way to store an IP header?</p>