Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The snifex.c is a good start (http://www.tcpdump.org/pcap.html)</p> <p>In the callback function:</p> <pre><code>got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet); </code></pre> <p>the pointer *ip points to the start of the ip header. </p> <pre><code>ip = (struct sniff_ip*)(packet + SIZE_ETHERNET); </code></pre> <p>There you can find the IP address information. Note that you have to separate the calls to inet_ntoa as it appears to use a static buffer. So you should use two printf calls if you are planning to show the output in the cmd or file. That is why they are in separate lines in snifex.c:</p> <pre><code>printf(" From: %s\n", inet_ntoa(ip-&gt;ip_src)); printf(" To: %s\n", inet_ntoa(ip-&gt;ip_dst)); </code></pre> <p>For the TCP information you can use the tcp pointer</p> <pre><code>tcp = (struct sniff_tcp*)(packet + SIZE_ETHERNET + size_ip); </code></pre> <p>Use the TCP flags tcp->th_flags to find out the connection state, e.g. <code>tcp-&gt;th_flags==TH_SYN</code></p> <p>Once you know the flags you have to check the <a href="http://www.ietf.org/rfc/rfc793.txt" rel="nofollow">RFC793</a> TCP/IP state diagram to determine the state of the TCP protocol.</p> <p>In terms of implementations, you could use a hash array for each 4-tuple (srcIP, dstIP, srcPort, dstPort) in order to have an O(1) (best case). Note that there may be cases in which you see midstream traffic, or half-open TCP connections etc. The RFC describes in detail how to handle them.</p> <p>Finally, if you do not wish to implement the TCP protocol you can use the <a href="http://libnids.sourceforge.net/" rel="nofollow">Libnids</a> library which emulates the IP stack of Linux 2.0.x, offers IP defragmentation and TCP stream assembly.</p>
    singulars
    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. This table or related slice is empty.
    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