Imported upstream version 1.5
[manpages-zh.git] / raw / man8 / tcpdump.8
blob537437411b9981718aac27682255b85ce93774fa
1 .\" @(#) $Header: /cvsroot/cmpp/man-pages-zh_CN/raw/man8/tcpdump.8,v 1.1 2003/12/20 03:31:54 bbbush Exp $ (LBL)
2 .\"
3 .\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997
4 .\"     The Regents of the University of California.  All rights reserved.
5 .\" All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that: (1) source code distributions
9 .\" retain the above copyright notice and this paragraph in its entirety, (2)
10 .\" distributions including binary code include the above copyright notice and
11 .\" this paragraph in its entirety in the documentation or other materials
12 .\" provided with the distribution, and (3) all advertising materials mentioning
13 .\" features or use of this software display the following acknowledgement:
14 .\" ``This product includes software developed by the University of California,
15 .\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 .\" the University nor the names of its contributors may be used to endorse
17 .\" or promote products derived from this software without specific prior
18 .\" written permission.
19 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 .\"
23 .TH TCPDUMP 8  "3 January 2001"
24 .SH NAME
25 tcpdump \- dump traffic on a network
26 .SH SYNOPSIS
27 .na
28 .B tcpdump
30 .B \-adeflnNOpqRStuvxX
31 ] [
32 .B \-c
33 .I count
35 .br
36 .ti +8
38 .B \-C
39 .I file_size
40 ] [
41 .B \-F
42 .I file
44 .br
45 .ti +8
47 .B \-i
48 .I interface
51 .B \-m
52 .I module
55 .B \-r
56 .I file
58 .br
59 .ti +8
61 .B \-s
62 .I snaplen
65 .B \-T
66 .I type
69 .B \-U
70 .I user
73 .B \-w
74 .I file
76 .br
77 .ti +8
79 .B \-E
80 .I algo:secret
83 .I expression
85 .br
86 .ad
87 .SH DESCRIPTION
88 .LP
89 \fITcpdump\fP prints out the headers of packets on a network interface
90 that match the boolean \fIexpression\fP.  It can also be run with the
91 .B \-w
92 flag, which causes it to save the packet data to a file for later
93 analysis, and/or with the
94 .B \-r
95 flag, which causes it to read from a saved packet file rather than to
96 read packets from a network interface.  In all cases, only packets that
97 match
98 .I expression
99 will be processed by
100 .IR tcpdump .
102 .I Tcpdump
103 will, if not run with the
104 .B \-c
105 flag, continue capturing packets until it is interrupted by a SIGINT
106 signal (generated, for example, by typing your interrupt character,
107 typically control-C) or a SIGTERM signal (typically generated with the
108 .BR kill (1)
109 command); if run with the
110 .B \-c
111 flag, it will capture packets until it is interrupted by a SIGINT or
112 SIGTERM signal or the specified number of packets have been processed.
114 When
115 .I tcpdump
116 finishes capturing packets, it will report counts of:
118 packets ``received by filter'' (the meaning of this depends on the OS on
119 which you're running
120 .IR tcpdump ,
121 and possibly on the way the OS was configured - if a filter was
122 specified on the command line, on some OSes it counts packets regardless
123 of whether they were matched by the filter expression, and on other OSes
124 it counts only packets that were matched by the filter expression and
125 were processed by
126 .IR tcpdump );
128 packets ``dropped by kernel'' (this is the number of packets that were
129 dropped, due to a lack of buffer space, by the packet capture mechanism
130 in the OS on which
131 .I tcpdump
132 is running, if the OS reports that information to applications; if not,
133 it will be reported as 0).
135 On platforms that support the SIGINFO signal, such as most BSDs, it will
136 report those counts when it receives a SIGINFO signal (generated, for
137 example, by typing your ``status'' character, typically control-T) and
138 will continue capturing packets.
140 Reading packets from a network interface may require that you have
141 special privileges:
143 .B Under SunOS 3.x or 4.x with NIT or BPF:
144 You must have read access to
145 .I /dev/nit
147 .IR /dev/bpf* .
149 .B Under Solaris with DLPI:
150 You must have read/write access to the network pseudo device, e.g.
151 .IR /dev/le .
152 On at least some versions of Solaris, however, this is not sufficient to
153 allow
154 .I tcpdump
155 to capture in promiscuous mode; on those versions of Solaris, you must
156 be root, or
157 .I tcpdump
158 must be installed setuid to root, in order to capture in promiscuous
159 mode.  Note that, on many (perhaps all) interfaces, if you don't capture
160 in promiscuous mode, you will not see any outgoing packets, so a capture
161 not done in promiscuous mode may not be very useful.
163 .B Under HP-UX with DLPI:
164 You must be root or
165 .I tcpdump
166 must be installed setuid to root.
168 .B Under IRIX with snoop:
169 You must be root or
170 .I tcpdump
171 must be installed setuid to root.
173 .B Under Linux:
174 You must be root or
175 .I tcpdump
176 must be installed setuid to root.
178 .B Under Ultrix and Digital UNIX/Tru64 UNIX:
179 Any user may capture network traffic with
180 .IR tcpdump .
181 However, no user (not even the super-user) can capture in promiscuous
182 mode on an interface unless the super-user has enabled promiscuous-mode
183 operation on that interface using
184 .IR pfconfig (8),
185 and no user (not even the super-user) can capture unicast traffic
186 received by or sent by the machine on an interface unless the super-user
187 has enabled copy-all-mode operation on that interface using
188 .IR pfconfig ,
190 .I useful
191 packet capture on an interface probably requires that either
192 promiscuous-mode or copy-all-mode operation, or both modes of
193 operation, be enabled on that interface.
195 .B Under BSD:
196 You must have read access to
197 .IR /dev/bpf* .
199 Reading a saved packet file doesn't require special privileges.
200 .SH OPTIONS
202 .B \-a
203 Attempt to convert network and broadcast addresses to names.
205 .B \-c
206 Exit after receiving \fIcount\fP packets.
208 .B \-C
209 Before writing a raw packet to a savefile, check whether the file is
210 currently larger than \fIfile_size\fP and, if so, close the current
211 savefile and open a new one.  Savefiles after the first savefile will
212 have the name specified with the
213 .B \-w
214 flag, with a number after it, starting at 2 and continuing upward.
215 The units of \fIfile_size\fP are millions of bytes (1,000,000 bytes,
216 not 1,048,576 bytes).
218 .B \-d
219 Dump the compiled packet-matching code in a human readable form to
220 standard output and stop.
222 .B \-dd
223 Dump packet-matching code as a
224 .B C
225 program fragment.
227 .B \-ddd
228 Dump packet-matching code as decimal numbers (preceded with a count).
230 .B \-e
231 Print the link-level header on each dump line.
233 .B \-E
234 Use \fIalgo:secret\fP for decrypting IPsec ESP packets.
235 Algorithms may be
236 \fBdes-cbc\fP,
237 \fB3des-cbc\fP,
238 \fBblowfish-cbc\fP,
239 \fBrc3-cbc\fP,
240 \fBcast128-cbc\fP, or
241 \fBnone\fP.
242 The default is \fBdes-cbc\fP.
243 The ability to decrypt packets is only present if \fItcpdump\fP was compiled
244 with cryptography enabled.
245 \fIsecret\fP the ascii text for ESP secret key.
246 We cannot take arbitrary binary value at this moment.
247 The option assumes RFC2406 ESP, not RFC1827 ESP.
248 The option is only for debugging purposes, and
249 the use of this option with truly `secret' key is discouraged.
250 By presenting IPsec secret key onto command line
251 you make it visible to others, via
252 .IR ps (1)
253 and other occasions.
255 .B \-f
256 Print `foreign' internet addresses numerically rather than symbolically
257 (this option is intended to get around serious brain damage in
258 Sun's yp server \(em usually it hangs forever translating non-local
259 internet numbers).
261 .B \-F
262 Use \fIfile\fP as input for the filter expression.
263 An additional expression given on the command line is ignored.
265 .B \-i
266 Listen on \fIinterface\fP.
267 If unspecified, \fItcpdump\fP searches the system interface list for the
268 lowest numbered, configured up interface (excluding loopback).
269 Ties are broken by choosing the earliest match.
271 On Linux systems with 2.2 or later kernels, an
272 .I interface
273 argument of ``any'' can be used to capture packets from all interfaces.
274 Note that captures on the ``any'' device will not be done in promiscuous
275 mode.
277 .B \-l
278 Make stdout line buffered.
279 Useful if you want to see the data
280 while capturing it.
281 E.g.,
283 ``tcpdump\ \ \-l\ \ |\ \ tee dat'' or
284 ``tcpdump\ \ \-l \ \ > dat\ \ &\ \ tail\ \ \-f\ \ dat''.
286 .B \-m
287 Load SMI MIB module definitions from file \fImodule\fR.
288 This option
289 can be used several times to load several MIB modules into \fItcpdump\fP.
291 .B \-n
292 Don't convert host addresses to names.  This can be used to avoid 
293 DNS lookups.
295 .B \-nn
296 Don't convert protocol and port numbers etc. to names either.  
298 .B \-N
299 Don't print domain name qualification of host names.
300 E.g.,
301 if you give this flag then \fItcpdump\fP will print ``nic''
302 instead of ``nic.ddn.mil''.
304 .B \-O
305 Do not run the packet-matching code optimizer.
306 This is useful only
307 if you suspect a bug in the optimizer.
309 .B \-p
310 \fIDon't\fP put the interface
311 into promiscuous mode.
312 Note that the interface might be in promiscuous
313 mode for some other reason; hence, `-p' cannot be used as an abbreviation for
314 `ether host {local-hw-addr} or ether broadcast'.
316 .B \-q
317 Quick (quiet?) output.
318 Print less protocol information so output
319 lines are shorter.
321 .B \-R
322 Assume ESP/AH packets to be based on old specification (RFC1825 to RFC1829).
323 If specified, \fItcpdump\fP will not print replay prevention field.
324 Since there is no protocol version field in ESP/AH specification,
325 \fItcpdump\fP cannot deduce the version of ESP/AH protocol.
327 .B \-r
328 Read packets from \fIfile\fR (which was created with the -w option).
329 Standard input is used if \fIfile\fR is ``-''.
331 .B \-S
332 Print absolute, rather than relative, TCP sequence numbers.
334 .B \-s
335 Snarf \fIsnaplen\fP bytes of data from each packet rather than the
336 default of 68 (with SunOS's NIT, the minimum is actually 96).
337 68 bytes is adequate for IP, ICMP, TCP
338 and UDP but may truncate protocol information from name server and NFS
339 packets (see below).
340 Packets truncated because of a limited snapshot
341 are indicated in the output with ``[|\fIproto\fP]'', where \fIproto\fP
342 is the name of the protocol level at which the truncation has occurred.
343 Note that taking larger snapshots both increases
344 the amount of time it takes to process packets and, effectively,
345 decreases the amount of packet buffering.
346 This may cause packets to be
347 lost.
348 You should limit \fIsnaplen\fP to the smallest number that will
349 capture the protocol information you're interested in.
350 Setting
351 \fIsnaplen\fP to 0 means use the required length to catch whole packets.
353 .B \-T
354 Force packets selected by "\fIexpression\fP" to be interpreted the
355 specified \fItype\fR.
356 Currently known types are
357 \fBcnfp\fR (Cisco NetFlow protocol),
358 \fBrpc\fR (Remote Procedure Call),
359 \fBrtp\fR (Real-Time Applications protocol),
360 \fBrtcp\fR (Real-Time Applications control protocol),
361 \fBsnmp\fR (Simple Network Management Protocol),
362 \fBvat\fR (Visual Audio Tool),
364 \fBwb\fR (distributed White Board).
366 .B \-t
367 \fIDon't\fP print a timestamp on each dump line.
369 .B \-tt
370 Print an unformatted timestamp on each dump line.
372 .B \-U
373 Drops root privileges and changes user ID to
374 .I user
375 and group ID to the primary group of
376 .IR user .
378 .B Note! 
379 Red Hat Linux automatically drops the privileges to user ``pcap''
380 if nothing else is specified.
382 .B \-ttt
383 Print a delta (in micro-seconds) between current and previous line
384 on each dump line.
386 .B \-tttt
387 Print a timestamp in default format proceeded by date on each dump line.
389 .B \-u
390 Print undecoded NFS handles.
392 .B \-v
393 (Slightly more) verbose output.
394 For example, the time to live,
395 identification, total length and options in an IP packet are printed.
396 Also enables additional packet integrity checks such as verifying the
397 IP and ICMP header checksum.
399 .B \-vv
400 Even more verbose output.
401 For example, additional fields are
402 printed from NFS reply packets, and SMB packets are fully decoded.
404 .B \-vvv
405 Even more verbose output.
406 For example,
407 telnet \fBSB\fP ... \fBSE\fP options
408 are printed in full.
409 With
410 .B \-X
411 telnet options are printed in hex as well.
413 .B \-w
414 Write the raw packets to \fIfile\fR rather than parsing and printing
415 them out.
416 They can later be printed with the \-r option.
417 Standard output is used if \fIfile\fR is ``-''.
419 .B \-x
420 Print each packet (minus its link level header) in hex.
421 The smaller of the entire packet or
422 .I snaplen
423 bytes will be printed.  Note that this is the entire link-layer
424 packet, so for link layers that pad (e.g. Ethernet), the padding bytes
425 will also be printed when the higher layer packet is shorter than the
426 required padding.
428 .B \-X
429 When printing hex, print ascii too.
430 Thus if
431 .B \-x
432 is also set, the packet is printed in hex/ascii.
433 This is very handy for analysing new protocols.
434 Even if
435 .B \-x
436 is not also set, some parts of some packets may be printed
437 in hex/ascii.
438 .IP "\fI expression\fP"
440 selects which packets will be dumped.
441 If no \fIexpression\fP
442 is given, all packets on the net will be dumped.
443 Otherwise,
444 only packets for which \fIexpression\fP is `true' will be dumped.
446 The \fIexpression\fP consists of one or more
447 .I primitives.
448 Primitives usually consist of an
449 .I id
450 (name or number) preceded by one or more qualifiers.
451 There are three
452 different kinds of qualifier:
453 .IP \fItype\fP
454 qualifiers say what kind of thing the id name or number refers to.
455 Possible types are
456 .BR host ,
457 .B net
459 .BR port .
460 E.g., `host foo', `net 128.3', `port 20'.
461 If there is no type
462 qualifier,
463 .B host
464 is assumed.
465 .IP \fIdir\fP
466 qualifiers specify a particular transfer direction to and/or from
467 .IR id .
468 Possible directions are
469 .BR src ,
470 .BR dst ,
471 .B "src or dst"
473 .B "src and"
474 .BR dst .
475 E.g., `src foo', `dst net 128.3', `src or dst port ftp-data'.
477 there is no dir qualifier,
478 .B "src or dst"
479 is assumed.
480 For `null' link layers (i.e. point to point protocols such as slip) the
481 .B inbound
483 .B outbound
484 qualifiers can be used to specify a desired direction.
485 .IP \fIproto\fP
486 qualifiers restrict the match to a particular protocol.
487 Possible
488 protos are:
489 .BR ether ,
490 .BR fddi ,
491 .BR tr ,
492 .BR ip ,
493 .BR ip6 ,
494 .BR arp ,
495 .BR rarp ,
496 .BR decnet ,
497 .B tcp
499 .BR udp .
500 E.g., `ether src foo', `arp net 128.3', `tcp port 21'.
501 If there is
502 no proto qualifier, all protocols consistent with the type are
503 assumed.
504 E.g., `src foo' means `(ip or arp or rarp) src foo'
505 (except the latter is not legal syntax), `net bar' means `(ip or
506 arp or rarp) net bar' and `port 53' means `(tcp or udp) port 53'.
508 [`fddi' is actually an alias for `ether'; the parser treats them
509 identically as meaning ``the data link level used on the specified
510 network interface.''  FDDI headers contain Ethernet-like source
511 and destination addresses, and often contain Ethernet-like packet
512 types, so you can filter on these FDDI fields just as with the
513 analogous Ethernet fields.
514 FDDI headers also contain other fields,
515 but you cannot name them explicitly in a filter expression.
517 Similarly, `tr' is an alias for `ether'; the previous paragraph's
518 statements about FDDI headers also apply to Token Ring headers.]
520 In addition to the above, there are some special `primitive' keywords
521 that don't follow the pattern:
522 .BR gateway ,
523 .BR broadcast ,
524 .BR less ,
525 .B greater
526 and arithmetic expressions.
527 All of these are described below.
529 More complex filter expressions are built up by using the words
530 .BR and ,
531 .B or
533 .B not
534 to combine primitives.
535 E.g., `host foo and not port ftp and not port ftp-data'.
536 To save typing, identical qualifier lists can be omitted.
537 E.g.,
538 `tcp dst port ftp or ftp-data or domain' is exactly the same as
539 `tcp dst port ftp or tcp dst port ftp-data or tcp dst port domain'.
541 Allowable primitives are:
542 .IP "\fBdst host \fIhost\fR"
543 True if the IPv4/v6 destination field of the packet is \fIhost\fP,
544 which may be either an address or a name.
545 .IP "\fBsrc host \fIhost\fR"
546 True if the IPv4/v6 source field of the packet is \fIhost\fP.
547 .IP "\fBhost \fIhost\fP
548 True if either the IPv4/v6 source or destination of the packet is \fIhost\fP.
549 Any of the above host expressions can be prepended with the keywords,
550 \fBip\fP, \fBarp\fP, \fBrarp\fP, or \fBip6\fP as in:
551 .in +.5i
553 \fBip host \fIhost\fR
555 .in -.5i
556 which is equivalent to:
557 .in +.5i
559 \fBether proto \fI\\ip\fB and host \fIhost\fR
561 .in -.5i
562 If \fIhost\fR is a name with multiple IP addresses, each address will
563 be checked for a match.
564 .IP "\fBether dst \fIehost\fP
565 True if the ethernet destination address is \fIehost\fP.
566 \fIEhost\fP
567 may be either a name from /etc/ethers or a number (see
568 .IR ethers (3N)
569 for numeric format).
570 .IP "\fBether src \fIehost\fP
571 True if the ethernet source address is \fIehost\fP.
572 .IP "\fBether host \fIehost\fP
573 True if either the ethernet source or destination address is \fIehost\fP.
574 .IP "\fBgateway\fP \fIhost\fP
575 True if the packet used \fIhost\fP as a gateway.
576 I.e., the ethernet
577 source or destination address was \fIhost\fP but neither the IP source
578 nor the IP destination was \fIhost\fP.
579 \fIHost\fP must be a name and
580 must be found both by the machine's host-name-to-IP-address resolution
581 mechanisms (host name file, DNS, NIS, etc.) and by the machine's
582 host-name-to-Ethernet-address resolution mechanism (/etc/ethers, etc.).
583 (An equivalent expression is
584 .in +.5i
586 \fBether host \fIehost \fBand not host \fIhost\fR
588 .in -.5i
589 which can be used with either names or numbers for \fIhost / ehost\fP.)
590 This syntax does not work in IPv6-enabled configuration at this moment.
591 .IP "\fBdst net \fInet\fR"
592 True if the IPv4/v6 destination address of the packet has a network
593 number of \fInet\fP.
594 \fINet\fP may be either a name from /etc/networks
595 or a network number (see \fInetworks(4)\fP for details).
596 .IP "\fBsrc net \fInet\fR"
597 True if the IPv4/v6 source address of the packet has a network
598 number of \fInet\fP.
599 .IP "\fBnet \fInet\fR"
600 True if either the IPv4/v6 source or destination address of the packet has a network
601 number of \fInet\fP.
602 .IP "\fBnet \fInet\fR \fBmask \fInetmask\fR"
603 True if the IP address matches \fInet\fR with the specific \fInetmask\fR.
604 May be qualified with \fBsrc\fR or \fBdst\fR.
605 Note that this syntax is not valid for IPv6 \fInet\fR.
606 .IP "\fBnet \fInet\fR/\fIlen\fR"
607 True if the IPv4/v6 address matches \fInet\fR with a netmask \fIlen\fR
608 bits wide.
609 May be qualified with \fBsrc\fR or \fBdst\fR.
610 .IP "\fBdst port \fIport\fR"
611 True if the packet is ip/tcp, ip/udp, ip6/tcp or ip6/udp and has a
612 destination port value of \fIport\fP.
613 The \fIport\fP can be a number or a name used in /etc/services (see
614 .IR tcp (4P)
616 .IR udp (4P)).
617 If a name is used, both the port
618 number and protocol are checked.
619 If a number or ambiguous name is used,
620 only the port number is checked (e.g., \fBdst port 513\fR will print both
621 tcp/login traffic and udp/who traffic, and \fBport domain\fR will print
622 both tcp/domain and udp/domain traffic).
623 .IP "\fBsrc port \fIport\fR"
624 True if the packet has a source port value of \fIport\fP.
625 .IP "\fBport \fIport\fR"
626 True if either the source or destination port of the packet is \fIport\fP.
627 Any of the above port expressions can be prepended with the keywords,
628 \fBtcp\fP or \fBudp\fP, as in:
629 .in +.5i
631 \fBtcp src port \fIport\fR
633 .in -.5i
634 which matches only tcp packets whose source port is \fIport\fP.
635 .IP "\fBless \fIlength\fR"
636 True if the packet has a length less than or equal to \fIlength\fP.
637 This is equivalent to:
638 .in +.5i
640 \fBlen <= \fIlength\fP.
642 .in -.5i
643 .IP "\fBgreater \fIlength\fR"
644 True if the packet has a length greater than or equal to \fIlength\fP.
645 This is equivalent to:
646 .in +.5i
648 \fBlen >= \fIlength\fP.
650 .in -.5i
651 .IP "\fBip proto \fIprotocol\fR"
652 True if the packet is an IP packet (see
653 .IR ip (4P))
654 of protocol type \fIprotocol\fP.
655 \fIProtocol\fP can be a number or one of the names
656 \fIicmp\fP, \fIicmp6\fP, \fIigmp\fP, \fIigrp\fP, \fIpim\fP, \fIah\fP,
657 \fIesp\fP, \fIvrrp\fP, \fIudp\fP, or \fItcp\fP.
658 Note that the identifiers \fItcp\fP, \fIudp\fP, and \fIicmp\fP are also
659 keywords and must be escaped via backslash (\\), which is \\\\ in the C-shell.
660 Note that this primitive does not chase the protocol header chain.
661 .IP "\fBip6 proto \fIprotocol\fR"
662 True if the packet is an IPv6 packet of protocol type \fIprotocol\fP.
663 Note that this primitive does not chase the protocol header chain.
664 .IP "\fBip6 protochain \fIprotocol\fR"
665 True if the packet is IPv6 packet,
666 and contains protocol header with type \fIprotocol\fR
667 in its protocol header chain.
668 For example,
669 .in +.5i
671 \fBip6 protochain 6\fR
673 .in -.5i
674 matches any IPv6 packet with TCP protocol header in the protocol header chain.
675 The packet may contain, for example,
676 authentication header, routing header, or hop-by-hop option header,
677 between IPv6 header and TCP header.
678 The BPF code emitted by this primitive is complex and
679 cannot be optimized by BPF optimizer code in \fItcpdump\fP,
680 so this can be somewhat slow.
681 .IP "\fBip protochain \fIprotocol\fR"
682 Equivalent to \fBip6 protochain \fIprotocol\fR, but this is for IPv4.
683 .IP "\fBether broadcast\fR"
684 True if the packet is an ethernet broadcast packet.
685 The \fIether\fP
686 keyword is optional.
687 .IP "\fBip broadcast\fR"
688 True if the packet is an IP broadcast packet.
689 It checks for both
690 the all-zeroes and all-ones broadcast conventions, and looks up
691 the local subnet mask.
692 .IP "\fBether multicast\fR"
693 True if the packet is an ethernet multicast packet.
694 The \fIether\fP
695 keyword is optional.
696 This is shorthand for `\fBether[0] & 1 != 0\fP'.
697 .IP "\fBip multicast\fR"
698 True if the packet is an IP multicast packet.
699 .IP "\fBip6 multicast\fR"
700 True if the packet is an IPv6 multicast packet.
701 .IP  "\fBether proto \fIprotocol\fR"
702 True if the packet is of ether type \fIprotocol\fR.
703 \fIProtocol\fP can be a number or one of the names
704 \fIip\fP, \fIip6\fP, \fIarp\fP, \fIrarp\fP, \fIatalk\fP, \fIaarp\fP,
705 \fIdecnet\fP, \fIsca\fP, \fIlat\fP, \fImopdl\fP, \fImoprc\fP,
706 \fIiso\fP, \fIstp\fP, \fIipx\fP, or \fInetbeui\fP.
707 Note these identifiers are also keywords
708 and must be escaped via backslash (\\).
710 [In the case of FDDI (e.g., `\fBfddi protocol arp\fR') and Token Ring
711 (e.g., `\fBtr protocol arp\fR'), for most of those protocols, the
712 protocol identification comes from the 802.2 Logical Link Control (LLC)
713 header, which is usually layered on top of the FDDI or Token Ring
714 header.
716 When filtering for most protocol identifiers on FDDI or Token Ring,
717 \fItcpdump\fR checks only the protocol ID field of an LLC header in
718 so-called SNAP format with an Organizational Unit Identifier (OUI) of
719 0x000000, for encapsulated Ethernet; it doesn't check whether the packet
720 is in SNAP format with an OUI of 0x000000.
722 The exceptions are \fIiso\fP, for which it checks the DSAP (Destination
723 Service Access Point) and SSAP (Source Service Access Point) fields of
724 the LLC header, \fIstp\fP and \fInetbeui\fP, where it checks the DSAP of
725 the LLC header, and \fIatalk\fP, where it checks for a SNAP-format
726 packet with an OUI of 0x080007 and the Appletalk etype.
728 In the case of Ethernet, \fItcpdump\fR checks the Ethernet type field
729 for most of those protocols; the exceptions are \fIiso\fP, \fIsap\fP,
730 and \fInetbeui\fP, for which it checks for an 802.3 frame and then
731 checks the LLC header as it does for FDDI and Token Ring, \fIatalk\fP,
732 where it checks both for the Appletalk etype in an Ethernet frame and
733 for a SNAP-format packet as it does for FDDI and Token Ring, \fIaarp\fP,
734 where it checks for the Appletalk ARP etype in either an Ethernet frame
735 or an 802.2 SNAP frame with an OUI of 0x000000, and \fIipx\fP, where it
736 checks for the IPX etype in an Ethernet frame, the IPX DSAP in the LLC
737 header, the 802.3 with no LLC header encapsulation of IPX, and the IPX
738 etype in a SNAP frame.]
739 .IP "\fBdecnet src \fIhost\fR"
740 True if the DECNET source address is
741 .IR host ,
742 which may be an address of the form ``10.123'', or a DECNET host
743 name.
744 [DECNET host name support is only available on Ultrix systems
745 that are configured to run DECNET.]
746 .IP "\fBdecnet dst \fIhost\fR"
747 True if the DECNET destination address is
748 .IR host .
749 .IP "\fBdecnet host \fIhost\fR"
750 True if either the DECNET source or destination address is
751 .IR host .
752 .IP "\fBip\fR, \fBip6\fR, \fBarp\fR, \fBrarp\fR, \fBatalk\fR, \fBaarp\fR, \fBdecnet\fR, \fBiso\fR, \fBstp\fR, \fBipx\fR, \fInetbeui\fP"
753 Abbreviations for:
754 .in +.5i
756 \fBether proto \fIp\fR
758 .in -.5i
759 where \fIp\fR is one of the above protocols.
760 .IP "\fBlat\fR, \fBmoprc\fR, \fBmopdl\fR"
761 Abbreviations for:
762 .in +.5i
764 \fBether proto \fIp\fR
766 .in -.5i
767 where \fIp\fR is one of the above protocols.
768 Note that
769 \fItcpdump\fP does not currently know how to parse these protocols.
770 .IP "\fBvlan \fI[vlan_id]\fR"
771 True if the packet is an IEEE 802.1Q VLAN packet.
772 If \fI[vlan_id]\fR is specified, only true is the packet has the specified
773 \fIvlan_id\fR.
774 Note that the first \fBvlan\fR keyword encountered in \fIexpression\fR
775 changes the decoding offsets for the remainder of \fIexpression\fR
776 on the assumption that the packet is a VLAN packet.
777 .IP  "\fBtcp\fR, \fBudp\fR, \fBicmp\fR"
778 Abbreviations for:
779 .in +.5i
781 \fBip proto \fIp\fR\fB or ip6 proto \fIp\fR
783 .in -.5i
784 where \fIp\fR is one of the above protocols.
785 .IP "\fBiso proto \fIprotocol\fR"
786 True if the packet is an OSI packet of protocol type \fIprotocol\fP.
787 \fIProtocol\fP can be a number or one of the names
788 \fIclnp\fP, \fIesis\fP, or \fIisis\fP.
789 .IP "\fBclnp\fR, \fBesis\fR, \fBisis\fR"
790 Abbreviations for:
791 .in +.5i
793 \fBiso proto \fIp\fR
795 .in -.5i
796 where \fIp\fR is one of the above protocols.
797 Note that \fItcpdump\fR does an incomplete job of parsing these protocols.
798 .IP  "\fIexpr relop expr\fR"
799 True if the relation holds, where \fIrelop\fR is one of >, <, >=, <=, =, !=,
800 and \fIexpr\fR is an arithmetic expression composed of integer constants
801 (expressed in standard C syntax), the normal binary operators
802 [+, -, *, /, &, |], a length operator, and special packet data accessors.
803 To access
804 data inside the packet, use the following syntax:
805 .in +.5i
807 \fIproto\fB [ \fIexpr\fB : \fIsize\fB ]\fR
809 .in -.5i
810 \fIProto\fR is one of \fBether, fddi, tr, ppp, slip, link,
811 ip, arp, rarp, tcp, udp, icmp\fR or \fBip6\fR, and
812 indicates the protocol layer for the index operation.
813 (\fBether, fddi, tr, ppp, slip\fR and \fBlink\fR all refer to the link
814 layer.)
815 Note that \fItcp, udp\fR and other upper-layer protocol types only
816 apply to IPv4, not IPv6 (this will be fixed in the future).
817 The byte offset, relative to the indicated protocol layer, is
818 given by \fIexpr\fR.
819 \fISize\fR is optional and indicates the number of bytes in the
820 field of interest; it can be either one, two, or four, and defaults to one.
821 The length operator, indicated by the keyword \fBlen\fP, gives the
822 length of the packet.
824 For example, `\fBether[0] & 1 != 0\fP' catches all multicast traffic.
825 The expression `\fBip[0] & 0xf != 5\fP'
826 catches all IP packets with options.
827 The expression
828 `\fBip[6:2] & 0x1fff = 0\fP'
829 catches only unfragmented datagrams and frag zero of fragmented datagrams.
830 This check is implicitly applied to the \fBtcp\fP and \fBudp\fP
831 index operations.
832 For instance, \fBtcp[0]\fP always means the first
833 byte of the TCP \fIheader\fP, and never means the first byte of an
834 intervening fragment.
836 Some offsets and field values may be expressed as names rather than
837 as numeric values.
838 The following protocol header field offsets are
839 available: \fBicmptype\fP (ICMP type field), \fBicmpcode\fP (ICMP
840 code field), and \fBtcpflags\fP (TCP flags field).
842 The following ICMP type field values are available: \fBicmp-echoreply\fP,
843 \fBicmp-unreach\fP, \fBicmp-sourcequench\fP, \fBicmp-redirect\fP,
844 \fBicmp-echo\fP, \fBicmp-routeradvert\fP, \fBicmp-routersolicit\fP,
845 \fBicmp-timxceed\fP, \fBicmp-paramprob\fP, \fBicmp-tstamp\fP,
846 \fBicmp-tstampreply\fP, \fBicmp-ireq\fP, \fBicmp-ireqreply\fP,
847 \fBicmp-maskreq\fP, \fBicmp-maskreply\fP.
849 The following TCP flags field values are available: \fBtcp-fin\fP,
850 \fBtcp-syn\fP, \fBtcp-rst\fP, \fBtcp-push\fP, \fBtcp-push\fP,
851 \fBtcp-ack\fP, \fBtcp-urg\fP.
853 Primitives may be combined using:
855 A parenthesized group of primitives and operators
856 (parentheses are special to the Shell and must be escaped).
858 Negation (`\fB!\fP' or `\fBnot\fP').
860 Concatenation (`\fB&&\fP' or `\fBand\fP').
862 Alternation (`\fB||\fP' or `\fBor\fP').
864 Negation has highest precedence.
865 Alternation and concatenation have equal precedence and associate
866 left to right.
867 Note that explicit \fBand\fR tokens, not juxtaposition,
868 are now required for concatenation.
870 If an identifier is given without a keyword, the most recent keyword
871 is assumed.
872 For example,
873 .in +.5i
875 \fBnot host vs and ace\fR
877 .in -.5i
878 is short for
879 .in +.5i
881 \fBnot host vs and host ace\fR
883 .in -.5i
884 which should not be confused with
885 .in +.5i
887 \fBnot ( host vs or ace )\fR
889 .in -.5i
891 Expression arguments can be passed to \fItcpdump\fP as either a single
892 argument or as multiple arguments, whichever is more convenient.
893 Generally, if the expression contains Shell metacharacters, it is
894 easier to pass it as a single, quoted argument.
895 Multiple arguments are concatenated with spaces before being parsed.
896 .SH EXAMPLES
898 To print all packets arriving at or departing from \fIsundown\fP:
901 \fBtcpdump host sundown\fP
905 To print traffic between \fIhelios\fR and either \fIhot\fR or \fIace\fR:
908 \fBtcpdump host helios and \\( hot or ace \\)\fP
912 To print all IP packets between \fIace\fR and any host except \fIhelios\fR:
915 \fBtcpdump ip host ace and not helios\fP
919 To print all traffic between local hosts and hosts at Berkeley:
923 tcpdump net ucb-ether
927 To print all ftp traffic through internet gateway \fIsnup\fP:
928 (note that the expression is quoted to prevent the shell from
929 (mis-)interpreting the parentheses):
933 tcpdump 'gateway snup and (port ftp or ftp-data)'
937 To print traffic neither sourced from nor destined for local hosts
938 (if you gateway to one other net, this stuff should never make it
939 onto your local net).
943 tcpdump ip and not net \fIlocalnet\fP
947 To print the start and end packets (the SYN and FIN packets) of each
948 TCP conversation that involves a non-local host.
952 tcpdump 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net \fIlocalnet\fP'
956 To print IP packets longer than 576 bytes sent through gateway \fIsnup\fP:
960 tcpdump 'gateway snup and ip[2:2] > 576'
964 To print IP broadcast or multicast packets that were
965 .I not
966 sent via ethernet broadcast or multicast:
970 tcpdump 'ether[0] & 1 = 0 and ip[16] >= 224'
974 To print all ICMP packets that are not echo requests/replies (i.e., not
975 ping packets):
979 tcpdump 'icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply'
982 .SH OUTPUT FORMAT
984 The output of \fItcpdump\fP is protocol dependent.
985 The following
986 gives a brief description and examples of most of the formats.
987 .de HD
988 .sp 1.5
992 Link Level Headers
994 If the '-e' option is given, the link level header is printed out.
995 On ethernets, the source and destination addresses, protocol,
996 and packet length are printed.
998 On FDDI networks, the  '-e' option causes \fItcpdump\fP to print
999 the `frame control' field,  the source and destination addresses,
1000 and the packet length.
1001 (The `frame control' field governs the
1002 interpretation of the rest of the packet.
1003 Normal packets (such
1004 as those containing IP datagrams) are `async' packets, with a priority
1005 value between 0 and 7; for example, `\fBasync4\fR'.
1006 Such packets
1007 are assumed to contain an 802.2 Logical Link Control (LLC) packet;
1008 the LLC header is printed if it is \fInot\fR an ISO datagram or a
1009 so-called SNAP packet.
1011 On Token Ring networks, the '-e' option causes \fItcpdump\fP to print
1012 the `access control' and `frame control' fields, the source and
1013 destination addresses, and the packet length.
1014 As on FDDI networks,
1015 packets are assumed to contain an LLC packet.
1016 Regardless of whether
1017 the '-e' option is specified or not, the source routing information is
1018 printed for source-routed packets.
1020 \fI(N.B.: The following description assumes familiarity with
1021 the SLIP compression algorithm described in RFC-1144.)\fP
1023 On SLIP links, a direction indicator (``I'' for inbound, ``O'' for outbound),
1024 packet type, and compression information are printed out.
1025 The packet type is printed first.
1026 The three types are \fIip\fP, \fIutcp\fP, and \fIctcp\fP.
1027 No further link information is printed for \fIip\fR packets.
1028 For TCP packets, the connection identifier is printed following the type.
1029 If the packet is compressed, its encoded header is printed out.
1030 The special cases are printed out as
1031 \fB*S+\fIn\fR and \fB*SA+\fIn\fR, where \fIn\fR is the amount by which
1032 the sequence number (or sequence number and ack) has changed.
1033 If it is not a special case,
1034 zero or more changes are printed.
1035 A change is indicated by U (urgent pointer), W (window), A (ack),
1036 S (sequence number), and I (packet ID), followed by a delta (+n or -n),
1037 or a new value (=n).
1038 Finally, the amount of data in the packet and compressed header length
1039 are printed.
1041 For example, the following line shows an outbound compressed TCP packet,
1042 with an implicit connection identifier; the ack has changed by 6,
1043 the sequence number by 49, and the packet ID by 6; there are 3 bytes of
1044 data and 6 bytes of compressed header:
1047 \fBO ctcp * A+6 S+49 I+6 3 (6)\fP
1051 ARP/RARP Packets
1053 Arp/rarp output shows the type of request and its arguments.
1055 format is intended to be self explanatory.
1056 Here is a short sample taken from the start of an `rlogin' from
1057 host \fIrtsg\fP to host \fIcsam\fP:
1060 .sp .5
1061 \f(CWarp who-has csam tell rtsg
1062 arp reply csam is-at CSAM\fR
1063 .sp .5
1066 The first line says that rtsg sent an arp packet asking
1067 for the ethernet address of internet host csam.
1068 Csam
1069 replies with its ethernet address (in this example, ethernet addresses
1070 are in caps and internet addresses in lower case).
1072 This would look less redundant if we had done \fItcpdump \-n\fP:
1075 .sp .5
1076 \f(CWarp who-has 128.3.254.6 tell 128.3.254.68
1077 arp reply 128.3.254.6 is-at 02:07:01:00:01:c4\fP
1081 If we had done \fItcpdump \-e\fP, the fact that the first packet is
1082 broadcast and the second is point-to-point would be visible:
1085 .sp .5
1086 \f(CWRTSG Broadcast 0806  64: arp who-has csam tell rtsg
1087 CSAM RTSG 0806  64: arp reply csam is-at CSAM\fR
1088 .sp .5
1091 For the first packet this says the ethernet source address is RTSG, the
1092 destination is the ethernet broadcast address, the type field
1093 contained hex 0806 (type ETHER_ARP) and the total length was 64 bytes.
1095 TCP Packets
1097 \fI(N.B.:The following description assumes familiarity with
1098 the TCP protocol described in RFC-793.
1099 If you are not familiar
1100 with the protocol, neither this description nor \fItcpdump\fP will
1101 be of much use to you.)\fP
1103 The general format of a tcp protocol line is:
1106 .sp .5
1107 \fIsrc > dst: flags data-seqno ack window urgent options\fP
1108 .sp .5
1111 \fISrc\fP and \fIdst\fP are the source and destination IP
1112 addresses and ports.
1113 \fIFlags\fP are some combination of S (SYN),
1114 F (FIN), P (PUSH) or R (RST) or a single `.' (no flags).
1115 \fIData-seqno\fP describes the portion of sequence space covered
1116 by the data in this packet (see example below).
1117 \fIAck\fP is sequence number of the next data expected the other
1118 direction on this connection.
1119 \fIWindow\fP is the number of bytes of receive buffer space available
1120 the other direction on this connection.
1121 \fIUrg\fP indicates there is `urgent' data in the packet.
1122 \fIOptions\fP are tcp options enclosed in angle brackets (e.g., <mss 1024>).
1124 \fISrc, dst\fP and \fIflags\fP are always present.
1125 The other fields
1126 depend on the contents of the packet's tcp protocol header and
1127 are output only if appropriate.
1129 Here is the opening portion of an rlogin from host \fIrtsg\fP to
1130 host \fIcsam\fP.
1133 .sp .5
1134 \s-2\f(CWrtsg.1023 > csam.login: S 768512:768512(0) win 4096 <mss 1024>
1135 csam.login > rtsg.1023: S 947648:947648(0) ack 768513 win 4096 <mss 1024>
1136 rtsg.1023 > csam.login: . ack 1 win 4096
1137 rtsg.1023 > csam.login: P 1:2(1) ack 1 win 4096
1138 csam.login > rtsg.1023: . ack 2 win 4096
1139 rtsg.1023 > csam.login: P 2:21(19) ack 1 win 4096
1140 csam.login > rtsg.1023: P 1:2(1) ack 21 win 4077
1141 csam.login > rtsg.1023: P 2:3(1) ack 21 win 4077 urg 1
1142 csam.login > rtsg.1023: P 3:4(1) ack 21 win 4077 urg 1\fR\s+2
1143 .sp .5
1146 The first line says that tcp port 1023 on rtsg sent a packet
1147 to port \fIlogin\fP
1148 on csam.
1149 The \fBS\fP indicates that the \fISYN\fP flag was set.
1150 The packet sequence number was 768512 and it contained no data.
1151 (The notation is `first:last(nbytes)' which means `sequence
1152 numbers \fIfirst\fP
1153 up to but not including \fIlast\fP which is \fInbytes\fP bytes of user data'.)
1154 There was no piggy-backed ack, the available receive window was 4096
1155 bytes and there was a max-segment-size option requesting an mss of
1156 1024 bytes.
1158 Csam replies with a similar packet except it includes a piggy-backed
1159 ack for rtsg's SYN.
1160 Rtsg then acks csam's SYN.
1161 The `.' means no
1162 flags were set.
1163 The packet contained no data so there is no data sequence number.
1164 Note that the ack sequence
1165 number is a small integer (1).
1166 The first time \fItcpdump\fP sees a
1167 tcp `conversation', it prints the sequence number from the packet.
1168 On subsequent packets of the conversation, the difference between
1169 the current packet's sequence number and this initial sequence number
1170 is printed.
1171 This means that sequence numbers after the
1172 first can be interpreted
1173 as relative byte positions in the conversation's data stream (with the
1174 first data byte each direction being `1').
1175 `-S' will override this
1176 feature, causing the original sequence numbers to be output.
1178 On the 6th line, rtsg sends csam 19 bytes of data (bytes 2 through 20
1179 in the rtsg \(-> csam side of the conversation).
1180 The PUSH flag is set in the packet.
1181 On the 7th line, csam says it's received data sent by rtsg up to
1182 but not including byte 21.
1183 Most of this data is apparently sitting in the
1184 socket buffer since csam's receive window has gotten 19 bytes smaller.
1185 Csam also sends one byte of data to rtsg in this packet.
1186 On the 8th and 9th lines,
1187 csam sends two bytes of urgent, pushed data to rtsg.
1189 If the snapshot was small enough that \fItcpdump\fP didn't capture
1190 the full TCP header, it interprets as much of the header as it can
1191 and then reports ``[|\fItcp\fP]'' to indicate the remainder could not
1192 be interpreted.
1193 If the header contains a bogus option (one with a length
1194 that's either too small or beyond the end of the header), \fItcpdump\fP
1195 reports it as ``[\fIbad opt\fP]'' and does not interpret any further
1196 options (since it's impossible to tell where they start).
1197 If the header
1198 length indicates options are present but the IP datagram length is not
1199 long enough for the options to actually be there, \fItcpdump\fP reports
1200 it as ``[\fIbad hdr length\fP]''.
1202 .B Capturing TCP packets with particular flag combinations (SYN-ACK, URG-ACK, etc.)
1204 There are 8 bits in the control bits section of the TCP header:
1206 .I CWR | ECE | URG | ACK | PSH | RST | SYN | FIN
1208 Let's assume that we want to watch packets used in establishing
1209 a TCP connection.
1210 Recall that TCP uses a 3-way handshake protocol
1211 when it initializes a new connection; the connection sequence with
1212 regard to the TCP control bits is
1215 1) Caller sends SYN
1218 2) Recipient responds with SYN, ACK
1221 3) Caller sends ACK
1224 Now we're interested in capturing packets that have only the
1225 SYN bit set (Step 1).
1226 Note that we don't want packets from step 2
1227 (SYN-ACK), just a plain initial SYN.
1228 What we need is a correct filter
1229 expression for \fItcpdump\fP.
1231 Recall the structure of a TCP header without options:
1234  0                            15                              31
1235 -----------------------------------------------------------------
1236 |          source port          |       destination port        |
1237 -----------------------------------------------------------------
1238 |                        sequence number                        |
1239 -----------------------------------------------------------------
1240 |                     acknowledgment number                     |
1241 -----------------------------------------------------------------
1242 |  HL   | rsvd  |C|E|U|A|P|R|S|F|        window size            |
1243 -----------------------------------------------------------------
1244 |         TCP checksum          |       urgent pointer          |
1245 -----------------------------------------------------------------
1248 A TCP header usually holds 20 octets of data, unless options are
1249 present.
1250 The first line of the graph contains octets 0 - 3, the
1251 second line shows octets 4 - 7 etc.
1253 Starting to count with 0, the relevant TCP control bits are contained
1254 in octet 13:
1257  0             7|             15|             23|             31
1258 ----------------|---------------|---------------|----------------
1259 |  HL   | rsvd  |C|E|U|A|P|R|S|F|        window size            |
1260 ----------------|---------------|---------------|----------------
1261 |               |  13th octet   |               |               |
1264 Let's have a closer look at octet no. 13:
1267                 |               |
1268                 |---------------|
1269                 |C|E|U|A|P|R|S|F|
1270                 |---------------|
1271                 |7   5   3     0|
1274 These are the TCP control bits we are interested
1276 We have numbered the bits in this octet from 0 to 7, right to
1277 left, so the PSH bit is bit number 3, while the URG bit is number 5.
1279 Recall that we want to capture packets with only SYN set.
1280 Let's see what happens to octet 13 if a TCP datagram arrives
1281 with the SYN bit set in its header:
1284                 |C|E|U|A|P|R|S|F|
1285                 |---------------|
1286                 |0 0 0 0 0 0 1 0|
1287                 |---------------|
1288                 |7 6 5 4 3 2 1 0|
1291 Looking at the
1292 control bits section we see that only bit number 1 (SYN) is set.
1294 Assuming that octet number 13 is an 8-bit unsigned integer in
1295 network byte order, the binary value of this octet is
1297 00000010
1299 and its decimal representation is
1302    7     6     5     4     3     2     1     0
1303 0*2 + 0*2 + 0*2 + 0*2 + 0*2 + 0*2 + 1*2 + 0*2  =  2
1306 We're almost done, because now we know that if only SYN is set,
1307 the value of the 13th octet in the TCP header, when interpreted
1308 as a 8-bit unsigned integer in network byte order, must be exactly 2.
1310 This relationship can be expressed as
1313 tcp[13] == 2
1316 We can use this expression as the filter for \fItcpdump\fP in order
1317 to watch packets which have only SYN set:
1320 tcpdump -i xl0 tcp[13] == 2
1323 The expression says "let the 13th octet of a TCP datagram have
1324 the decimal value 2", which is exactly what we want.
1326 Now, let's assume that we need to capture SYN packets, but we
1327 don't care if ACK or any other TCP control bit is set at the
1328 same time.
1329 Let's see what happens to octet 13 when a TCP datagram
1330 with SYN-ACK set arrives:
1333      |C|E|U|A|P|R|S|F|
1334      |---------------|
1335      |0 0 0 1 0 0 1 0|
1336      |---------------|
1337      |7 6 5 4 3 2 1 0|
1340 Now bits 1 and 4 are set in the 13th octet.
1341 The binary value of
1342 octet 13 is
1344      00010010
1346 which translates to decimal
1349    7     6     5     4     3     2     1     0
1350 0*2 + 0*2 + 0*2 + 1*2 + 0*2 + 0*2 + 1*2 + 0*2   = 18
1353 Now we can't just use 'tcp[13] == 18' in the \fItcpdump\fP filter
1354 expression, because that would select only those packets that have
1355 SYN-ACK set, but not those with only SYN set.
1356 Remember that we don't care
1357 if ACK or any other control bit is set as long as SYN is set.
1359 In order to achieve our goal, we need to logically AND the
1360 binary value of octet 13 with some other value to preserve
1361 the SYN bit.
1362 We know that we want SYN to be set in any case,
1363 so we'll logically AND the value in the 13th octet with
1364 the binary value of a SYN:
1368           00010010 SYN-ACK              00000010 SYN
1369      AND  00000010 (we want SYN)   AND  00000010 (we want SYN)
1370           --------                      --------
1371      =    00000010                 =    00000010
1374 We see that this AND operation delivers the same result
1375 regardless whether ACK or another TCP control bit is set.
1376 The decimal representation of the AND value as well as
1377 the result of this operation is 2 (binary 00000010),
1378 so we know that for packets with SYN set the following
1379 relation must hold true:
1381 ( ( value of octet 13 ) AND ( 2 ) ) == ( 2 )
1383 This points us to the \fItcpdump\fP filter expression
1386      tcpdump -i xl0 'tcp[13] & 2 == 2'
1389 Note that you should use single quotes or a backslash
1390 in the expression to hide the AND ('&') special character
1391 from the shell.
1394 UDP Packets
1396 UDP format is illustrated by this rwho packet:
1399 .sp .5
1400 \f(CWactinide.who > broadcast.who: udp 84\fP
1401 .sp .5
1404 This says that port \fIwho\fP on host \fIactinide\fP sent a udp
1405 datagram to port \fIwho\fP on host \fIbroadcast\fP, the Internet
1406 broadcast address.
1407 The packet contained 84 bytes of user data.
1409 Some UDP services are recognized (from the source or destination
1410 port number) and the higher level protocol information printed.
1411 In particular, Domain Name service requests (RFC-1034/1035) and Sun
1412 RPC calls (RFC-1050) to NFS.
1414 UDP Name Server Requests
1416 \fI(N.B.:The following description assumes familiarity with
1417 the Domain Service protocol described in RFC-1035.
1418 If you are not familiar
1419 with the protocol, the following description will appear to be written
1420 in greek.)\fP
1422 Name server requests are formatted as
1425 .sp .5
1426 \fIsrc > dst: id op? flags qtype qclass name (len)\fP
1427 .sp .5
1428 \f(CWh2opolo.1538 > helios.domain: 3+ A? ucbvax.berkeley.edu. (37)\fR
1429 .sp .5
1432 Host \fIh2opolo\fP asked the domain server on \fIhelios\fP for an
1433 address record (qtype=A) associated with the name \fIucbvax.berkeley.edu.\fP
1434 The query id was `3'.
1435 The `+' indicates the \fIrecursion desired\fP flag
1436 was set.
1437 The query length was 37 bytes, not including the UDP and
1438 IP protocol headers.
1439 The query operation was the normal one, \fIQuery\fP,
1440 so the op field was omitted.
1441 If the op had been anything else, it would
1442 have been printed between the `3' and the `+'.
1443 Similarly, the qclass was the normal one,
1444 \fIC_IN\fP, and omitted.
1445 Any other qclass would have been printed
1446 immediately after the `A'.
1448 A few anomalies are checked and may result in extra fields enclosed in
1449 square brackets:  If a query contains an answer, authority records or
1450 additional records section,
1451 .IR ancount ,
1452 .IR nscount ,
1454 .I arcount
1455 are printed as `[\fIn\fPa]', `[\fIn\fPn]' or  `[\fIn\fPau]' where \fIn\fP
1456 is the appropriate count.
1457 If any of the response bits are set (AA, RA or rcode) or any of the
1458 `must be zero' bits are set in bytes two and three, `[b2&3=\fIx\fP]'
1459 is printed, where \fIx\fP is the hex value of header bytes two and three.
1461 UDP Name Server Responses
1463 Name server responses are formatted as
1466 .sp .5
1467 \fIsrc > dst:  id op rcode flags a/n/au type class data (len)\fP
1468 .sp .5
1469 \f(CWhelios.domain > h2opolo.1538: 3 3/3/7 A 128.32.137.3 (273)
1470 helios.domain > h2opolo.1537: 2 NXDomain* 0/1/0 (97)\fR
1471 .sp .5
1474 In the first example, \fIhelios\fP responds to query id 3 from \fIh2opolo\fP
1475 with 3 answer records, 3 name server records and 7 additional records.
1476 The first answer record is type A (address) and its data is internet
1477 address 128.32.137.3.
1478 The total size of the response was 273 bytes,
1479 excluding UDP and IP headers.
1480 The op (Query) and response code
1481 (NoError) were omitted, as was the class (C_IN) of the A record.
1483 In the second example, \fIhelios\fP responds to query 2 with a
1484 response code of non-existent domain (NXDomain) with no answers,
1485 one name server and no authority records.
1486 The `*' indicates that
1487 the \fIauthoritative answer\fP bit was set.
1488 Since there were no
1489 answers, no type, class or data were printed.
1491 Other flag characters that might appear are `\-' (recursion available,
1492 RA, \fInot\fP set) and `|' (truncated message, TC, set).
1493 If the
1494 `question' section doesn't contain exactly one entry, `[\fIn\fPq]'
1495 is printed.
1497 Note that name server requests and responses tend to be large and the
1498 default \fIsnaplen\fP of 68 bytes may not capture enough of the packet
1499 to print.
1500 Use the \fB\-s\fP flag to increase the snaplen if you
1501 need to seriously investigate name server traffic.
1502 `\fB\-s 128\fP'
1503 has worked well for me.
1506 SMB/CIFS decoding
1508 \fItcpdump\fP now includes fairly extensive SMB/CIFS/NBT decoding for data
1509 on UDP/137, UDP/138 and TCP/139.
1510 Some primitive decoding of IPX and
1511 NetBEUI SMB data is also done.
1513 By default a fairly minimal decode is done, with a much more detailed
1514 decode done if -v is used.
1515 Be warned that with -v a single SMB packet
1516 may take up a page or more, so only use -v if you really want all the
1517 gory details.
1519 If you are decoding SMB sessions containing unicode strings then you
1520 may wish to set the environment variable USE_UNICODE to 1.
1521 A patch to
1522 auto-detect unicode srings would be welcome.
1524 For information on SMB packet formats and what all te fields mean see
1525 www.cifs.org or the pub/samba/specs/ directory on your favourite
1526 samba.org mirror site.
1527 The SMB patches were written by Andrew Tridgell
1528 (tridge@samba.org).
1531 NFS Requests and Replies
1533 Sun NFS (Network File System) requests and replies are printed as:
1536 .sp .5
1537 \fIsrc.xid > dst.nfs: len op args\fP
1538 \fIsrc.nfs > dst.xid: reply stat len op results\fP
1539 .sp .5
1540 \f(CW
1541 sushi.6709 > wrl.nfs: 112 readlink fh 21,24/10.73165
1542 wrl.nfs > sushi.6709: reply ok 40 readlink "../var"
1543 sushi.201b > wrl.nfs:
1544         144 lookup fh 9,74/4096.6878 "xcolors"
1545 wrl.nfs > sushi.201b:
1546         reply ok 128 lookup fh 9,74/4134.3150
1548 .sp .5
1551 In the first line, host \fIsushi\fP sends a transaction with id \fI6709\fP
1552 to \fIwrl\fP (note that the number following the src host is a
1553 transaction id, \fInot\fP the source port).
1554 The request was 112 bytes,
1555 excluding the UDP and IP headers.
1556 The operation was a \fIreadlink\fP
1557 (read symbolic link) on file handle (\fIfh\fP) 21,24/10.731657119.
1558 (If one is lucky, as in this case, the file handle can be interpreted
1559 as a major,minor device number pair, followed by the inode number and
1560 generation number.)
1561 \fIWrl\fP replies `ok' with the contents of the link.
1563 In the third line, \fIsushi\fP asks \fIwrl\fP to lookup the name
1564 `\fIxcolors\fP' in directory file 9,74/4096.6878.
1565 Note that the data printed
1566 depends on the operation type.
1567 The format is intended to be self
1568 explanatory if read in conjunction with
1569 an NFS protocol spec.
1571 If the \-v (verbose) flag is given, additional information is printed.
1572 For example:
1575 .sp .5
1576 \f(CW
1577 sushi.1372a > wrl.nfs:
1578         148 read fh 21,11/12.195 8192 bytes @ 24576
1579 wrl.nfs > sushi.1372a:
1580         reply ok 1472 read REG 100664 ids 417/0 sz 29388
1582 .sp .5
1585 (\-v also prints the IP header TTL, ID, length, and fragmentation fields,
1586 which have been omitted from this example.)  In the first line,
1587 \fIsushi\fP asks \fIwrl\fP to read 8192 bytes from file 21,11/12.195,
1588 at byte offset 24576.
1589 \fIWrl\fP replies `ok'; the packet shown on the
1590 second line is the first fragment of the reply, and hence is only 1472
1591 bytes long (the other bytes will follow in subsequent fragments, but
1592 these fragments do not have NFS or even UDP headers and so might not be
1593 printed, depending on the filter expression used).
1594 Because the \-v flag
1595 is given, some of the file attributes (which are returned in addition
1596 to the file data) are printed: the file type (``REG'', for regular file),
1597 the file mode (in octal), the uid and gid, and the file size.
1599 If the \-v flag is given more than once, even more details are printed.
1601 Note that NFS requests are very large and much of the detail won't be printed
1602 unless \fIsnaplen\fP is increased.
1603 Try using `\fB\-s 192\fP' to watch
1604 NFS traffic.
1606 NFS reply packets do not explicitly identify the RPC operation.
1607 Instead,
1608 \fItcpdump\fP keeps track of ``recent'' requests, and matches them to the
1609 replies using the transaction ID.
1610 If a reply does not closely follow the
1611 corresponding request, it might not be parsable.
1613 AFS Requests and Replies
1615 Transarc AFS (Andrew File System) requests and replies are printed
1620 .sp .5
1621 \fIsrc.sport > dst.dport: rx packet-type\fP
1622 \fIsrc.sport > dst.dport: rx packet-type service call call-name args\fP
1623 \fIsrc.sport > dst.dport: rx packet-type service reply call-name args\fP
1624 .sp .5
1625 \f(CW
1626 elvis.7001 > pike.afsfs:
1627         rx data fs call rename old fid 536876964/1/1 ".newsrc.new"
1628         new fid 536876964/1/1 ".newsrc"
1629 pike.afsfs > elvis.7001: rx data fs reply rename
1631 .sp .5
1634 In the first line, host elvis sends a RX packet to pike.
1635 This was
1636 a RX data packet to the fs (fileserver) service, and is the start of
1637 an RPC call.
1638 The RPC call was a rename, with the old directory file id
1639 of 536876964/1/1 and an old filename of `.newsrc.new', and a new directory
1640 file id of 536876964/1/1 and a new filename of `.newsrc'.
1641 The host pike
1642 responds with a RPC reply to the rename call (which was successful, because
1643 it was a data packet and not an abort packet).
1645 In general, all AFS RPCs are decoded at least by RPC call name.
1646 Most
1647 AFS RPCs have at least some of the arguments decoded (generally only
1648 the `interesting' arguments, for some definition of interesting).
1650 The format is intended to be self-describing, but it will probably
1651 not be useful to people who are not familiar with the workings of
1652 AFS and RX.
1654 If the -v (verbose) flag is given twice, acknowledgement packets and
1655 additional header information is printed, such as the the RX call ID,
1656 call number, sequence number, serial number, and the RX packet flags.
1658 If the -v flag is given twice, additional information is printed,
1659 such as the the RX call ID, serial number, and the RX packet flags.
1660 The MTU negotiation information is also printed from RX ack packets.
1662 If the -v flag is given three times, the security index and service id
1663 are printed.
1665 Error codes are printed for abort packets, with the exception of Ubik
1666 beacon packets (because abort packets are used to signify a yes vote
1667 for the Ubik protocol).
1669 Note that AFS requests are very large and many of the arguments won't
1670 be printed unless \fIsnaplen\fP is increased.
1671 Try using `\fB-s 256\fP'
1672 to watch AFS traffic.
1674 AFS reply packets do not explicitly identify the RPC operation.
1675 Instead,
1676 \fItcpdump\fP keeps track of ``recent'' requests, and matches them to the
1677 replies using the call number and service ID.
1678 If a reply does not closely
1679 follow the
1680 corresponding request, it might not be parsable.
1683 KIP Appletalk (DDP in UDP)
1685 Appletalk DDP packets encapsulated in UDP datagrams are de-encapsulated
1686 and dumped as DDP packets (i.e., all the UDP header information is
1687 discarded).
1688 The file
1689 .I /etc/atalk.names
1690 is used to translate appletalk net and node numbers to names.
1691 Lines in this file have the form
1694 .sp .5
1695 \fInumber       name\fP
1697 \f(CW1.254              ether
1698 16.1            icsd-net
1699 1.254.110       ace\fR
1700 .sp .5
1703 The first two lines give the names of appletalk networks.
1704 The third
1705 line gives the name of a particular host (a host is distinguished
1706 from a net by the 3rd octet in the number \-
1707 a net number \fImust\fP have two octets and a host number \fImust\fP
1708 have three octets.)  The number and name should be separated by
1709 whitespace (blanks or tabs).
1711 .I /etc/atalk.names
1712 file may contain blank lines or comment lines (lines starting with
1713 a `#').
1715 Appletalk addresses are printed in the form
1718 .sp .5
1719 \fInet.host.port\fP
1721 \f(CW144.1.209.2 > icsd-net.112.220
1722 office.2 > icsd-net.112.220
1723 jssmag.149.235 > icsd-net.2\fR
1724 .sp .5
1727 (If the
1728 .I /etc/atalk.names
1729 doesn't exist or doesn't contain an entry for some appletalk
1730 host/net number, addresses are printed in numeric form.)
1731 In the first example, NBP (DDP port 2) on net 144.1 node 209
1732 is sending to whatever is listening on port 220 of net icsd node 112.
1733 The second line is the same except the full name of the source node
1734 is known (`office').
1735 The third line is a send from port 235 on
1736 net jssmag node 149 to broadcast on the icsd-net NBP port (note that
1737 the broadcast address (255) is indicated by a net name with no host
1738 number \- for this reason it's a good idea to keep node names and
1739 net names distinct in /etc/atalk.names).
1741 NBP (name binding protocol) and ATP (Appletalk transaction protocol)
1742 packets have their contents interpreted.
1743 Other protocols just dump
1744 the protocol name (or number if no name is registered for the
1745 protocol) and packet size.
1747 \fBNBP packets\fP are formatted like the following examples:
1750 .sp .5
1751 \s-2\f(CWicsd-net.112.220 > jssmag.2: nbp-lkup 190: "=:LaserWriter@*"
1752 jssmag.209.2 > icsd-net.112.220: nbp-reply 190: "RM1140:LaserWriter@*" 250
1753 techpit.2 > icsd-net.112.220: nbp-reply 190: "techpit:LaserWriter@*" 186\fR\s+2
1754 .sp .5
1757 The first line is a name lookup request for laserwriters sent by net icsd host
1758 112 and broadcast on net jssmag.
1759 The nbp id for the lookup is 190.
1760 The second line shows a reply for this request (note that it has the
1761 same id) from host jssmag.209 saying that it has a laserwriter
1762 resource named "RM1140" registered on port 250.
1763 The third line is
1764 another reply to the same request saying host techpit has laserwriter
1765 "techpit" registered on port 186.
1767 \fBATP packet\fP formatting is demonstrated by the following example:
1770 .sp .5
1771 \s-2\f(CWjssmag.209.165 > helios.132: atp-req  12266<0-7> 0xae030001
1772 helios.132 > jssmag.209.165: atp-resp 12266:0 (512) 0xae040000
1773 helios.132 > jssmag.209.165: atp-resp 12266:1 (512) 0xae040000
1774 helios.132 > jssmag.209.165: atp-resp 12266:2 (512) 0xae040000
1775 helios.132 > jssmag.209.165: atp-resp 12266:3 (512) 0xae040000
1776 helios.132 > jssmag.209.165: atp-resp 12266:4 (512) 0xae040000
1777 helios.132 > jssmag.209.165: atp-resp 12266:5 (512) 0xae040000
1778 helios.132 > jssmag.209.165: atp-resp 12266:6 (512) 0xae040000
1779 helios.132 > jssmag.209.165: atp-resp*12266:7 (512) 0xae040000
1780 jssmag.209.165 > helios.132: atp-req  12266<3,5> 0xae030001
1781 helios.132 > jssmag.209.165: atp-resp 12266:3 (512) 0xae040000
1782 helios.132 > jssmag.209.165: atp-resp 12266:5 (512) 0xae040000
1783 jssmag.209.165 > helios.132: atp-rel  12266<0-7> 0xae030001
1784 jssmag.209.133 > helios.132: atp-req* 12267<0-7> 0xae030002\fR\s+2
1785 .sp .5
1788 Jssmag.209 initiates transaction id 12266 with host helios by requesting
1789 up to 8 packets (the `<0-7>').
1790 The hex number at the end of the line
1791 is the value of the `userdata' field in the request.
1793 Helios responds with 8 512-byte packets.
1794 The `:digit' following the
1795 transaction id gives the packet sequence number in the transaction
1796 and the number in parens is the amount of data in the packet,
1797 excluding the atp header.
1798 The `*' on packet 7 indicates that the
1799 EOM bit was set.
1801 Jssmag.209 then requests that packets 3 & 5 be retransmitted.
1802 Helios
1803 resends them then jssmag.209 releases the transaction.
1804 Finally,
1805 jssmag.209 initiates the next request.
1806 The `*' on the request
1807 indicates that XO (`exactly once') was \fInot\fP set.
1810 IP Fragmentation
1812 Fragmented Internet datagrams are printed as
1815 .sp .5
1816 \fB(frag \fIid\fB:\fIsize\fB@\fIoffset\fB+)\fR
1817 \fB(frag \fIid\fB:\fIsize\fB@\fIoffset\fB)\fR
1818 .sp .5
1821 (The first form indicates there are more fragments.
1822 The second
1823 indicates this is the last fragment.)
1825 \fIId\fP is the fragment id.
1826 \fISize\fP is the fragment
1827 size (in bytes) excluding the IP header.
1828 \fIOffset\fP is this
1829 fragment's offset (in bytes) in the original datagram.
1831 The fragment information is output for each fragment.
1832 The first
1833 fragment contains the higher level protocol header and the frag
1834 info is printed after the protocol info.
1835 Fragments
1836 after the first contain no higher level protocol header and the
1837 frag info is printed after the source and destination addresses.
1838 For example, here is part of an ftp from arizona.edu to lbl-rtsg.arpa
1839 over a CSNET connection that doesn't appear to handle 576 byte datagrams:
1842 .sp .5
1843 \s-2\f(CWarizona.ftp-data > rtsg.1170: . 1024:1332(308) ack 1 win 4096 (frag 595a:328@0+)
1844 arizona > rtsg: (frag 595a:204@328)
1845 rtsg.1170 > arizona.ftp-data: . ack 1536 win 2560\fP\s+2
1846 .sp .5
1849 There are a couple of things to note here:  First, addresses in the
1850 2nd line don't include port numbers.
1851 This is because the TCP
1852 protocol information is all in the first fragment and we have no idea
1853 what the port or sequence numbers are when we print the later fragments.
1854 Second, the tcp sequence information in the first line is printed as if there
1855 were 308 bytes of user data when, in fact, there are 512 bytes (308 in
1856 the first frag and 204 in the second).
1857 If you are looking for holes
1858 in the sequence space or trying to match up acks
1859 with packets, this can fool you.
1861 A packet with the IP \fIdon't fragment\fP flag is marked with a
1862 trailing \fB(DF)\fP.
1864 Timestamps
1866 By default, all output lines are preceded by a timestamp.
1867 The timestamp
1868 is the current clock time in the form
1871 \fIhh:mm:ss.frac\fP
1874 and is as accurate as the kernel's clock.
1875 The timestamp reflects the time the kernel first saw the packet.
1876 No attempt
1877 is made to account for the time lag between when the
1878 ethernet interface removed the packet from the wire and when the kernel
1879 serviced the `new packet' interrupt.
1880 .SH "SEE ALSO"
1881 traffic(1C), nit(4P), bpf(4), pcap(3)
1882 .SH AUTHORS
1883 The original authors are:
1885 Van Jacobson,
1886 Craig Leres and
1887 Steven McCanne, all of the
1888 Lawrence Berkeley National Laboratory, University of California, Berkeley, CA.
1890 It is currently being maintained by tcpdump.org.
1892 The current version is available via http:
1895 .I http://www.tcpdump.org/
1898 The original distribution is available via anonymous ftp:
1901 .I ftp://ftp.ee.lbl.gov/tcpdump.tar.Z
1904 IPv6/IPsec support is added by WIDE/KAME project.
1905 This program uses Eric Young's SSLeay library, under specific configuration.
1906 .SH BUGS
1907 Please send problems, bugs, questions, desirable enhancements, etc. to:
1910 tcpdump-workers@tcpdump.org
1913 Please send source code contributions, etc. to:
1916 patches@tcpdump.org
1919 NIT doesn't let you watch your own outbound traffic, BPF will.
1920 We recommend that you use the latter.
1922 On Linux systems with 2.0[.x] kernels:
1924 packets on the loopback device will be seen twice;
1926 packet filtering cannot be done in the kernel, so that all packets must
1927 be copied from the kernel in order to be filtered in user mode;
1929 all of a packet, not just the part that's within the snapshot length,
1930 will be copied from the kernel (the 2.0[.x] packet capture mechanism, if
1931 asked to copy only part of a packet to userland, will not report the
1932 true length of the packet; this would cause most IP packets to get an
1933 error from
1934 .BR tcpdump );
1936 capturing on some PPP devices won't work correctly.
1938 We recommend that you upgrade to a 2.2 or later kernel.
1940 Some attempt should be made to reassemble IP fragments or, at least
1941 to compute the right length for the higher level protocol.
1943 Name server inverse queries are not dumped correctly: the (empty)
1944 question section is printed rather than real query in the answer
1945 section.
1946 Some believe that inverse queries are themselves a bug and
1947 prefer to fix the program generating them rather than \fItcpdump\fP.
1949 A packet trace that crosses a daylight savings time change will give
1950 skewed time stamps (the time change is ignored).
1952 Filter expressions that manipulate FDDI or Token Ring headers assume
1953 that all FDDI and Token Ring packets are SNAP-encapsulated Ethernet
1954 packets.
1955 This is true for IP, ARP, and DECNET Phase IV, but is not true
1956 for protocols such as ISO CLNS.
1957 Therefore, the filter may inadvertently
1958 accept certain packets that do not properly match the filter expression.
1960 Filter expressions on fields other than those that manipulate Token Ring
1961 headers will not correctly handle source-routed Token Ring packets.
1963 .BR "ip6 proto"
1964 should chase header chain, but at this moment it does not.
1965 .BR "ip6 protochain"
1966 is supplied for this behavior.
1968 Arithmetic expression against transport layer headers, like \fBtcp[0]\fP,
1969 does not work against IPv6 packets.
1970 It only looks at IPv4 packets.