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