title: How do I get packet length and ip addresses in libpcap
body: <p>From <a href="http://www.binarytides.com/packet-sniffer-code-c-libpcap-linux-sockets/" rel="nofollow">this</a> example </p>
  
  <pre><code>void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *buffer)
  {
      int size = header-&gt;len;
  
      //Get the IP Header part of this packet , excluding the ethernet header
      struct iphdr *iph = (struct iphdr*)(buffer + sizeof(struct ethhdr));
      ++total;
      switch (iph-&gt;protocol) //Check the Protocol and do accordingly...
      {
          case 1:  //ICMP Protocol
              ++icmp;
              print_icmp_packet( buffer , size);
              break;
  
          case 2:  //IGMP Protocol
              ++igmp;
              break;
  
          case 6:  //TCP Protocol
              ++tcp;
              print_tcp_packet(buffer , size);
              break;
  
          case 17: //UDP Protocol
              ++udp;
              print_udp_packet(buffer , size);
              break;
  
          default: //Some Other Protocol like ARP etc.
              ++others;
              break;
      }
      printf("TCP : %d   UDP : %d   ICMP : %d   IGMP : %d   Others : %d   Total : %d\r", tcp , udp , icmp , igmp , others , total);
  }
  </code></pre>
  
  <p>variable size is, I guess, the size of the header. How do I get the size of the whole packet?</p>
  
  <p>Also, how do I convert uint32_t IP addresses to human readable IP addresses of the form xxx.xxx.xxx.xxx?</p>