]> The Tcpdump Group git mirrors - libpcap/blob - pcap-filter.manmisc.in
remove libpcap's own CVS keywords
[libpcap] / pcap-filter.manmisc.in
1 .\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997
2 .\" The Regents of the University of California. All rights reserved.
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that: (1) source code distributions
7 .\" retain the above copyright notice and this paragraph in its entirety, (2)
8 .\" distributions including binary code include the above copyright notice and
9 .\" this paragraph in its entirety in the documentation or other materials
10 .\" provided with the distribution, and (3) all advertising materials mentioning
11 .\" features or use of this software display the following acknowledgement:
12 .\" ``This product includes software developed by the University of California,
13 .\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 .\" the University nor the names of its contributors may be used to endorse
15 .\" or promote products derived from this software without specific prior
16 .\" written permission.
17 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 .\"
21 .TH PCAP-FILTER @MAN_MISC_INFO@ "6 January 2008"
22 .SH NAME
23 pcap-filter \- packet filter syntax
24 .br
25 .ad
26 .SH DESCRIPTION
27 .LP
28 .B pcap_compile()
29 is used to compile a string into a filter program.
30 The resulting filter program can then be applied to
31 some stream of packets to determine which packets will be supplied to
32 .BR pcap_loop() ,
33 .BR pcap_dispatch() ,
34 .BR pcap_next() ,
35 or
36 .BR pcap_next_ex() .
37 .LP
38 The \fIfilter expression\fP consists of one or more
39 .IR primitives .
40 Primitives usually consist of an
41 .I id
42 (name or number) preceded by one or more qualifiers.
43 There are three
44 different kinds of qualifier:
45 .IP \fItype\fP
46 .I type
47 qualifiers say what kind of thing the id name or number refers to.
48 Possible types are
49 .BR host ,
50 .B net ,
51 .B port
52 and
53 .BR portrange .
54 E.g., `host foo', `net 128.3', `port 20', `portrange 6000-6008'.
55 If there is no type
56 qualifier,
57 .B host
58 is assumed.
59 .IP \fIdir\fP
60 .I dir
61 qualifiers specify a particular transfer direction to and/or from
62 .IR id .
63 Possible directions are
64 .BR src ,
65 .BR dst ,
66 .BR "src or dst" ,
67 .BR "src and dst" ,
68 .BR ra ,
69 .BR ta ,
70 .BR addr1 ,
71 .BR addr2 ,
72 .BR addr3 ,
73 and
74 .BR addr4 .
75 E.g., `src foo', `dst net 128.3', `src or dst port ftp-data'.
76 If
77 there is no dir qualifier,
78 .B "src or dst"
79 is assumed.
80 The
81 .BR ra ,
82 .BR ta ,
83 .BR addr1 ,
84 .BR addr2 ,
85 .BR addr3 ,
86 and
87 .B addr4
88 qualifiers are only valid for IEEE 802.11 Wireless LAN link layers.
89 For some link layers, such as SLIP and the ``cooked'' Linux capture mode
90 used for the ``any'' device and for some other device types, the
91 .B inbound
92 and
93 .B outbound
94 qualifiers can be used to specify a desired direction.
95 .IP \fIproto\fP
96 .I proto
97 qualifiers restrict the match to a particular protocol.
98 Possible
99 protos are:
100 .BR ether ,
101 .BR fddi ,
102 .BR tr ,
103 .BR wlan ,
104 .BR ip ,
105 .BR ip6 ,
106 .BR arp ,
107 .BR rarp ,
108 .BR decnet ,
109 .B tcp
110 and
111 .BR udp .
112 E.g., `ether src foo', `arp net 128.3', `tcp port 21', `udp portrange
113 7000-7009', `wlan addr2 0:2:3:4:5:6'.
114 If there is
115 no proto qualifier, all protocols consistent with the type are
116 assumed.
117 E.g., `src foo' means `(ip or arp or rarp) src foo'
118 (except the latter is not legal syntax), `net bar' means `(ip or
119 arp or rarp) net bar' and `port 53' means `(tcp or udp) port 53'.
120 .LP
121 [`fddi' is actually an alias for `ether'; the parser treats them
122 identically as meaning ``the data link level used on the specified
123 network interface.'' FDDI headers contain Ethernet-like source
124 and destination addresses, and often contain Ethernet-like packet
125 types, so you can filter on these FDDI fields just as with the
126 analogous Ethernet fields.
127 FDDI headers also contain other fields,
128 but you cannot name them explicitly in a filter expression.
129 .LP
130 Similarly, `tr' and `wlan' are aliases for `ether'; the previous
131 paragraph's statements about FDDI headers also apply to Token Ring
132 and 802.11 wireless LAN headers. For 802.11 headers, the destination
133 address is the DA field and the source address is the SA field; the
134 BSSID, RA, and TA fields aren't tested.]
135 .LP
136 In addition to the above, there are some special `primitive' keywords
137 that don't follow the pattern:
138 .BR gateway ,
139 .BR broadcast ,
140 .BR less ,
141 .B greater
142 and arithmetic expressions.
143 All of these are described below.
144 .LP
145 More complex filter expressions are built up by using the words
146 .BR and ,
147 .B or
148 and
149 .B not
150 to combine primitives.
151 E.g., `host foo and not port ftp and not port ftp-data'.
152 To save typing, identical qualifier lists can be omitted.
153 E.g.,
154 `tcp dst port ftp or ftp-data or domain' is exactly the same as
155 `tcp dst port ftp or tcp dst port ftp-data or tcp dst port domain'.
156 .LP
157 Allowable primitives are:
158 .IP "\fBdst host \fIhost\fR"
159 True if the IPv4/v6 destination field of the packet is \fIhost\fP,
160 which may be either an address or a name.
161 .IP "\fBsrc host \fIhost\fR"
162 True if the IPv4/v6 source field of the packet is \fIhost\fP.
163 .IP "\fBhost \fIhost\fP"
164 True if either the IPv4/v6 source or destination of the packet is \fIhost\fP.
165 .IP
166 Any of the above host expressions can be prepended with the keywords,
167 \fBip\fP, \fBarp\fP, \fBrarp\fP, or \fBip6\fP as in:
168 .in +.5i
169 .nf
170 \fBip host \fIhost\fR
171 .fi
172 .in -.5i
173 which is equivalent to:
174 .in +.5i
175 .nf
176 \fBether proto \fI\\ip\fB and host \fIhost\fR
177 .fi
178 .in -.5i
179 If \fIhost\fR is a name with multiple IP addresses, each address will
180 be checked for a match.
181 .IP "\fBether dst \fIehost\fP"
182 True if the Ethernet destination address is \fIehost\fP.
183 \fIEhost\fP
184 may be either a name from /etc/ethers or a number (see
185 .IR ethers (3N)
186 for numeric format).
187 .IP "\fBether src \fIehost\fP"
188 True if the Ethernet source address is \fIehost\fP.
189 .IP "\fBether host \fIehost\fP"
190 True if either the Ethernet source or destination address is \fIehost\fP.
191 .IP "\fBgateway\fP \fIhost\fP"
192 True if the packet used \fIhost\fP as a gateway.
193 I.e., the Ethernet
194 source or destination address was \fIhost\fP but neither the IP source
195 nor the IP destination was \fIhost\fP.
196 \fIHost\fP must be a name and
197 must be found both by the machine's host-name-to-IP-address resolution
198 mechanisms (host name file, DNS, NIS, etc.) and by the machine's
199 host-name-to-Ethernet-address resolution mechanism (/etc/ethers, etc.).
200 (An equivalent expression is
201 .in +.5i
202 .nf
203 \fBether host \fIehost \fBand not host \fIhost\fR
204 .fi
205 .in -.5i
206 which can be used with either names or numbers for \fIhost / ehost\fP.)
207 This syntax does not work in IPv6-enabled configuration at this moment.
208 .IP "\fBdst net \fInet\fR"
209 True if the IPv4/v6 destination address of the packet has a network
210 number of \fInet\fP.
211 \fINet\fP may be either a name from the networks database
212 (/etc/networks, etc.) or a network number.
213 An IPv4 network number can be written as a dotted quad (e.g., 192.168.1.0),
214 dotted triple (e.g., 192.168.1), dotted pair (e.g, 172.16), or single
215 number (e.g., 10); the netmask is 255.255.255.255 for a dotted quad
216 (which means that it's really a host match), 255.255.255.0 for a dotted
217 triple, 255.255.0.0 for a dotted pair, or 255.0.0.0 for a single number.
218 An IPv6 network number must be written out fully; the netmask is
219 ff:ff:ff:ff:ff:ff:ff:ff, so IPv6 "network" matches are really always
220 host matches, and a network match requires a netmask length.
221 .IP "\fBsrc net \fInet\fR"
222 True if the IPv4/v6 source address of the packet has a network
223 number of \fInet\fP.
224 .IP "\fBnet \fInet\fR"
225 True if either the IPv4/v6 source or destination address of the packet has a network
226 number of \fInet\fP.
227 .IP "\fBnet \fInet\fR \fBmask \fInetmask\fR"
228 True if the IPv4 address matches \fInet\fR with the specific \fInetmask\fR.
229 May be qualified with \fBsrc\fR or \fBdst\fR.
230 Note that this syntax is not valid for IPv6 \fInet\fR.
231 .IP "\fBnet \fInet\fR/\fIlen\fR"
232 True if the IPv4/v6 address matches \fInet\fR with a netmask \fIlen\fR
233 bits wide.
234 May be qualified with \fBsrc\fR or \fBdst\fR.
235 .IP "\fBdst port \fIport\fR"
236 True if the packet is ip/tcp, ip/udp, ip6/tcp or ip6/udp and has a
237 destination port value of \fIport\fP.
238 The \fIport\fP can be a number or a name used in /etc/services (see
239 .IR tcp (4P)
240 and
241 .IR udp (4P)).
242 If a name is used, both the port
243 number and protocol are checked.
244 If a number or ambiguous name is used,
245 only the port number is checked (e.g., \fBdst port 513\fR will print both
246 tcp/login traffic and udp/who traffic, and \fBport domain\fR will print
247 both tcp/domain and udp/domain traffic).
248 .IP "\fBsrc port \fIport\fR"
249 True if the packet has a source port value of \fIport\fP.
250 .IP "\fBport \fIport\fR"
251 True if either the source or destination port of the packet is \fIport\fP.
252 .IP "\fBdst portrange \fIport1\fB-\fIport2\fR"
253 True if the packet is ip/tcp, ip/udp, ip6/tcp or ip6/udp and has a
254 destination port value between \fIport1\fP and \fIport2\fP.
255 .I port1
256 and
257 .I port2
258 are interpreted in the same fashion as the
259 .I port
260 parameter for
261 .BR port .
262 .IP "\fBsrc portrange \fIport1\fB-\fIport2\fR"
263 True if the packet has a source port value between \fIport1\fP and
264 \fIport2\fP.
265 .IP "\fBportrange \fIport1\fB-\fIport2\fR"
266 True if either the source or destination port of the packet is between
267 \fIport1\fP and \fIport2\fP.
268 .IP
269 Any of the above port or port range expressions can be prepended with
270 the keywords, \fBtcp\fP or \fBudp\fP, as in:
271 .in +.5i
272 .nf
273 \fBtcp src port \fIport\fR
274 .fi
275 .in -.5i
276 which matches only tcp packets whose source port is \fIport\fP.
277 .IP "\fBless \fIlength\fR"
278 True if the packet has a length less than or equal to \fIlength\fP.
279 This is equivalent to:
280 .in +.5i
281 .nf
282 \fBlen <= \fIlength\fP.
283 .fi
284 .in -.5i
285 .IP "\fBgreater \fIlength\fR"
286 True if the packet has a length greater than or equal to \fIlength\fP.
287 This is equivalent to:
288 .in +.5i
289 .nf
290 \fBlen >= \fIlength\fP.
291 .fi
292 .in -.5i
293 .IP "\fBip proto \fIprotocol\fR"
294 True if the packet is an IPv4 packet (see
295 .IR ip (4P))
296 of protocol type \fIprotocol\fP.
297 \fIProtocol\fP can be a number or one of the names
298 \fBicmp\fP, \fBicmp6\fP, \fBigmp\fP, \fBigrp\fP, \fBpim\fP, \fBah\fP,
299 \fBesp\fP, \fBvrrp\fP, \fBudp\fP, or \fBtcp\fP.
300 Note that the identifiers \fBtcp\fP, \fBudp\fP, and \fBicmp\fP are also
301 keywords and must be escaped via backslash (\\), which is \\\\ in the C-shell.
302 Note that this primitive does not chase the protocol header chain.
303 .IP "\fBip6 proto \fIprotocol\fR"
304 True if the packet is an IPv6 packet of protocol type \fIprotocol\fP.
305 Note that this primitive does not chase the protocol header chain.
306 .IP "\fBproto \fIprotocol\fR"
307 True if the packet is an IPv4 or IPv6 packet of protocol type
308 \fIprotocol\fP. Note that this primitive does not chase the protocol
309 header chain.
310 .IP "\fBtcp\fR, \fBudp\fR, \fBicmp\fR"
311 Abbreviations for:
312 .in +.5i
313 .nf
314 \fBproto \fIp\fR\fB
315 .fi
316 .in -.5i
317 where \fIp\fR is one of the above protocols.
318 .IP "\fBip6 protochain \fIprotocol\fR"
319 True if the packet is IPv6 packet,
320 and contains protocol header with type \fIprotocol\fR
321 in its protocol header chain.
322 For example,
323 .in +.5i
324 .nf
325 \fBip6 protochain 6\fR
326 .fi
327 .in -.5i
328 matches any IPv6 packet with TCP protocol header in the protocol header chain.
329 The packet may contain, for example,
330 authentication header, routing header, or hop-by-hop option header,
331 between IPv6 header and TCP header.
332 The BPF code emitted by this primitive is complex and
333 cannot be optimized by the BPF optimizer code, so this can be somewhat
334 slow.
335 .IP "\fBip protochain \fIprotocol\fR"
336 Equivalent to \fBip6 protochain \fIprotocol\fR, but this is for IPv4.
337 .IP "\fBprotochain \fIprotocol\fR"
338 True if the packet is an IPv4 or IPv6 packet of protocol type
339 \fIprotocol\fP. Note that this primitive chases the protocol
340 header chain.
341 .IP "\fBether broadcast\fR"
342 True if the packet is an Ethernet broadcast packet.
343 The \fIether\fP
344 keyword is optional.
345 .IP "\fBip broadcast\fR"
346 True if the packet is an IPv4 broadcast packet.
347 It checks for both the all-zeroes and all-ones broadcast conventions,
348 and looks up the subnet mask on the interface on which the capture is
349 being done.
350 .IP
351 If the subnet mask of the interface on which the capture is being done
352 is not available, either because the interface on which capture is being
353 done has no netmask or because the capture is being done on the Linux
354 "any" interface, which can capture on more than one interface, this
355 check will not work correctly.
356 .IP "\fBether multicast\fR"
357 True if the packet is an Ethernet multicast packet.
358 The \fBether\fP
359 keyword is optional.
360 This is shorthand for `\fBether[0] & 1 != 0\fP'.
361 .IP "\fBip multicast\fR"
362 True if the packet is an IPv4 multicast packet.
363 .IP "\fBip6 multicast\fR"
364 True if the packet is an IPv6 multicast packet.
365 .IP "\fBether proto \fIprotocol\fR"
366 True if the packet is of ether type \fIprotocol\fR.
367 \fIProtocol\fP can be a number or one of the names
368 \fBip\fP, \fBip6\fP, \fBarp\fP, \fBrarp\fP, \fBatalk\fP, \fBaarp\fP,
369 \fBdecnet\fP, \fBsca\fP, \fBlat\fP, \fBmopdl\fP, \fBmoprc\fP,
370 \fBiso\fP, \fBstp\fP, \fBipx\fP, or \fBnetbeui\fP.
371 Note these identifiers are also keywords
372 and must be escaped via backslash (\\).
373 .IP
374 [In the case of FDDI (e.g., `\fBfddi protocol arp\fR'), Token Ring
375 (e.g., `\fBtr protocol arp\fR'), and IEEE 802.11 wireless LANS (e.g.,
376 `\fBwlan protocol arp\fR'), for most of those protocols, the
377 protocol identification comes from the 802.2 Logical Link Control (LLC)
378 header, which is usually layered on top of the FDDI, Token Ring, or
379 802.11 header.
380 .IP
381 When filtering for most protocol identifiers on FDDI, Token Ring, or
382 802.11, the filter checks only the protocol ID field of an LLC header
383 in so-called SNAP format with an Organizational Unit Identifier (OUI) of
384 0x000000, for encapsulated Ethernet; it doesn't check whether the packet
385 is in SNAP format with an OUI of 0x000000.
386 The exceptions are:
387 .RS
388 .TP
389 \fBiso\fP
390 the filter checks the DSAP (Destination Service Access Point) and
391 SSAP (Source Service Access Point) fields of the LLC header;
392 .TP
393 \fBstp\fP and \fBnetbeui\fP
394 the filter checks the DSAP of the LLC header;
395 .TP
396 \fBatalk\fP
397 the filter checks for a SNAP-format packet with an OUI of 0x080007
398 and the AppleTalk etype.
399 .RE
400 .IP
401 In the case of Ethernet, the filter checks the Ethernet type field
402 for most of those protocols. The exceptions are:
403 .RS
404 .TP
405 \fBiso\fP, \fBstp\fP, and \fBnetbeui\fP
406 the filter checks for an 802.3 frame and then checks the LLC header as
407 it does for FDDI, Token Ring, and 802.11;
408 .TP
409 \fBatalk\fP
410 the filter checks both for the AppleTalk etype in an Ethernet frame and
411 for a SNAP-format packet as it does for FDDI, Token Ring, and 802.11;
412 .TP
413 \fBaarp\fP
414 the filter checks for the AppleTalk ARP etype in either an Ethernet
415 frame or an 802.2 SNAP frame with an OUI of 0x000000;
416 .TP
417 \fBipx\fP
418 the filter checks for the IPX etype in an Ethernet frame, the IPX
419 DSAP in the LLC header, the 802.3-with-no-LLC-header encapsulation of
420 IPX, and the IPX etype in a SNAP frame.
421 .RE
422 .IP "\fBip\fR, \fBip6\fR, \fBarp\fR, \fBrarp\fR, \fBatalk\fR, \fBaarp\fR, \fBdecnet\fR, \fBiso\fR, \fBstp\fR, \fBipx\fR, \fBnetbeui\fP"
423 Abbreviations for:
424 .in +.5i
425 .nf
426 \fBether proto \fIp\fR
427 .fi
428 .in -.5i
429 where \fIp\fR is one of the above protocols.
430 .IP "\fBlat\fR, \fBmoprc\fR, \fBmopdl\fR"
431 Abbreviations for:
432 .in +.5i
433 .nf
434 \fBether proto \fIp\fR
435 .fi
436 .in -.5i
437 where \fIp\fR is one of the above protocols.
438 Note that not all applications using
439 .BR pcap (3PCAP)
440 currently know how to parse these protocols.
441 .IP "\fBdecnet src \fIhost\fR"
442 True if the DECNET source address is
443 .IR host ,
444 which may be an address of the form ``10.123'', or a DECNET host
445 name.
446 [DECNET host name support is only available on ULTRIX systems
447 that are configured to run DECNET.]
448 .IP "\fBdecnet dst \fIhost\fR"
449 True if the DECNET destination address is
450 .IR host .
451 .IP "\fBdecnet host \fIhost\fR"
452 True if either the DECNET source or destination address is
453 .IR host .
454 .IP "\fBifname \fIinterface\fR"
455 True if the packet was logged as coming from the specified interface (applies
456 only to packets logged by OpenBSD's or FreeBSD's
457 .BR pf (4)).
458 .IP "\fBon \fIinterface\fR"
459 Synonymous with the
460 .B ifname
461 modifier.
462 .IP "\fBrnr \fInum\fR"
463 True if the packet was logged as matching the specified PF rule number
464 (applies only to packets logged by OpenBSD's or FreeBSD's
465 .BR pf (4)).
466 .IP "\fBrulenum \fInum\fR"
467 Synonymous with the
468 .B rnr
469 modifier.
470 .IP "\fBreason \fIcode\fR"
471 True if the packet was logged with the specified PF reason code. The known
472 codes are:
473 .BR match ,
474 .BR bad-offset ,
475 .BR fragment ,
476 .BR short ,
477 .BR normalize ,
478 and
479 .B memory
480 (applies only to packets logged by OpenBSD's or FreeBSD's
481 .BR pf (4)).
482 .IP "\fBrset \fIname\fR"
483 True if the packet was logged as matching the specified PF ruleset
484 name of an anchored ruleset (applies only to packets logged by OpenBSD's
485 or FreeBSD's
486 .BR pf (4)).
487 .IP "\fBruleset \fIname\fR"
488 Synonymous with the
489 .B rset
490 modifier.
491 .IP "\fBsrnr \fInum\fR"
492 True if the packet was logged as matching the specified PF rule number
493 of an anchored ruleset (applies only to packets logged by OpenBSD's or
494 FreeBSD's
495 .BR pf (4)).
496 .IP "\fBsubrulenum \fInum\fR"
497 Synonymous with the
498 .B srnr
499 modifier.
500 .IP "\fBaction \fIact\fR"
501 True if PF took the specified action when the packet was logged. Known actions
502 are:
503 .B pass
504 and
505 .B block
506 and, with later versions of
507 .BR pf (4)),
508 .BR nat ,
509 .BR rdr ,
510 .B binat
511 and
512 .B scrub
513 (applies only to packets logged by OpenBSD's or FreeBSD's
514 .BR pf (4)).
515 .IP "\fBwlan ra \fIehost\fR"
516 True if the IEEE 802.11 RA is
517 .IR ehost .
518 The RA field is used in all frames except for management frames.
519 .IP "\fBwlan ta \fIehost\fR"
520 True if the IEEE 802.11 TA is
521 .IR ehost .
522 The TA field is used in all frames except for management frames and
523 CTS (Clear To Send) and ACK (Acknowledgment) control frames.
524 .IP "\fBwlan addr1 \fIehost\fR"
525 True if the first IEEE 802.11 address is
526 .IR ehost .
527 .IP "\fBwlan addr2 \fIehost\fR"
528 True if the second IEEE 802.11 address, if present, is
529 .IR ehost .
530 The second address field is used in all frames except for CTS (Clear To
531 Send) and ACK (Acknowledgment) control frames.
532 .IP "\fBwlan addr3 \fIehost\fR"
533 True if the third IEEE 802.11 address, if present, is
534 .IR ehost .
535 The third address field is used in management and data frames, but not
536 in control frames.
537 .IP "\fBwlan addr4 \fIehost\fR"
538 True if the fourth IEEE 802.11 address, if present, is
539 .IR ehost .
540 The fourth address field is only used for
541 WDS (Wireless Distribution System) frames.
542 .IP "\fBtype \fIwlan_type\fR"
543 True if the IEEE 802.11 frame type matches the specified \fIwlan_type\fR.
544 Valid \fIwlan_type\fRs are:
545 \fBmgt\fP,
546 \fBctl\fP
547 and \fBdata\fP.
548 .IP "\fBtype \fIwlan_type \fBsubtype \fIwlan_subtype\fR"
549 True if the IEEE 802.11 frame type matches the specified \fIwlan_type\fR
550 and frame subtype matches the specified \fIwlan_subtype\fR.
551 .IP
552 If the specified \fIwlan_type\fR is \fBmgt\fP,
553 then valid \fIwlan_subtype\fRs are:
554 \fBassoc-req\fP,
555 \fBassoc-resp\fP,
556 \fBreassoc-req\fP,
557 \fBreassoc-resp\fP,
558 \fBprobe-req\fP,
559 \fBprobe-resp\fP,
560 \fBbeacon\fP,
561 \fBatim\fP,
562 \fBdisassoc\fP,
563 \fBauth\fP and
564 \fBdeauth\fP.
565 .IP
566 If the specified \fIwlan_type\fR is \fBctl\fP,
567 then valid \fIwlan_subtype\fRs are:
568 \fBps-poll\fP,
569 \fBrts\fP,
570 \fBcts\fP,
571 \fBack\fP,
572 \fBcf-end\fP and
573 \fBcf-end-ack\fP.
574 .IP
575 If the specified \fIwlan_type\fR is \fBdata\fP,
576 then valid \fIwlan_subtype\fRs are:
577 \fBdata\fP,
578 \fBdata-cf-ack\fP,
579 \fBdata-cf-poll\fP,
580 \fBdata-cf-ack-poll\fP,
581 \fBnull\fP,
582 \fBcf-ack\fP,
583 \fBcf-poll\fP,
584 \fBcf-ack-poll\fP,
585 \fBqos-data\fP,
586 \fBqos-data-cf-ack\fP,
587 \fBqos-data-cf-poll\fP,
588 \fBqos-data-cf-ack-poll\fP,
589 \fBqos\fP,
590 \fBqos-cf-poll\fP and
591 \fBqos-cf-ack-poll\fP.
592 .IP "\fBsubtype \fIwlan_subtype\fR"
593 True if the IEEE 802.11 frame subtype matches the specified \fIwlan_subtype\fR
594 and frame has the type to which the specified \fIwlan_subtype\fR belongs.
595 .IP "\fBdir \fIdir\fR"
596 True if the IEEE 802.11 frame direction matches the specified
597 .IR dir .
598 Valid directions are:
599 .BR nods ,
600 .BR tods ,
601 .BR fromds ,
602 .BR dstods ,
603 or a numeric value.
604 .IP "\fBvlan \fI[vlan_id]\fR"
605 True if the packet is an IEEE 802.1Q VLAN packet.
606 If \fI[vlan_id]\fR is specified, only true if the packet has the specified
607 \fIvlan_id\fR.
608 Note that the first \fBvlan\fR keyword encountered in \fIexpression\fR
609 changes the decoding offsets for the remainder of \fIexpression\fR on
610 the assumption that the packet is a VLAN packet. The \fBvlan
611 \fI[vlan_id]\fR expression may be used more than once, to filter on VLAN
612 hierarchies. Each use of that expression increments the filter offsets
613 by 4.
614 .IP
615 For example:
616 .in +.5i
617 .nf
618 \fBvlan 100 && vlan 200\fR
619 .fi
620 .in -.5i
621 filters on VLAN 200 encapsulated within VLAN 100, and
622 .in +.5i
623 .nf
624 \fBvlan && vlan 300 && ip\fR
625 .fi
626 .in -.5i
627 filters IPv4 protocols encapsulated in VLAN 300 encapsulated within any
628 higher order VLAN.
629 .IP "\fBmpls \fI[label_num]\fR"
630 True if the packet is an MPLS packet.
631 If \fI[label_num]\fR is specified, only true is the packet has the specified
632 \fIlabel_num\fR.
633 Note that the first \fBmpls\fR keyword encountered in \fIexpression\fR
634 changes the decoding offsets for the remainder of \fIexpression\fR on
635 the assumption that the packet is a MPLS-encapsulated IP packet. The
636 \fBmpls \fI[label_num]\fR expression may be used more than once, to
637 filter on MPLS hierarchies. Each use of that expression increments the
638 filter offsets by 4.
639 .IP
640 For example:
641 .in +.5i
642 .nf
643 \fBmpls 100000 && mpls 1024\fR
644 .fi
645 .in -.5i
646 filters packets with an outer label of 100000 and an inner label of
647 1024, and
648 .in +.5i
649 .nf
650 \fBmpls && mpls 1024 && host 192.9.200.1\fR
651 .fi
652 .in -.5i
653 filters packets to or from 192.9.200.1 with an inner label of 1024 and
654 any outer label.
655 .IP \fBpppoed\fP
656 True if the packet is a PPP-over-Ethernet Discovery packet (Ethernet
657 type 0x8863).
658 .IP "\fBpppoes \fI[session_id]\fR"
659 True if the packet is a PPP-over-Ethernet Session packet (Ethernet
660 type 0x8864).
661 If \fI[session_id]\fR is specified, only true if the packet has the specified
662 \fIsession_id\fR.
663 Note that the first \fBpppoes\fR keyword encountered in \fIexpression\fR
664 changes the decoding offsets for the remainder of \fIexpression\fR on
665 the assumption that the packet is a PPPoE session packet.
666 .IP
667 For example:
668 .in +.5i
669 .nf
670 \fBpppoes 0x27 && ip\fR
671 .fi
672 .in -.5i
673 filters IPv4 protocols encapsulated in PPPoE session id 0x27.
674 .IP "\fBiso proto \fIprotocol\fR"
675 True if the packet is an OSI packet of protocol type \fIprotocol\fP.
676 \fIProtocol\fP can be a number or one of the names
677 \fBclnp\fP, \fBesis\fP, or \fBisis\fP.
678 .IP "\fBclnp\fR, \fBesis\fR, \fBisis\fR"
679 Abbreviations for:
680 .in +.5i
681 .nf
682 \fBiso proto \fIp\fR
683 .fi
684 .in -.5i
685 where \fIp\fR is one of the above protocols.
686 .IP "\fBl1\fR, \fBl2\fR, \fBiih\fR, \fBlsp\fR, \fBsnp\fR, \fBcsnp\fR, \fBpsnp\fR"
687 Abbreviations for IS-IS PDU types.
688 .IP "\fBvpi\fP \fIn\fR"
689 True if the packet is an ATM packet, for SunATM on Solaris, with a
690 virtual path identifier of
691 .IR n .
692 .IP "\fBvci\fP \fIn\fR"
693 True if the packet is an ATM packet, for SunATM on Solaris, with a
694 virtual channel identifier of
695 .IR n .
696 .IP \fBlane\fP
697 True if the packet is an ATM packet, for SunATM on Solaris, and is
698 an ATM LANE packet.
699 Note that the first \fBlane\fR keyword encountered in \fIexpression\fR
700 changes the tests done in the remainder of \fIexpression\fR
701 on the assumption that the packet is either a LANE emulated Ethernet
702 packet or a LANE LE Control packet. If \fBlane\fR isn't specified, the
703 tests are done under the assumption that the packet is an
704 LLC-encapsulated packet.
705 .IP \fBllc\fP
706 True if the packet is an ATM packet, for SunATM on Solaris, and is
707 an LLC-encapsulated packet.
708 .IP \fBoamf4s\fP
709 True if the packet is an ATM packet, for SunATM on Solaris, and is
710 a segment OAM F4 flow cell (VPI=0 & VCI=3).
711 .IP \fBoamf4e\fP
712 True if the packet is an ATM packet, for SunATM on Solaris, and is
713 an end-to-end OAM F4 flow cell (VPI=0 & VCI=4).
714 .IP \fBoamf4\fP
715 True if the packet is an ATM packet, for SunATM on Solaris, and is
716 a segment or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 | VCI=4)).
717 .IP \fBoam\fP
718 True if the packet is an ATM packet, for SunATM on Solaris, and is
719 a segment or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 | VCI=4)).
720 .IP \fBmetac\fP
721 True if the packet is an ATM packet, for SunATM on Solaris, and is
722 on a meta signaling circuit (VPI=0 & VCI=1).
723 .IP \fBbcc\fP
724 True if the packet is an ATM packet, for SunATM on Solaris, and is
725 on a broadcast signaling circuit (VPI=0 & VCI=2).
726 .IP \fBsc\fP
727 True if the packet is an ATM packet, for SunATM on Solaris, and is
728 on a signaling circuit (VPI=0 & VCI=5).
729 .IP \fBilmic\fP
730 True if the packet is an ATM packet, for SunATM on Solaris, and is
731 on an ILMI circuit (VPI=0 & VCI=16).
732 .IP \fBconnectmsg\fP
733 True if the packet is an ATM packet, for SunATM on Solaris, and is
734 on a signaling circuit and is a Q.2931 Setup, Call Proceeding, Connect,
735 Connect Ack, Release, or Release Done message.
736 .IP \fBmetaconnect\fP
737 True if the packet is an ATM packet, for SunATM on Solaris, and is
738 on a meta signaling circuit and is a Q.2931 Setup, Call Proceeding, Connect,
739 Release, or Release Done message.
740 .IP "\fIexpr relop expr\fR"
741 True if the relation holds, where \fIrelop\fR is one of >, <, >=, <=, =,
742 !=, and \fIexpr\fR is an arithmetic expression composed of integer
743 constants (expressed in standard C syntax), the normal binary operators
744 [+, -, *, /, &, |, <<, >>], a length operator, and special packet data
745 accessors. Note that all comparisons are unsigned, so that, for example,
746 0x80000000 and 0xffffffff are > 0.
747 To access
748 data inside the packet, use the following syntax:
749 .in +.5i
750 .nf
751 \fIproto\fB [ \fIexpr\fB : \fIsize\fB ]\fR
752 .fi
753 .in -.5i
754 \fIProto\fR is one of \fBether, fddi, tr, wlan, ppp, slip, link,
755 ip, arp, rarp, tcp, udp, icmp, ip6\fR or \fBradio\fR, and
756 indicates the protocol layer for the index operation.
757 (\fBether, fddi, wlan, tr, ppp, slip\fR and \fBlink\fR all refer to the
758 link layer. \fBradio\fR refers to the "radio header" added to some
759 802.11 captures.)
760 Note that \fItcp, udp\fR and other upper-layer protocol types only
761 apply to IPv4, not IPv6 (this will be fixed in the future).
762 The byte offset, relative to the indicated protocol layer, is
763 given by \fIexpr\fR.
764 \fISize\fR is optional and indicates the number of bytes in the
765 field of interest; it can be either one, two, or four, and defaults to one.
766 The length operator, indicated by the keyword \fBlen\fP, gives the
767 length of the packet.
768
769 For example, `\fBether[0] & 1 != 0\fP' catches all multicast traffic.
770 The expression `\fBip[0] & 0xf != 5\fP'
771 catches all IPv4 packets with options.
772 The expression
773 `\fBip[6:2] & 0x1fff = 0\fP'
774 catches only unfragmented IPv4 datagrams and frag zero of fragmented
775 IPv4 datagrams.
776 This check is implicitly applied to the \fBtcp\fP and \fBudp\fP
777 index operations.
778 For instance, \fBtcp[0]\fP always means the first
779 byte of the TCP \fIheader\fP, and never means the first byte of an
780 intervening fragment.
781
782 Some offsets and field values may be expressed as names rather than
783 as numeric values.
784 The following protocol header field offsets are
785 available: \fBicmptype\fP (ICMP type field), \fBicmpcode\fP (ICMP
786 code field), and \fBtcpflags\fP (TCP flags field).
787
788 The following ICMP type field values are available: \fBicmp-echoreply\fP,
789 \fBicmp-unreach\fP, \fBicmp-sourcequench\fP, \fBicmp-redirect\fP,
790 \fBicmp-echo\fP, \fBicmp-routeradvert\fP, \fBicmp-routersolicit\fP,
791 \fBicmp-timxceed\fP, \fBicmp-paramprob\fP, \fBicmp-tstamp\fP,
792 \fBicmp-tstampreply\fP, \fBicmp-ireq\fP, \fBicmp-ireqreply\fP,
793 \fBicmp-maskreq\fP, \fBicmp-maskreply\fP.
794
795 The following TCP flags field values are available: \fBtcp-fin\fP,
796 \fBtcp-syn\fP, \fBtcp-rst\fP, \fBtcp-push\fP,
797 \fBtcp-ack\fP, \fBtcp-urg\fP.
798 .LP
799 Primitives may be combined using:
800 .IP
801 A parenthesized group of primitives and operators
802 (parentheses are special to the Shell and must be escaped).
803 .IP
804 Negation (`\fB!\fP' or `\fBnot\fP').
805 .IP
806 Concatenation (`\fB&&\fP' or `\fBand\fP').
807 .IP
808 Alternation (`\fB||\fP' or `\fBor\fP').
809 .LP
810 Negation has highest precedence.
811 Alternation and concatenation have equal precedence and associate
812 left to right.
813 Note that explicit \fBand\fR tokens, not juxtaposition,
814 are now required for concatenation.
815 .LP
816 If an identifier is given without a keyword, the most recent keyword
817 is assumed.
818 For example,
819 .in +.5i
820 .nf
821 \fBnot host vs and ace\fR
822 .fi
823 .in -.5i
824 is short for
825 .in +.5i
826 .nf
827 \fBnot host vs and host ace\fR
828 .fi
829 .in -.5i
830 which should not be confused with
831 .in +.5i
832 .nf
833 \fBnot ( host vs or ace )\fR
834 .fi
835 .in -.5i
836 .SH EXAMPLES
837 .LP
838 To select all packets arriving at or departing from \fIsundown\fP:
839 .RS
840 .nf
841 \fBhost sundown\fP
842 .fi
843 .RE
844 .LP
845 To select traffic between \fIhelios\fR and either \fIhot\fR or \fIace\fR:
846 .RS
847 .nf
848 \fBhost helios and \\( hot or ace \\)\fP
849 .fi
850 .RE
851 .LP
852 To select all IP packets between \fIace\fR and any host except \fIhelios\fR:
853 .RS
854 .nf
855 \fBip host ace and not helios\fP
856 .fi
857 .RE
858 .LP
859 To select all traffic between local hosts and hosts at Berkeley:
860 .RS
861 .nf
862 .B
863 net ucb-ether
864 .fi
865 .RE
866 .LP
867 To select all ftp traffic through internet gateway \fIsnup\fP:
868 .RS
869 .nf
870 .B
871 gateway snup and (port ftp or ftp-data)
872 .fi
873 .RE
874 .LP
875 To select traffic neither sourced from nor destined for local hosts
876 (if you gateway to one other net, this stuff should never make it
877 onto your local net).
878 .RS
879 .nf
880 .B
881 ip and not net \fIlocalnet\fP
882 .fi
883 .RE
884 .LP
885 To select the start and end packets (the SYN and FIN packets) of each
886 TCP conversation that involves a non-local host.
887 .RS
888 .nf
889 .B
890 tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net \fIlocalnet\fP
891 .fi
892 .RE
893 .LP
894 To select all IPv4 HTTP packets to and from port 80, i.e. print only
895 packets that contain data, not, for example, SYN and FIN packets and
896 ACK-only packets. (IPv6 is left as an exercise for the reader.)
897 .RS
898 .nf
899 .B
900 tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)
901 .fi
902 .RE
903 .LP
904 To select IP packets longer than 576 bytes sent through gateway \fIsnup\fP:
905 .RS
906 .nf
907 .B
908 gateway snup and ip[2:2] > 576
909 .fi
910 .RE
911 .LP
912 To select IP broadcast or multicast packets that were
913 .I not
914 sent via Ethernet broadcast or multicast:
915 .RS
916 .nf
917 .B
918 ether[0] & 1 = 0 and ip[16] >= 224
919 .fi
920 .RE
921 .LP
922 To select all ICMP packets that are not echo requests/replies (i.e., not
923 ping packets):
924 .RS
925 .nf
926 .B
927 icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
928 .fi
929 .RE
930 .SH "SEE ALSO"
931 pcap(3PCAP)
932 .SH BUGS
933 Please send problems, bugs, questions, desirable enhancements, etc. to:
934 .LP
935 .RS
936 tcpdump-workers@lists.tcpdump.org
937 .RE
938 .LP
939 Filter expressions on fields other than those in Token Ring headers will
940 not correctly handle source-routed Token Ring packets.
941 .LP
942 Filter expressions on fields other than those in 802.11 headers will not
943 correctly handle 802.11 data packets with both To DS and From DS set.
944 .LP
945 .BR "ip6 proto"
946 should chase header chain, but at this moment it does not.
947 .BR "ip6 protochain"
948 is supplied for this behavior.
949 .LP
950 Arithmetic expression against transport layer headers, like \fBtcp[0]\fP,
951 does not work against IPv6 packets.
952 It only looks at IPv4 packets.