1PCAP-FILTER(7)         Miscellaneous Information Manual         PCAP-FILTER(7)
2
3
4

NAME

6       pcap-filter - packet filter syntax
7

DESCRIPTION

9       pcap_compile()  is used to compile a string into a filter program.  The
10       resulting filter program can then be applied to some stream of  packets
11       to  determine  which packets will be supplied to pcap_loop(), pcap_dis‐
12       patch(), pcap_next(), or pcap_next_ex().
13
14       The filter expression consists of one or more  primitives.   Primitives
15       usually consist of an id (name or number) preceded by one or more qual‐
16       ifiers.  There are three different kinds of qualifier:
17
18       type   type qualifiers say what kind of thing the  id  name  or  number
19              refers  to.   Possible types are host, net , port and portrange.
20              E.g., `host foo', `net 128.3', `port 20', `portrange 6000-6008'.
21              If there is no type qualifier, host is assumed.
22
23       dir    dir qualifiers specify a particular transfer direction to and/or
24              from id.  Possible directions are src, dst, src or dst, src  and
25              dst,  ra,  ta, addr1, addr2, addr3, and addr4.  E.g., `src foo',
26              `dst net 128.3', `src or dst port ftp-data'.  If there is no dir
27              qualifier,  src  or  dst  is assumed.  The ra, ta, addr1, addr2,
28              addr3, and addr4 qualifiers are only valid for IEEE 802.11 Wire‐
29              less  LAN  link  layers.  For some link layers, such as SLIP and
30              the ``cooked'' Linux capture mode used for  the  ``any''  device
31              and for some other device types, the inbound and outbound quali‐
32              fiers can be used to specify a desired direction.
33
34       proto  proto qualifiers restrict the match to  a  particular  protocol.
35              Possible  protos are: ether, fddi, tr, wlan, ip, ip6, arp, rarp,
36              decnet, tcp and udp.  E.g., `ether src foo',  `arp  net  128.3',
37              `tcp   port   21',   `udp   portrange  7000-7009',  `wlan  addr2
38              0:2:3:4:5:6'.  If there is no  proto  qualifier,  all  protocols
39              consistent  with  the  type  are assumed.  E.g., `src foo' means
40              `(ip or arp or rarp) src foo' (except the latter  is  not  legal
41              syntax), `net bar' means `(ip or arp or rarp) net bar' and `port
42              53' means `(tcp or udp) port 53'.
43
44       [`fddi' is actually an alias for `ether'; the parser treats them  iden‐
45       tically  as meaning ``the data link level used on the specified network
46       interface.''  FDDI headers contain Ethernet-like source and destination
47       addresses,  and  often  contain  Ethernet-like packet types, so you can
48       filter on these FDDI fields just as with the analogous Ethernet fields.
49       FDDI  headers  also  contain  other  fields,  but  you cannot name them
50       explicitly in a filter expression.
51
52       Similarly, `tr' and `wlan' are aliases for `ether'; the previous  para‐
53       graph's  statements  about  FDDI  headers  also apply to Token Ring and
54       802.11 wireless LAN  headers.   For  802.11  headers,  the  destination
55       address  is  the  DA  field and the source address is the SA field; the
56       BSSID, RA, and TA fields aren't tested.]
57
58       In addition to the above, there are some special  `primitive'  keywords
59       that  don't  follow  the pattern: gateway, broadcast, less, greater and
60       arithmetic expressions.  All of these are described below.
61
62       More complex filter expressions are built up by using the words and, or
63       and  not  to  combine primitives.  E.g., `host foo and not port ftp and
64       not port ftp-data'.  To save typing, identical qualifier lists  can  be
65       omitted.  E.g., `tcp dst port ftp or ftp-data or domain' is exactly the
66       same as `tcp dst port ftp or tcp dst port  ftp-data  or  tcp  dst  port
67       domain'.
68
69       Allowable primitives are:
70
71       dst host host
72              True  if  the  IPv4/v6  destination field of the packet is host,
73              which may be either an address or a name.
74
75       src host host
76              True if the IPv4/v6 source field of the packet is host.
77
78       host host
79              True if either the IPv4/v6 source or destination of  the  packet
80              is host.
81
82              Any of the above host expressions can be prepended with the key‐
83              words, ip, arp, rarp, or ip6 as in:
84                   ip host host
85              which is equivalent to:
86                   ether proto \ip and host host
87              If host is a name with multiple IP addresses, each address  will
88              be checked for a match.
89
90       ether dst ehost
91              True if the Ethernet destination address is ehost.  Ehost may be
92              either a name from /etc/ethers or a number (see  ethers(3N)  for
93              numeric format).
94
95       ether src ehost
96              True if the Ethernet source address is ehost.
97
98       ether host ehost
99              True  if  either  the  Ethernet source or destination address is
100              ehost.
101
102       gateway host
103              True if the packet used host as a gateway.  I.e.,  the  Ethernet
104              source or destination address was host but neither the IP source
105              nor the IP destination was host.  Host must be a name  and  must
106              be  found  both by the machine's host-name-to-IP-address resolu‐
107              tion mechanisms (host name file, DNS,  NIS,  etc.)  and  by  the
108              machine's   host-name-to-Ethernet-address  resolution  mechanism
109              (/etc/ethers, etc.).  (An equivalent expression is
110                   ether host ehost and not host host
111              which can be used with  either  names  or  numbers  for  host  /
112              ehost.)  This syntax does not work in IPv6-enabled configuration
113              at this moment.
114
115       dst net net
116              True if the IPv4/v6 destination address of the packet has a net‐
117              work  number of net.  Net may be either a name from the networks
118              database (/etc/networks, etc.) or a  network  number.   An  IPv4
119              network   number   can  be  written  as  a  dotted  quad  (e.g.,
120              192.168.1.0), dotted triple (e.g., 192.168.1), dotted pair (e.g,
121              172.16),   or   single   number   (e.g.,  10);  the  netmask  is
122              255.255.255.255 for a dotted quad (which means that it's  really
123              a  host  match),  255.255.255.0 for a dotted triple, 255.255.0.0
124              for a dotted pair, or 255.0.0.0 for a single  number.   An  IPv6
125              network  number  must  be  written  out  fully;  the  netmask is
126              ff:ff:ff:ff:ff:ff:ff:ff, so IPv6 "network"  matches  are  really
127              always  host  matches,  and  a  network match requires a netmask
128              length.
129
130       src net net
131              True if the IPv4/v6 source address of the packet has  a  network
132              number of net.
133
134       net net
135              True  if either the IPv4/v6 source or destination address of the
136              packet has a network number of net.
137
138       net net mask netmask
139              True if the IPv4 address matches net with the specific  netmask.
140              May  be qualified with src or dst.  Note that this syntax is not
141              valid for IPv6 net.
142
143       net net/len
144              True if the IPv4/v6 address matches net with a netmask len  bits
145              wide.  May be qualified with src or dst.
146
147       dst port port
148              True if the packet is ip/tcp, ip/udp, ip6/tcp or ip6/udp and has
149              a destination port value of port.  The port can be a number or a
150              name used in /etc/services (see tcp(4P) and udp(4P)).  If a name
151              is used, both the port number and protocol are  checked.   If  a
152              number  or  ambiguous  name  is  used,  only  the port number is
153              checked (e.g., dst port 513 will print  both  tcp/login  traffic
154              and  udp/who traffic, and port domain will print both tcp/domain
155              and udp/domain traffic).
156
157       src port port
158              True if the packet has a source port value of port.
159
160       port port
161              True if either the source or destination port of the  packet  is
162              port.
163
164       dst portrange port1-port2
165              True if the packet is ip/tcp, ip/udp, ip6/tcp or ip6/udp and has
166              a destination port value between port1  and  port2.   port1  and
167              port2  are interpreted in the same fashion as the port parameter
168              for port.
169
170       src portrange port1-port2
171              True if the packet has a source port  value  between  port1  and
172              port2.
173
174       portrange port1-port2
175              True  if  either the source or destination port of the packet is
176              between port1 and port2.
177
178              Any of the above port or port range expressions can be prepended
179              with the keywords, tcp or udp, as in:
180                   tcp src port port
181              which matches only tcp packets whose source port is port.
182
183       less length
184              True  if  the  packet has a length less than or equal to length.
185              This is equivalent to:
186                   len <= length.
187
188       greater length
189              True if the packet has a length greater than or equal to length.
190              This is equivalent to:
191                   len >= length.
192
193       ip proto protocol
194              True  if  the  packet is an IPv4 packet (see ip(4P)) of protocol
195              type protocol.  Protocol can be a number or  one  of  the  names
196              icmp,  icmp6, igmp, igrp, pim, ah, esp, vrrp, udp, or tcp.  Note
197              that the identifiers tcp, udp, and icmp are  also  keywords  and
198              must  be  escaped via backslash (\), which is \\ in the C-shell.
199              Note that this primitive does  not  chase  the  protocol  header
200              chain.
201
202       ip6 proto protocol
203              True  if the packet is an IPv6 packet of protocol type protocol.
204              Note that this primitive does  not  chase  the  protocol  header
205              chain.
206
207       proto protocol
208              True  if  the  packet is an IPv4 or IPv6 packet of protocol type
209              protocol.  Note that this primitive does not chase the  protocol
210              header chain.
211
212       tcp, udp, icmp
213              Abbreviations for:
214                   proto p
215              where p is one of the above protocols.
216
217       ip6 protochain protocol
218              True  if the packet is IPv6 packet, and contains protocol header
219              with type protocol in its protocol header chain.  For example,
220                   ip6 protochain 6
221              matches any IPv6 packet with TCP protocol header in the protocol
222              header  chain.  The packet may contain, for example, authentica‐
223              tion  header,  routing  header,  or  hop-by-hop  option  header,
224              between  IPv6  header  and  TCP header.  The BPF code emitted by
225              this primitive is complex and cannot be  optimized  by  the  BPF
226              optimizer code, so this can be somewhat slow.
227
228       ip protochain protocol
229              Equivalent to ip6 protochain protocol, but this is for IPv4.
230
231       protochain protocol
232              True  if  the  packet is an IPv4 or IPv6 packet of protocol type
233              protocol.  Note that this primitive chases the  protocol  header
234              chain.
235
236       ether broadcast
237              True  if  the packet is an Ethernet broadcast packet.  The ether
238              keyword is optional.
239
240       ip broadcast
241              True if the packet is an IPv4 broadcast packet.  It  checks  for
242              both  the  all-zeroes  and  all-ones  broadcast conventions, and
243              looks up the subnet mask on the interface on which  the  capture
244              is being done.
245
246              If  the  subnet  mask  of  the interface on which the capture is
247              being done is not available, either  because  the  interface  on
248              which  capture  is being done has no netmask or because the cap‐
249              ture is being done on the Linux "any" interface, which can  cap‐
250              ture  on  more than one interface, this check will not work cor‐
251              rectly.
252
253       ether multicast
254              True if the packet is an Ethernet multicast packet.   The  ether
255              keyword is optional.  This is shorthand for `ether[0] & 1 != 0'.
256
257       ip multicast
258              True if the packet is an IPv4 multicast packet.
259
260       ip6 multicast
261              True if the packet is an IPv6 multicast packet.
262
263       ether proto protocol
264              True if the packet is of ether type protocol.  Protocol can be a
265              number or one of the names ip, ip6, arp, rarp, atalk, aarp, dec‐
266              net,  sca,  lat,  mopdl, moprc, iso, stp, ipx, or netbeui.  Note
267              these identifiers are also keywords  and  must  be  escaped  via
268              backslash (\).
269
270              [In  the  case  of  FDDI (e.g., `fddi protocol arp'), Token Ring
271              (e.g., `tr protocol arp'), and IEEE 802.11 wireless LANS  (e.g.,
272              `wlan  protocol arp'), for most of those protocols, the protocol
273              identification comes from the 802.2 Logical Link  Control  (LLC)
274              header, which is usually layered on top of the FDDI, Token Ring,
275              or 802.11 header.
276
277              When filtering for most  protocol  identifiers  on  FDDI,  Token
278              Ring, or 802.11, the filter checks only the protocol ID field of
279              an LLC header in so-called SNAP format  with  an  Organizational
280              Unit Identifier (OUI) of 0x000000, for encapsulated Ethernet; it
281              doesn't check whether the packet is in SNAP format with  an  OUI
282              of 0x000000.  The exceptions are:
283
284              iso    the  filter  checks  the DSAP (Destination Service Access
285                     Point) and SSAP (Source Service Access Point)  fields  of
286                     the LLC header;
287
288              stp and netbeui
289                     the filter checks the DSAP of the LLC header;
290
291              atalk  the filter checks for a SNAP-format packet with an OUI of
292                     0x080007 and the AppleTalk etype.
293
294              In the case of Ethernet, the filter  checks  the  Ethernet  type
295              field for most of those protocols.  The exceptions are:
296
297              iso, stp, and netbeui
298                     the  filter checks for an 802.3 frame and then checks the
299                     LLC header as it does for FDDI, Token Ring, and 802.11;
300
301              atalk  the filter checks both for the AppleTalk etype in an Eth‐
302                     ernet  frame  and for a SNAP-format packet as it does for
303                     FDDI, Token Ring, and 802.11;
304
305              aarp   the filter checks for the AppleTalk ARP etype  in  either
306                     an  Ethernet  frame or an 802.2 SNAP frame with an OUI of
307                     0x000000;
308
309              ipx    the filter checks for the IPX etype in an Ethernet frame,
310                     the  IPX  DSAP  in the LLC header, the 802.3-with-no-LLC-
311                     header encapsulation of IPX, and the IPX etype in a  SNAP
312                     frame.
313
314       ip, ip6, arp, rarp, atalk, aarp, decnet, iso, stp, ipx, netbeui
315              Abbreviations for:
316                   ether proto p
317              where p is one of the above protocols.
318
319       lat, moprc, mopdl
320              Abbreviations for:
321                   ether proto p
322              where p is one of the above protocols.  Note that not all appli‐
323              cations using pcap(3PCAP) currently know how to parse these pro‐
324              tocols.
325
326       decnet src host
327              True  if  the  DECNET  source  address  is host, which may be an
328              address of the form ``10.123'', or a DECNET host name.   [DECNET
329              host  name  support is only available on ULTRIX systems that are
330              configured to run DECNET.]
331
332       decnet dst host
333              True if the DECNET destination address is host.
334
335       decnet host host
336              True if either the DECNET source or destination address is host.
337
338       ifname interface
339              True if the packet was  logged  as  coming  from  the  specified
340              interface  (applies only to packets logged by OpenBSD's or Free‐
341              BSD's pf(4)).
342
343       on interface
344              Synonymous with the ifname modifier.
345
346       rnr num
347              True if the packet was logged as matching the specified PF  rule
348              number (applies only to packets logged by OpenBSD's or FreeBSD's
349              pf(4)).
350
351       rulenum num
352              Synonymous with the rnr modifier.
353
354       reason code
355              True if the packet was logged with the specified PF reason code.
356              The known codes are: match, bad-offset, fragment, short, normal‐
357              ize, and memory (applies only to packets logged by OpenBSD's  or
358              FreeBSD's pf(4)).
359
360       rset name
361              True if the packet was logged as matching the specified PF rule‐
362              set name of an anchored ruleset (applies only to packets  logged
363              by OpenBSD's or FreeBSD's pf(4)).
364
365       ruleset name
366              Synonomous with the rset modifier.
367
368       srnr num
369              True  if the packet was logged as matching the specified PF rule
370              number of an anchored ruleset (applies only to packets logged by
371              OpenBSD's or FreeBSD's pf(4)).
372
373       subrulenum num
374              Synonomous with the srnr modifier.
375
376       action act
377              True if PF took the specified action when the packet was logged.
378              Known actions are: pass and block and, with  later  versions  of
379              pf(4)),  nat,  rdr,  binat  and  scrub  (applies only to packets
380              logged by OpenBSD's or FreeBSD's pf(4)).
381
382       wlan ra ehost
383              True if the IEEE 802.11 RA is ehost.  The RA field  is  used  in
384              all frames except for management frames.
385
386       wlan ta ehost
387              True  if  the  IEEE 802.11 TA is ehost.  The TA field is used in
388              all frames except for management frames and CTS (Clear To  Send)
389              and ACK (Acknowledgment) control frames.
390
391       wlan addr1 ehost
392              True if the first IEEE 802.11 address is ehost.
393
394       wlan addr2 ehost
395              True  if  the  second IEEE 802.11 address, if present, is ehost.
396              The second address field is used in all frames  except  for  CTS
397              (Clear To Send) and ACK (Acknowledgment) control frames.
398
399       wlan addr3 ehost
400              True  if  the  third  IEEE 802.11 address, if present, is ehost.
401              The third address field is used in management and  data  frames,
402              but not in control frames.
403
404       wlan addr4 ehost
405              True  if  the  fourth IEEE 802.11 address, if present, is ehost.
406              The fourth address field is only used for WDS (Wireless  Distri‐
407              bution System) frames.
408
409       type wlan_type
410              True  if  the  IEEE  802.11  frame  type  matches  the specified
411              wlan_type.  Valid wlan_types are: mgt, ctl and data.
412
413       type wlan_type subtype wlan_subtype
414              True if  the  IEEE  802.11  frame  type  matches  the  specified
415              wlan_type and frame subtype matches the specified wlan_subtype.
416
417              If the specified wlan_type is mgt, then valid wlan_subtypes are:
418              assoc-req,  assoc-resp,  reassoc-req,  reassoc-resp,  probe-req,
419              probe-resp, beacon, atim, disassoc, auth and deauth.
420
421              If the specified wlan_type is ctl, then valid wlan_subtypes are:
422              ps-poll, rts, cts, ack, cf-end and cf-end-ack.
423
424              If the specified wlan_type is  data,  then  valid  wlan_subtypes
425              are:  data,  data-cf-ack,  data-cf-poll, data-cf-ack-poll, null,
426              cf-ack, cf-poll, cf-ack-poll,  qos-data,  qos-data-cf-ack,  qos-
427              data-cf-poll, qos-data-cf-ack-poll, qos, qos-cf-poll and qos-cf-
428              ack-poll.
429
430       subtype wlan_subtype
431              True if the IEEE 802.11  frame  subtype  matches  the  specified
432              wlan_subtype  and  frame  has  the  type  to which the specified
433              wlan_subtype belongs.
434
435       dir dir
436              True if the IEEE 802.11 frame direction  matches  the  specified
437              dir.   Valid  directions  are:  nods, tods, fromds, dstods, or a
438              numeric value.
439
440       vlan [vlan_id]
441              True if the packet is an IEEE 802.1Q VLAN packet.  If  [vlan_id]
442              is specified, only true if the packet has the specified vlan_id.
443              Note that the  first  vlan  keyword  encountered  in  expression
444              changes  the decoding offsets for the remainder of expression on
445              the assumption that the packet  is  a  VLAN  packet.   The  vlan
446              [vlan_id]  expression  may  be used more than once, to filter on
447              VLAN hierarchies.  Each use of that  expression  increments  the
448              filter offsets by 4.
449
450              For example:
451                   vlan 100 && vlan 200
452              filters on VLAN 200 encapsulated within VLAN 100, and
453                   vlan && vlan 300 && ip
454              filters  IPv4  protocols  encapsulated  in VLAN 300 encapsulated
455              within any higher order VLAN.
456
457       mpls [label_num]
458              True if the packet is an MPLS packet.  If [label_num] is  speci‐
459              fied, only true is the packet has the specified label_num.  Note
460              that the first mpls keyword encountered  in  expression  changes
461              the  decoding  offsets  for  the  remainder of expression on the
462              assumption that the packet is  a  MPLS-encapsulated  IP  packet.
463              The  mpls  [label_num] expression may be used more than once, to
464              filter on MPLS hierarchies.  Each use of that expression  incre‐
465              ments the filter offsets by 4.
466
467              For example:
468                   mpls 100000 && mpls 1024
469              filters packets with an outer label of 100000 and an inner label
470              of 1024, and
471                   mpls && mpls 1024 && host 192.9.200.1
472              filters packets to or from 192.9.200.1 with an  inner  label  of
473              1024 and any outer label.
474
475       pppoed True if the packet is a PPP-over-Ethernet Discovery packet (Eth‐
476              ernet type 0x8863).
477
478       pppoes [session_id]
479              True if the packet is a PPP-over-Ethernet Session packet (Ether‐
480              net  type  0x8864).   If [session_id] is specified, only true if
481              the packet has the specified session_id.  Note  that  the  first
482              pppoes  keyword  encountered  in expression changes the decoding
483              offsets for the remainder of expression on the  assumption  that
484              the packet is a PPPoE session packet.
485
486              For example:
487                   pppoes 0x27 && ip
488              filters IPv4 protocols encapsulated in PPPoE session id 0x27.
489
490       iso proto protocol
491              True  if  the packet is an OSI packet of protocol type protocol.
492              Protocol can be a number or one of  the  names  clnp,  esis,  or
493              isis.
494
495       clnp, esis, isis
496              Abbreviations for:
497                   iso proto p
498              where p is one of the above protocols.
499
500       l1, l2, iih, lsp, snp, csnp, psnp
501              Abbreviations for IS-IS PDU types.
502
503       vpi n  True if the packet is an ATM packet, for SunATM on Solaris, with
504              a virtual path identifier of n.
505
506       vci n  True if the packet is an ATM packet, for SunATM on Solaris, with
507              a virtual channel identifier of n.
508
509       lane   True  if the packet is an ATM packet, for SunATM on Solaris, and
510              is an ATM LANE packet.  Note that the first lane keyword encoun‐
511              tered  in  expression changes the tests done in the remainder of
512              expression on the assumption that the packet is  either  a  LANE
513              emulated  Ethernet  packet or a LANE LE Control packet.  If lane
514              isn't specified, the tests are done under  the  assumption  that
515              the packet is an LLC-encapsulated packet.
516
517       llc    True  if the packet is an ATM packet, for SunATM on Solaris, and
518              is an LLC-encapsulated packet.
519
520       oamf4s True if the packet is an ATM packet, for SunATM on Solaris,  and
521              is a segment OAM F4 flow cell (VPI=0 & VCI=3).
522
523       oamf4e True  if the packet is an ATM packet, for SunATM on Solaris, and
524              is an end-to-end OAM F4 flow cell (VPI=0 & VCI=4).
525
526       oamf4  True if the packet is an ATM packet, for SunATM on Solaris,  and
527              is  a  segment  or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 |
528              VCI=4)).
529
530       oam    True if the packet is an ATM packet, for SunATM on Solaris,  and
531              is  a  segment  or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 |
532              VCI=4)).
533
534       metac  True if the packet is an ATM packet, for SunATM on Solaris,  and
535              is on a meta signaling circuit (VPI=0 & VCI=1).
536
537       bcc    True  if the packet is an ATM packet, for SunATM on Solaris, and
538              is on a broadcast signaling circuit (VPI=0 & VCI=2).
539
540       sc     True if the packet is an ATM packet, for SunATM on Solaris,  and
541              is on a signaling circuit (VPI=0 & VCI=5).
542
543       ilmic  True  if the packet is an ATM packet, for SunATM on Solaris, and
544              is on an ILMI circuit (VPI=0 & VCI=16).
545
546       connectmsg
547              True if the packet is an ATM packet, for SunATM on Solaris,  and
548              is  on  a signaling circuit and is a Q.2931 Setup, Call Proceed‐
549              ing, Connect, Connect Ack, Release, or Release Done message.
550
551       metaconnect
552              True if the packet is an ATM packet, for SunATM on Solaris,  and
553              is  on a meta signaling circuit and is a Q.2931 Setup, Call Pro‐
554              ceeding, Connect, Release, or Release Done message.
555
556       expr relop expr
557              True if the relation holds, where relop is one of >, <, >=,  <=,
558              =,  !=, and expr is an arithmetic expression composed of integer
559              constants (expressed in standard C syntax),  the  normal  binary
560              operators  [+,  -,  *,  /, &, |, <<, >>], a length operator, and
561              special packet data accessors.  Note that  all  comparisons  are
562              unsigned,  so that, for example, 0x80000000 and 0xffffffff are >
563              0.  To access data inside the packet, use the following syntax:
564                   proto [ expr : size ]
565              Proto is one of ether, fddi, tr, wlan, ppp, slip, link, ip, arp,
566              rarp,  tcp,  udp, icmp, ip6 or radio, and indicates the protocol
567              layer for the index operation.  (ether,  fddi,  wlan,  tr,  ppp,
568              slip  and  link all refer to the link layer. radio refers to the
569              "radio header" added to some 802.11 captures.)  Note  that  tcp,
570              udp and other upper-layer protocol types only apply to IPv4, not
571              IPv6 (this will be fixed in the future).  The byte offset, rela‐
572              tive to the indicated protocol layer, is given by expr.  Size is
573              optional and indicates the number  of  bytes  in  the  field  of
574              interest;  it  can  be either one, two, or four, and defaults to
575              one.  The length operator, indicated by the keyword  len,  gives
576              the length of the packet.
577
578              For  example, `ether[0] & 1 != 0' catches all multicast traffic.
579              The expression `ip[0] & 0xf != 5' catches all IPv4 packets  with
580              options.   The  expression  `ip[6:2]  & 0x1fff = 0' catches only
581              unfragmented IPv4 datagrams and frag  zero  of  fragmented  IPv4
582              datagrams.   This check is implicitly applied to the tcp and udp
583              index operations.  For instance, tcp[0] always means  the  first
584              byte  of  the  TCP  header, and never means the first byte of an
585              intervening fragment.
586
587              Some offsets and field values may be expressed as  names  rather
588              than  as  numeric  values.   The following protocol header field
589              offsets are available:  icmptype  (ICMP  type  field),  icmpcode
590              (ICMP code field), and tcpflags (TCP flags field).
591
592              The following ICMP type field values are available: icmp-echore‐
593              ply, icmp-unreach, icmp-sourcequench, icmp-redirect,  icmp-echo,
594              icmp-routeradvert,   icmp-routersolicit,   icmp-timxceed,  icmp-
595              paramprob, icmp-tstamp, icmp-tstampreply,  icmp-ireq,  icmp-ire‐
596              qreply, icmp-maskreq, icmp-maskreply.
597
598              The  following  TCP  flags  field values are available: tcp-fin,
599              tcp-syn, tcp-rst, tcp-push, tcp-ack, tcp-urg.
600
601       Primitives may be combined using:
602
603              A parenthesized group of primitives and  operators  (parentheses
604              are special to the Shell and must be escaped).
605
606              Negation (`!' or `not').
607
608              Concatenation (`&&' or `and').
609
610              Alternation (`||' or `or').
611
612       Negation  has  highest  precedence.  Alternation and concatenation have
613       equal precedence and associate left to right.  Note that  explicit  and
614       tokens, not juxtaposition, are now required for concatenation.
615
616       If an identifier is given without a keyword, the most recent keyword is
617       assumed.  For example,
618            not host vs and ace
619       is short for
620            not host vs and host ace
621       which should not be confused with
622            not ( host vs or ace )
623

EXAMPLES

625       To select all packets arriving at or departing from sundown:
626              host sundown
627
628       To select traffic between helios and either hot or ace:
629              host helios and \( hot or ace \)
630
631       To select all IP packets between ace and any host except helios:
632              ip host ace and not helios
633
634       To select all traffic between local hosts and hosts at Berkeley:
635              net ucb-ether
636
637       To select all ftp traffic through internet gateway snup:
638              gateway snup and (port ftp or ftp-data)
639
640       To select traffic neither sourced from nor destined for local hosts (if
641       you gateway to one other net, this stuff should never make it onto your
642       local net).
643              ip and not net localnet
644
645       To select the start and end packets (the SYN and FIN packets)  of  each
646       TCP conversation that involves a non-local host.
647              tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet
648
649       To  select  all  IPv4 HTTP packets to and from port 80, i.e. print only
650       packets that contain data, not, for example, SYN and  FIN  packets  and
651       ACK-only packets.  (IPv6 is left as an exercise for the reader.)
652              tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)
653
654       To select IP packets longer than 576 bytes sent through gateway snup:
655              gateway snup and ip[2:2] > 576
656
657       To select IP broadcast or multicast packets that were not sent via Eth‐
658       ernet broadcast or multicast:
659              ether[0] & 1 = 0 and ip[16] >= 224
660
661       To select all ICMP packets that are not  echo  requests/replies  (i.e.,
662       not ping packets):
663              icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
664

SEE ALSO

666       pcap(3PCAP)
667

BUGS

669       Please send problems, bugs, questions, desirable enhancements, etc. to:
670
671              tcpdump-workers@lists.tcpdump.org
672
673       Filter  expressions  on  fields  other than those in Token Ring headers
674       will not correctly handle source-routed Token Ring packets.
675
676       Filter expressions on fields other than those in  802.11  headers  will
677       not  correctly  handle  802.11 data packets with both To DS and From DS
678       set.
679
680       ip6 proto should chase header chain, but at this moment  it  does  not.
681       ip6 protochain is supplied for this behavior.
682
683       Arithmetic  expression  against  transport  layer headers, like tcp[0],
684       does not work against IPv6 packets.  It only looks at IPv4 packets.
685
686
687
688                                6 January 2008                  PCAP-FILTER(7)
Impressum