Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <pre><code>while (packet = pcap_next(handle,&amp;header)) { u_char *pkt_ptr = (u_char *)packet; </code></pre> </blockquote> <p>Don't do that; you're throwing away the <code>const</code>, and you really should <em>NOT</em> be modifying what the return value of <code>pcap_next()</code> points to.</p> <blockquote> <pre><code> struct ip *ip_hdr = (struct ip *)pkt_ptr; //point to an IP header structure </code></pre> </blockquote> <p>That will point to an IP header structure <em>ONLY</em> if <code>pcap_datalink(handle)</code> returns <code>DLT_RAW</code>, which it probably will <em>NOT</em> do on most devices.</p> <p>If, for example, <code>pcap_datalink(handle)</code> returns <code>DLT_EN10MB</code>, <code>packet</code> will point to an <em>Ethernet</em> header (the <code>10MB</code> is historical - it's used for all Ethernet speeds other than the ancient historical 3MB experimental Ethernet at Xerox, which had a different header type).</p> <p>See <a href="http://www.tcpdump.org/linktypes.html" rel="nofollow">the list of link-layer header type values</a> for a list of the possible <code>DLT_</code> types.</p> <blockquote> <pre><code> struct pcap_pkthdr *pkt_hdr =(struct pcap_pkthdr *)packet; </code></pre> </blockquote> <p>That won't work, either. The <code>struct pcap_pkthdr</code> for the packet is in <code>header</code>.</p> <blockquote> <pre><code> unsigned int packet_length = pkt_hdr-&gt;len; </code></pre> </blockquote> <p>As per my earlier comment, that won't work. Use <code>header.len</code> instead.</p> <p>(And bear in mind that, if a "snapshot length" shorter than the maximum packet size was specified in the <code>pcap_open_live()</code> call, or specified in a <code>pcap_set_snaplen()</code> call between the <code>pcap_create()</code> and <code>pcap_activate()</code> calls, <code>header.caplen</code> could be less than <code>header.len</code>, and only <code>header.caplen</code> bytes of the packet data will actually be available.)</p> <blockquote> <pre><code> unsigned int ip_length = ntohs(ip_hdr-&gt;ip_len); </code></pre> </blockquote> <p>And, as per my earlier comment, that probably won't work, either.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload