title: Bogus IPv4 version after sending packet on c
body: <p>I have written a code to send icmp ping packets. However, packets are not sent correctly. I'm using the gnu iphdr and icmphdr for my packet. I was using wireshark after compiling my code and it showed me, that arp successfully found destination, but the packet I sent was corrupted (Bogus IPv4 version (1, must be 4)). What could possibly cause this? I can't find anything for now, I compared it with some other codes for ping command, and basically packet should be the same. Thank you.</p>
  
  <p><strong>Wireshark:</strong></p>
  
  <blockquote>
    <p>271 | 3.195079710 | Tp-LinkT_13:20:1a | Azurewav_fd:23:a9 | IPv4 | 42 | Bogus IPv4 version (1, must be 4)</p>
  </blockquote>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>struct iphdr *ip;
  struct icmphdr *icmp;
  
  //decimal version of ip addresses
  subnet.ipDec = 2248190144;
  subnet.ipDest = 2868947136;
  
  //forming packet
  uint16_t psize = sizeof(*icmp)+sizeof(*ip)+1;
  char *packet;
  packet=malloc(psize);
  ip= (struct iphdr*) packet;
  icmp= (struct icmphdr*)(ip+1);
  
  //session identificators
  unsigned int id = (unsigned int)rand();
  unsigned int seq = (unsigned int)rand();
  
  //filling packet with data
  ip-&gt;version = 4;
  ip-&gt;ihl = 4;
  ip-&gt;tos = 0;
  ip-&gt;tot_len = htons(psize);
  ip-&gt;id = id;
  ip-&gt;frag_off = 0;
  ip-&gt;ttl = 64;
  ip-&gt;protocol = IPPROTO_ICMP;
  ip-&gt;saddr = subnet.ipDec;
  ip-&gt;daddr = subnet.ipDest;
  icmp-&gt;type = 8;
  icmp-&gt;code = 0;
  icmp-&gt;un.echo.id=id;
  icmp-&gt;un.echo.sequence=seq;
  icmp-&gt;checksum=icmpchecksum((unsigned short *)icmp, sizeof(struct icmphdr));
  
  sock=socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
  
  //destination for sendto
  struct sockaddr_in destIP;
  socklen_t destLen = sizeof(destIP);
  destIP.sin_addr.s_addr=subnet.ipDest;
  destIP.sin_family=AF_INET;
  
  sendto(sock, &amp;packet, psize, 0, (struct sockaddr*) &amp;destIP, destLen);
  </code></pre>