The libpcap puts pcap-filter into the misc section (which seems to be 7).
[obnox/wireshark/wip.git] / doc / wireshark-filter.pod
1 =head1 NAME
2
3 wireshark-filter - Wireshark filter syntax and reference
4
5 =head1 SYNOPSIS
6
7 B<wireshark> [other options]
8 S<[ B<-R> "filter expression" ]>
9
10 B<tshark> [other options]
11 S<[ B<-R> "filter expression" ]>
12
13 =head1 DESCRIPTION
14
15 B<Wireshark> and B<TShark> share a powerful filter engine that helps remove
16 the noise from a packet trace and lets you see only the packets that interest
17 you.  If a packet meets the requirements expressed in your filter, then it
18 is displayed in the list of packets.  Display filters let you compare the
19 fields within a protocol against a specific value, compare fields against
20 fields, and check the existence of specified fields or protocols.
21
22 Filters are also used by other features such as statistics generation and
23 packet list colorization (the latter is only available to B<Wireshark>). This
24 manual page describes their syntax. A comprehensive reference of filter fields
25 can be found within Wireshark and in the display filter reference at
26 L<http://www.wireshark.org/docs/dfref/>.
27
28 =head1 FILTER SYNTAX
29
30 =head2 Check whether a field or protocol exists
31
32 The simplest filter allows you to check for the existence of a protocol or
33 field.  If you want to see all packets which contain the IP protocol, the
34 filter would be "ip" (without the quotation marks). To see all packets
35 that contain a Token-Ring RIF field, use "tr.rif".
36
37 Think of a protocol or field in a filter as implicitly having the "exists"
38 operator.
39
40 =head2 Comparison operators
41
42 Fields can also be compared against values.  The comparison operators
43 can be expressed either through English-like abbreviations or through 
44 C-like symbols:
45
46     eq, ==    Equal
47     ne, !=    Not Equal
48     gt, >     Greater Than
49     lt, <     Less Than
50     ge, >=    Greater than or Equal to
51     le, <=    Less than or Equal to
52
53 =head2 Search and match operators
54
55 Additional operators exist expressed only in English, not C-like syntax:
56
57     contains  Does the protocol, field or slice contain a value
58     matches   Does the protocol or text string match the given Perl
59               regular expression
60
61 The "contains" operator allows a filter to search for a sequence of
62 characters, expressed as a string (quoted or unquoted), or bytes,
63 expressed as a byte array.  For example, to search for a given HTTP
64 URL in a capture, the following filter can be used:
65
66     http contains "http://www.wireshark.org"
67
68 The "contains" operator cannot be used on atomic fields,
69 such as numbers or IP addresses.
70
71 The "matches" operator allows a filter to apply to a specified
72 Perl-compatible regular expression (PCRE).  The "matches" operator is only
73 implemented for protocols and for protocol fields with a text string
74 representation.  For example, to search for a given WAP WSP User-Agent,
75 you can write:
76
77     wsp.user_agent matches "(?i)cldc"
78
79 This example shows an interesting PCRE feature: pattern match options have to
80 be specified with the B<(?>optionB<)> construct. For instance, B<(?i)> performs
81 a case-insensitive pattern match. More information on PCRE can be found in the
82 pcrepattern(3) man page (Perl Regular Expressions are explained in
83 L<http://www.perldoc.com/perl5.8.0/pod/perlre.html>).
84
85 Note: the "matches" operator is only available if B<Wireshark> or B<TShark>
86 have been compiled with the PCRE library. This can be checked by running:
87
88     wireshark -v
89     tshark -v
90
91 or selecting the "About Wireshark" item from the "Help" menu in B<Wireshark>.
92
93 =head2 Functions
94
95 The filter language has the following functions:
96
97     upper(string-field) - converts a string field to uppercase
98     lower(string-field) - converts a string field to lowercase
99
100 upper() and lower() are useful for performing case-insensitive string
101 comparisons. For example:
102
103     upper(ncp.nds_stream_name) contains "MACRO"
104     lower(mount.dump.hostname) == "angel"
105
106 =head2 Protocol field types
107
108 Each protocol field is typed. The types are:
109
110     ASN.1 object identifier
111     Boolean
112     Character string
113     Compiled Perl-Compatible Regular Expression (GRegex) object
114     Date and time
115     Ethernet or other MAC address
116     EUI64 address
117     Floating point (double-precision)
118     Floating point (single-precision)
119     Frame number
120     Globally Unique Identifier
121     IPv4 address
122     IPv6 address
123     IPX network number
124     Label
125     Protocol
126     Sequence of bytes
127     Signed integer, 1, 2, 3, 4, or 8 bytes
128     Time offset
129     Unsigned integer, 1, 2, 3, 4, or 8 bytes
130
131 An integer may be expressed in decimal, octal, or hexadecimal notation. 
132 The following three display filters are equivalent:
133
134     frame.pkt_len > 10
135     frame.pkt_len > 012
136     frame.pkt_len > 0xa
137
138 Boolean values are either true or false.  In a display filter expression
139 testing the value of a Boolean field, "true" is expressed as 1 or any
140 other non-zero value, and "false" is expressed as zero.  For example, a
141 token-ring packet's source route field is Boolean.  To find any
142 source-routed packets, a display filter would be:
143
144     tr.sr == 1
145
146 Non source-routed packets can be found with:
147
148     tr.sr == 0
149
150 Ethernet addresses and byte arrays are represented by hex
151 digits.  The hex digits may be separated by colons, periods, or hyphens:
152
153     eth.dst eq ff:ff:ff:ff:ff:ff
154     aim.data == 0.1.0.d
155     fddi.src == aa-aa-aa-aa-aa-aa
156     echo.data == 7a
157
158 IPv4 addresses can be represented in either dotted decimal notation or
159 by using the hostname:
160
161     ip.dst eq www.mit.edu
162     ip.src == 192.168.1.1
163
164 IPv4 addresses can be compared with the same logical relations as numbers:
165 eq, ne, gt, ge, lt, and le.  The IPv4 address is stored in host order,
166 so you do not have to worry about the endianness of an IPv4 address
167 when using it in a display filter.
168
169 Classless InterDomain Routing (CIDR) notation can be used to test if an
170 IPv4 address is in a certain subnet.  For example, this display filter
171 will find all packets in the 129.111 Class-B network:
172
173     ip.addr == 129.111.0.0/16
174
175 Remember, the number after the slash represents the number of bits used
176 to represent the network.  CIDR notation can also be used with
177 hostnames, as in this example of finding IP addresses on the same Class C
178 network as 'sneezy':
179
180     ip.addr eq sneezy/24
181
182 The CIDR notation can only be used on IP addresses or hostnames, not in
183 variable names.  So, a display filter like "ip.src/24 == ip.dst/24" is
184 not valid (yet).
185
186 IPX networks are represented by unsigned 32-bit integers.  Most likely
187 you will be using hexadecimal when testing IPX network values:
188
189     ipx.src.net == 0xc0a82c00
190
191 Strings are enclosed in double quotes:
192
193     http.request.method == "POST"
194
195 Inside double quotes, you may use a backslash to embed a double quote
196 or an arbitrary byte represented in either octal or hexadecimal.
197
198     browser.comment == "An embedded \" double-quote"
199
200 Use of hexadecimal to look for "HEAD":
201
202     http.request.method == "\x48EAD"
203
204 Use of octal to look for "HEAD":
205
206     http.request.method == "\110EAD"
207
208 This means that you must escape backslashes with backslashes inside
209 double quotes.
210
211     smb.path contains "\\\\SERVER\\SHARE"
212
213 looks for \\SERVER\SHARE in "smb.path".
214
215 =head2 The slice operator
216
217 You can take a slice of a field if the field is a text string or a
218 byte array. 
219 For example, you can filter on
220 the vendor portion of an ethernet address (the first three bytes) like
221 this:
222
223     eth.src[0:3] == 00:00:83
224
225 Another example is:
226
227     http.content_type[0:4] == "text"
228
229 You can use the slice operator on a protocol name, too.
230 The "frame" protocol can be useful, encompassing all the data captured
231 by B<Wireshark> or B<TShark>.
232
233     token[0:5] ne 0.0.0.1.1
234     llc[0] eq aa
235     frame[100-199] contains "wireshark"
236
237 The following syntax governs slices:
238
239     [i:j]    i = start_offset, j = length
240     [i-j]    i = start_offset, j = end_offset, inclusive.
241     [i]      i = start_offset, length = 1
242     [:j]     start_offset = 0, length = j
243     [i:]     start_offset = i, end_offset = end_of_field
244
245 Offsets can be negative, in which case they indicate the
246 offset from the B<end> of the field.  The last byte of the field is at offset
247 -1, the last but one byte is at offset -2, and so on.
248 Here's how to check the last four bytes of a frame:
249
250     frame[-4:4] == 0.1.2.3
251
252 or
253
254     frame[-4:] == 0.1.2.3
255
256 You can concatenate slices using the comma operator:
257
258     ftp[1,3-5,9:] == 01:03:04:05:09:0a:0b
259
260 This concatenates offset 1, offsets 3-5, and offset 9 to the end of the ftp
261 data.
262
263 =head2 Type conversions
264
265 If a field is a text string or a byte array, it can be expressed in whichever
266 way is most convenient.
267
268 So, for instance, the following filters are equivalent:
269
270     http.request.method == "GET"
271     http.request.method == 47.45.54
272
273 A range can also be expressed in either way:
274
275     frame[60:2] gt 50.51
276     frame[60:2] gt "PQ"
277
278 =head2 Bit field operations
279
280 It is also possible to define tests with bit field operations. Currently the
281 following bit field operation is supported:
282
283     bitwise_and, &      Bitwise AND
284
285 The bitwise AND operation allows testing to see if one or more bits are set.
286 Bitwise AND operates on integer protocol fields and slices.
287
288 When testing for TCP SYN packets, you can write:
289
290     tcp.flags & 0x02
291
292 That expression will match all packets that contain a "tcp.flags" field
293 with the 0x02 bit, i.e. the SYN bit, set.
294
295 Similarly, filtering for all WSP GET and extended GET methods is achieved with:
296
297     wsp.pdu_type & 0x40
298
299 When using slices, the bit mask must be specified as a byte string, and it must
300 have the same number of bytes as the slice itself, as in:
301
302     ip[42:2] & 40:ff
303
304 =head2 Logical expressions
305
306 Tests can be combined using logical expressions. 
307 These too are expressible in C-like syntax or with English-like
308 abbreviations:
309
310     and, &&   Logical AND
311     or,  ||   Logical OR
312     not, !    Logical NOT
313
314 Expressions can be grouped by parentheses as well.  The following are
315 all valid display filter expressions:
316
317     tcp.port == 80 and ip.src == 192.168.2.1
318     not llc
319     http and frame[100-199] contains "wireshark"
320     (ipx.src.net == 0xbad && ipx.src.node == 0.0.0.0.0.1) || ip
321
322 Remember that whenever a protocol or field name occurs in an expression, the
323 "exists" operator is implicitly called. The "exists" operator has the highest
324 priority. This means that the first filter expression must be read as "show me
325 the packets for which tcp.port exists and equals 80, and ip.src exists and
326 equals 192.168.2.1". The second filter expression means "show me the packets
327 where not (llc exists)", or in other words "where llc does not exist" and hence
328 will match all packets that do not contain the llc protocol.
329 The third filter expression includes the constraint that offset 199 in the
330 frame exists, in other words the length of the frame is at least 200.
331
332 A special caveat must be given regarding fields that occur more than
333 once per packet.  "ip.addr" occurs twice per IP packet, once for the
334 source address, and once for the destination address.  Likewise,
335 "tr.rif.ring" fields can occur more than once per packet.  The following
336 two expressions are not equivalent:
337
338         ip.addr ne 192.168.4.1
339     not ip.addr eq 192.168.4.1
340
341 The first filter says "show me packets where an ip.addr exists that
342 does not equal 192.168.4.1".  That is, as long as one ip.addr in the
343 packet does not equal 192.168.4.1, the packet passes the display
344 filter.  The other ip.addr could equal 192.168.4.1 and the packet would
345 still be displayed.
346 The second filter says "don't show me any packets that have an
347 ip.addr field equal to 192.168.4.1".  If one ip.addr is 192.168.4.1,
348 the packet does not pass.  If B<neither> ip.addr field is 192.168.4.1,
349 then the packet is displayed.
350
351 It is easy to think of the 'ne' and 'eq' operators as having an implicit
352 "exists" modifier when dealing with multiply-recurring fields.  "ip.addr
353 ne 192.168.4.1" can be thought of as "there exists an ip.addr that does
354 not equal 192.168.4.1".  "not ip.addr eq 192.168.4.1" can be thought of as
355 "there does not exist an ip.addr equal to 192.168.4.1".
356
357 Be careful with multiply-recurring fields; they can be confusing.
358
359 Care must also be taken when using the display filter to remove noise
360 from the packet trace. If, for example, you want to filter out all IP
361 multicast packets to address 224.1.2.3, then using:
362
363     ip.dst ne 224.1.2.3
364
365 may be too restrictive. Filtering with "ip.dst" selects only those
366 B<IP> packets that satisfy the rule. Any other packets, including all
367 non-IP packets, will not be displayed. To display the non-IP
368 packets as well, you can use one of the following two expressions:
369
370     not ip or ip.dst ne 224.1.2.3
371     not ip.addr eq 224.1.2.3
372
373 The first filter uses "not ip" to include all non-IP packets and then
374 lets "ip.dst ne 224.1.2.3" filter out the unwanted IP packets. The
375 second filter has already been explained above where filtering with
376 multiply occurring fields was discussed.
377
378 =head1 FILTER FIELD REFERENCE
379
380 The entire list of display filters is too large to list here. You can
381 can find references and examples at the following locations:
382
383 =over 4
384
385 =item
386
387 The online Display Filter Reference: L<http://www.wireshark.org/docs/dfref/>
388
389 =item
390
391 I<Help:Supported Protocols> in Wireshark
392
393 =item
394
395 C<tshark -G fields> on the command line
396
397 =item
398
399 The Wireshark wiki: L<http://wiki.wireshark.org/DisplayFilters>
400
401 =back
402
403 =head1 NOTES
404
405 The B<wireshark-filters> manpage is part of the B<Wireshark> distribution.
406 The latest version of B<Wireshark> can be found at
407 L<http://www.wireshark.org>.
408
409 Regular expressions in the "matches" operator are provided with B<libpcre>,
410 the Perl-Compatible Regular Expressions library: see B<http://www.pcre.org/>.
411
412 This manpage does not describe the capture filter syntax, which is
413 different. See the manual page of pcap-filter(7) or, if that doesn't exist,
414 tcpdump(8), or, if that doesn't exist, L<http://wiki.wireshark.org/CaptureFilters>
415 for a description of capture filters.
416
417 =head1 SEE ALSO
418
419 wireshark(1), tshark(1), editcap(1), pcap(3), pcap-filter(7) or tcpdump(8) if it
420 doesn't exist.
421
422 =head1 AUTHORS
423
424 See the list of authors in the B<Wireshark> man page for a list of authors of
425 that code.