vendor/TCPDUMP: Import libpcap 4.99.1
[dragonfly.git] / contrib / tcpdump / README.md
1 # TCPDUMP 4.x.y by [The Tcpdump Group](https://www.tcpdump.org/)
2
3 **To report a security issue please send an e-mail to security@tcpdump.org.**
4
5 To report bugs and other problems, contribute patches, request a
6 feature, provide generic feedback etc please see the
7 [guidelines for contributing](CONTRIBUTING) in the tcpdump source tree root.
8
9 Anonymous Git is available via
10
11         https://github.com/the-tcpdump-group/tcpdump.git
12
13 This directory contains source code for tcpdump, a tool for network
14 monitoring and data acquisition.
15
16 Over the past few years, tcpdump has been steadily improved by the
17 excellent contributions from the Internet community (just browse
18 through the [change log](CHANGES)).  We are grateful for all the input.
19
20 ### Supported platforms
21 In many operating systems tcpdump is available as a native package or port,
22 which simplifies installation of updates and long-term maintenance. However,
23 the native packages are sometimes a few versions behind and to try a more
24 recent snapshot it will take to compile tcpdump from the source code.
25
26 tcpdump compiles and works on at least the following platforms:
27
28 * AIX
29 * DragonFly BSD
30 * FreeBSD
31 * Haiku
32 * HP-UX 11i
33 * GNU/Linux
34 * {Mac} OS X / macOS
35 * NetBSD
36 * OpenBSD
37 * OpenWrt
38 * Solaris
39 * Windows (requires WinPcap or Npcap, and Visual Studio with CMake)
40
41 ### Dependency on libpcap
42 Tcpdump uses libpcap, a system-independent interface for user-level
43 packet capture.  Before building tcpdump, you must first retrieve and
44 build libpcap.
45
46 Once libpcap is built (either install it or make sure it's in
47 `../libpcap`), you can build tcpdump using the procedure in the
48 [installation guide](INSTALL.txt).
49
50 ### Origins of tcpdump
51 The program is loosely based on SMI's "etherfind" although none of the
52 etherfind code remains.  It was originally written by Van Jacobson as
53 part of an ongoing research project to investigate and improve TCP and
54 Internet gateway performance.  The parts of the program originally
55 taken from Sun's etherfind were later re-written by Steven McCanne of
56 LBL.  To insure that there would be no vestige of proprietary code in
57 tcpdump, Steve wrote these pieces from the specification given by the
58 manual entry, with no access to the source of tcpdump or etherfind.
59 ```text
60 formerly from   Lawrence Berkeley National Laboratory
61                 Network Research Group <tcpdump@ee.lbl.gov>
62                 ftp://ftp.ee.lbl.gov/old/tcpdump.tar.Z (3.4)
63 ```
64
65 ### See also
66 Richard Stevens gives an excellent treatment of the Internet protocols
67 in his book *"TCP/IP Illustrated, Volume 1"*. If you want to learn more
68 about tcpdump and how to interpret its output, pick up this book.
69
70 Another tool that tcpdump users might find useful is
71 [tcpslice](https://github.com/the-tcpdump-group/tcpslice).
72 It is a program that can be used to extract portions of tcpdump binary
73 trace files.
74
75 ### The original LBL README by Steve McCanne, Craig Leres and Van Jacobson
76 ```
77 This directory also contains some short awk programs intended as
78 examples of ways to reduce tcpdump data when you're tracking
79 particular network problems:
80
81 send-ack.awk
82         Simplifies the tcpdump trace for an ftp (or other unidirectional
83         tcp transfer).  Since we assume that one host only sends and
84         the other only acks, all address information is left off and
85         we just note if the packet is a "send" or an "ack".
86
87         There is one output line per line of the original trace.
88         Field 1 is the packet time in decimal seconds, relative
89         to the start of the conversation.  Field 2 is delta-time
90         from last packet.  Field 3 is packet type/direction.
91         "Send" means data going from sender to receiver, "ack"
92         means an ack going from the receiver to the sender.  A
93         preceding "*" indicates that the data is a retransmission.
94         A preceding "-" indicates a hole in the sequence space
95         (i.e., missing packet(s)), a "#" means an odd-size (not max
96         seg size) packet.  Field 4 has the packet flags
97         (same format as raw trace).  Field 5 is the sequence
98         number (start seq. num for sender, next expected seq number
99         for acks).  The number in parens following an ack is
100         the delta-time from the first send of the packet to the
101         ack.  A number in parens following a send is the
102         delta-time from the first send of the packet to the
103         current send (on duplicate packets only).  Duplicate
104         sends or acks have a number in square brackets showing
105         the number of duplicates so far.
106
107         Here is a short sample from near the start of an ftp:
108                 3.00    0.20   send . 512
109                 3.20    0.20    ack . 1024  (0.20)
110                 3.20    0.00   send P 1024
111                 3.40    0.20    ack . 1536  (0.20)
112                 3.80    0.40 * send . 0  (3.80) [2]
113                 3.82    0.02 *  ack . 1536  (0.62) [2]
114         Three seconds into the conversation, bytes 512 through 1023
115         were sent.  200ms later they were acked.  Shortly thereafter
116         bytes 1024-1535 were sent and again acked after 200ms.
117         Then, for no apparent reason, 0-511 is retransmitted, 3.8
118         seconds after its initial send (the round trip time for this
119         ftp was 1sec, +-500ms).  Since the receiver is expecting
120         1536, 1536 is re-acked when 0 arrives.
121
122 packetdat.awk
123         Computes chunk summary data for an ftp (or similar
124         unidirectional tcp transfer). [A "chunk" refers to
125         a chunk of the sequence space -- essentially the packet
126         sequence number divided by the max segment size.]
127
128         A summary line is printed showing the number of chunks,
129         the number of packets it took to send that many chunks
130         (if there are no lost or duplicated packets, the number
131         of packets should equal the number of chunks) and the
132         number of acks.
133
134         Following the summary line is one line of information
135         per chunk.  The line contains eight fields:
136            1 - the chunk number
137            2 - the start sequence number for this chunk
138            3 - time of first send
139            4 - time of last send
140            5 - time of first ack
141            6 - time of last ack
142            7 - number of times chunk was sent
143            8 - number of times chunk was acked
144         (all times are in decimal seconds, relative to the start
145         of the conversation.)
146
147         As an example, here is the first part of the output for
148         an ftp trace:
149
150         # 134 chunks.  536 packets sent.  508 acks.
151         1       1       0.00    5.80    0.20    0.20    4       1
152         2       513     0.28    6.20    0.40    0.40    4       1
153         3       1025    1.16    6.32    1.20    1.20    4       1
154         4       1561    1.86    15.00   2.00    2.00    6       1
155         5       2049    2.16    15.44   2.20    2.20    5       1
156         6       2585    2.64    16.44   2.80    2.80    5       1
157         7       3073    3.00    16.66   3.20    3.20    4       1
158         8       3609    3.20    17.24   3.40    5.82    4       11
159         9       4097    6.02    6.58    6.20    6.80    2       5
160
161         This says that 134 chunks were transferred (about 70K
162         since the average packet size was 512 bytes).  It took
163         536 packets to transfer the data (i.e., on the average
164         each chunk was transmitted four times).  Looking at,
165         say, chunk 4, we see it represents the 512 bytes of
166         sequence space from 1561 to 2048.  It was first sent
167         1.86 seconds into the conversation.  It was last
168         sent 15 seconds into the conversation and was sent
169         a total of 6 times (i.e., it was retransmitted every
170         2 seconds on the average).  It was acked once, 140ms
171         after it first arrived.
172
173 stime.awk
174 atime.awk
175         Output one line per send or ack, respectively, in the form
176                 <time> <seq. number>
177         where <time> is the time in seconds since the start of the
178         transfer and <seq. number> is the sequence number being sent
179         or acked.  I typically plot this data looking for suspicious
180         patterns.
181
182
183 The problem I was looking at was the bulk-data-transfer
184 throughput of medium delay network paths (1-6 sec.  round trip
185 time) under typical DARPA Internet conditions.  The trace of the
186 ftp transfer of a large file was used as the raw data source.
187 The method was:
188
189   - On a local host (but not the Sun running tcpdump), connect to
190     the remote ftp.
191
192   - On the monitor Sun, start the trace going.  E.g.,
193       tcpdump host local-host and remote-host and port ftp-data >tracefile
194
195   - On local, do either a get or put of a large file (~500KB),
196     preferably to the null device (to minimize effects like
197     closing the receive window while waiting for a disk write).
198
199   - When transfer is finished, stop tcpdump.  Use awk to make up
200     two files of summary data (maxsize is the maximum packet size,
201     tracedata is the file of tcpdump tracedata):
202       awk -f send-ack.awk packetsize=avgsize tracedata >sa
203       awk -f packetdat.awk packetsize=avgsize tracedata >pd
204
205   - While the summary data files are printing, take a look at
206     how the transfer behaved:
207       awk -f stime.awk tracedata | xgraph
208     (90% of what you learn seems to happen in this step).
209
210   - Do all of the above steps several times, both directions,
211     at different times of day, with different protocol
212     implementations on the other end.
213
214   - Using one of the Unix data analysis packages (in my case,
215     S and Gary Perlman's Unix|Stat), spend a few months staring
216     at the data.
217
218   - Change something in the local protocol implementation and
219     redo the steps above.
220
221   - Once a week, tell your funding agent that you're discovering
222     wonderful things and you'll write up that research report
223     "real soon now".
224 ```