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