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