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.
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.
21 .TH PCAP-FILTER @MAN_MISC_INFO@ "27 March 2025"
23 pcap-filter \- packet filter syntax
28 .BR pcap_compile (3PCAP)
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 (3PCAP),
33 .BR pcap_dispatch (3PCAP),
34 .BR pcap_next (3PCAP),
36 .BR pcap_next_ex (3PCAP).
38 The \fIfilter expression\fP consists of one or more
40 Primitives usually consist of an
42 (a name, a number or something slightly more complex, such as a CIDR prefix)
43 preceded by one or more qualifiers.
45 different kinds of qualifier:
48 qualifiers restrict the match to a particular protocol.
49 (This should not be confused with the
51 type qualifier below.)
72 E.g., `\fBether src\fP foo', `\fBarp net\fP 128.3', `\fBtcp port\fP 21',
73 `\fBip proto\fP ospf', `\fBether proto\fP 0x88CC',
74 `\fBudp portrange\fP 7000-7009', `\fBwlan addr2\fP 0:2:3:4:5:6'.
77 qualifier, all protocols consistent with the type are assumed.
78 E.g., `\fBsrc\fP foo' means `\fB(ip6 or ip or arp or rarp) src\fP foo',
79 `\fBproto\fP tcp' means `\fB(ip6 or ip) proto\fP tcp'
80 `\fBnet\fP bar' means `\fB(ip6 or ip or arp or rarp) net\fP bar' and
81 `\fBport\fP 53' means `\fB(tcp or udp or sctp) port\fP 53'
82 (note that these examples use invalid syntax to illustrate the principle).
85 qualifiers specify a particular transfer direction to and/or from
87 Possible directions are
99 E.g., `\fBsrc\fP foo', `\fBdst net\fP 128.3', `\fBsrc or dst port\fP ftp-data'.
101 there is no dir qualifier, `\fBsrc or dst\fP' is assumed.
110 qualifiers are only valid for IEEE 802.11 Wireless LAN link layers.
113 qualifiers say what kind of thing the id name or number refers to.
123 E.g., `\fBhost\fP foo', `\fBnet\fP 128.3', `\fBport\fP 20', `\fBportrange\fP 6000-6008',
130 In primitives that follow this pattern each qualifier kind may be present at
131 most once, and if more than one kind is present, any
133 qualifier must be the first qualifier and any
135 qualifier must be the last qualifier, for example, `\fBtcp dst port\fP 80'.
136 Also not all combinations of these qualifier kinds are valid syntax. Some
137 make no sense in network protocols space, for example:
139 (Ethernet header has no ports),
141 (TCP header does not have layer 3 fields),
143 (in a protocol header the same protocol applies to both the source and the
144 destination), and so on. Some other combinations are not valid syntax because
145 they are not implemented, even though hypothetically could make sense, for
151 [\fBfddi\fP is actually an alias for \fBether\fP; the parser treats them
152 identically as meaning ``the data link level used on the specified
153 network interface''. FDDI headers contain Ethernet-like source
154 and destination addresses, and often contain Ethernet-like packet
155 types, so you can filter on these FDDI fields just as with the
156 analogous Ethernet fields.
157 FDDI headers also contain other fields,
158 but you cannot name them explicitly in a filter expression.
159 Similarly, \fBtr\fP and \fBwlan\fP are aliases for \fBether\fP; the
160 statements about FDDI headers also apply to Token Ring and 802.11 wireless
161 LAN headers. The same stands for the
168 For IEEE 802.11 headers, the destination address is the DA field and the
169 source address is the SA field. For both ARP and RARP headers, the
170 destination address is the TPA (Target Protocol Address) field and the
171 source address is the SPA (Sender Protocol Address) field.
173 In addition to the above, there are some special `primitive' keywords
174 that don't follow the pattern (for example:
185 packet data accessors and relations of two arithmetic expressions.
186 All of these are described below.
188 More complex filter expressions are built up by using the words
193 (or equivalently: `\fB&&\fP', `\fB||\fP' and `\fB!\fP' respectively)
194 to combine primitives.
195 E.g., `\fBhost\fP foo \fBand not port\fP ftp \fBand not port\fP ftp-data'.
196 To save typing, identical qualifier lists can be omitted.
198 `\fBtcp dst port\fP ftp \fBor\fP ftp-data \fBor\fP domain' is exactly the same as
199 `\fBtcp dst port\fP ftp \fBor tcp dst port\fP ftp-data \fBor tcp dst port\fP domain'.
201 .IP "\fBhost \fIhostnameaddr\fR"
202 True if the source or the destination ARP/IPv4/IPv6/RARP address of the packet is
204 May be qualified with a specific protocol
209 and/or a different direction
213 in the latter case the
215 keyword is optional. For example,
218 \fBip src \fIhostnameaddr\fR
221 for Ethernet-like link-layer types is equivalent to
224 \fBether proto \\\fRip \fBand ip src host \fIhostnameaddr\fR
229 may be either an address or a name. If it is a name with multiple IPv4/IPv6 addresses,
230 each address will be checked for a match.
231 .IP "\fBether host \fIethernameaddr\fP"
232 True if the source or the destination Ethernet/802.11/IPFC/ATM LANE/FDDI/Token Ring
233 address of the packet is
235 May be qualified with a different direction
244 may be either a name from /etc/ethers or a numerical MAC address of the
245 form "xx:xx:xx:xx:xx:xx", "xx.xx.xx.xx.xx.xx", "xx-xx-xx-xx-xx-xx",
246 "xxxx.xxxx.xxxx" or "xxxxxxxxxxxx",
247 where each "x" is a hex digit (0-9, a-f, or A-F).
248 .IP "\fBgateway\fP \fIhost\fP"
249 True if the packet used \fIhost\fP as a gateway.
250 I.e., the source or the destination Ethernet address was
252 but neither the source nor the destination ARP/IPv4/RARP address was
254 In this implementation this primitive is not available in IPv6-enabled
255 configuration. May be qualified with a specific protocol
262 \fBip gateway \fIhost\fR
268 \fBether host \fIethernameaddr \fBand not ip host \fIhostnameaddr\fR
271 which can be used with either names or numbers for
276 \fIHost\fP must be a name and
277 must be found both by the machine's host-name-to-IP-address resolution
278 mechanisms (host name file, DNS, NIS, etc.) and by the machine's
279 host-name-to-Ethernet-address resolution mechanism (/etc/ethers, etc.).
280 .IP "\fBnet \fInetnameaddr\fR"
281 True if the source or the destination ARP/IPv4/IPv6/RARP address of the packet
282 belongs to the specified network. May be qualified with a specific protocol
287 and/or a different direction
291 in the latter case the
293 keyword remains mandatory.
295 may be either a name from the networks database
296 (/etc/networks, etc.) or a network number.
298 An IPv4 network number can be written as a dotted quad (e.g., 192.168.1.0),
299 dotted triple (e.g., 192.168.1), dotted pair (e.g, 172.16), or single
300 number (e.g., 10); the netmask is 255.255.255.255 (/32) for a dotted quad
301 (which means that it's really a host match), 255.255.255.0 (/24) for a dotted
302 triple, 255.255.0.0 (/16) for a dotted pair, or 255.0.0.0 (/8) for a single number.
303 An IPv6 network number must be written out fully; the netmask is
304 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (/128), so in this primitive IPv6
305 "network" matches are really always host matches. For an actual IPv6 network
306 match see the `\fBnet \fInetaddr\fR/\fIlen\fR' primitive below.
307 .IP "\fBnet \fInetaddr\fR \fBmask \fInetmask\fR"
308 True if the source or the destination ARP/IPv4/RARP address of the packet
309 belongs to \fInetaddr\fR with the specified \fInetmask\fR. May be qualified
310 with a specific protocol
314 and/or a different direction
318 in the latter case the
320 keyword remains mandatory. In this implementation this primitive does not
321 support IPv6 networks.
327 use the IPv4 network number notation described above, except the "single
328 number" form is not valid in this primitive. For example,
331 \fBnet \fP192.168 \fBmask \fP255.255\fR
337 \fBnet \fP192.168.0.0 \fBmask \fP255.255.0.0\fR
343 can represent any 32-bit value, which is why the
344 `\fBnet \fI\%netaddr\fR/\fIlen\fR' primitive below is usually a better fit for
345 use cases that require the value to be strictly one of the 33 CIDR masks (from
347 .IP "\fBnet \fInetaddr\fR/\fIlen\fR"
348 True if the source or the destination ARP/IPv4/IPv6/RARP address of the packet
351 where the bit-length of the network mask equals
353 (in other words, the address belongs to the specified CIDR prefix). May be
354 qualified with a specific protocol
359 and/or a different direction
363 in the latter case the
369 is an integer between 0 and 32 (both inclusive) and
371 is the same as the above. For IPv6,
373 is an integer between 0 and 128 (both inclusive) and
375 is an IPv6 address. For the latter zero compression notation
377 is valid, but IPv4-mapped notation
378 .RB ( x:x:x:x:x:x:d.d.d.d )
379 is not. For both IPv4 and IPv6 the maximum value of
381 is equivalent to a host match and the 0 value (which implies an all-zeroes
384 matches any address. In the latter case this primitive reduces to matching
385 the specified (or implied) protocols only.
386 .IP "\fBport \fIportnamenum\fR"
387 True if the source or the destination TCP/UDP/SCTP port of an IPv4/IPv6 packet
390 For IPv4 this also implies that the packet is the first fragment or is not
391 fragmented. May be qualified with a specific layer 4 protocol
395 or a different direction
399 in the latter case the
401 keyword remains mandatory. Cannot be qualified with a specific layer 3
402 protocol (IPv4/IPv6) in the same primitive, but can be trivially combined with
403 other primitives to achieve the required effect, for example:
406 \fBip and tcp dst port \fP80\fR
410 The \fIportnamenum\fP can be a number or a name used in /etc/services (see
412 If a name is used, both the port
413 number and protocol are checked.
414 If a number or ambiguous name is used,
415 only the port number is checked (e.g., `\fBdst port\fR 513' will print both
416 tcp/login traffic and udp/who traffic, and `\fBport\fR domain' will print
417 both tcp/domain and udp/domain traffic).
418 .IP "\fBportrange \fIportnamenum1-portnamenum2\fR"
419 This is a more generic form of the above: true if the port number in the
424 (both inclusive), everything else holds the same meaning.
429 can be specified in either order. If the two values are equal, this primitive
430 has the same effect as the
433 .IP "\fBless \fIlength\fR"
434 True if the packet has a length less than or equal to \fIlength\fP.
435 This is equivalent to:
438 \fBlen <= \fIlength\fP
441 .IP "\fBgreater \fIlength\fR"
442 True if the packet has a length greater than or equal to \fIlength\fP.
443 This is equivalent to:
446 \fBlen >= \fIlength\fP
449 .IP "\fBip proto \fIprotocol\fR"
450 True if the packet is an IPv4 packet of protocol type \fIprotocol\fP.
451 \fIProtocol\fP can be a number or one of the names recognized by
452 .BR getprotobyname (3),
457 (only in Linux with glibc, FreeBSD, NetBSD, DragonFly BSD, and macOS),
461 (only in Haiku and OpenBSD),
468 Note that most of these example identifiers
469 are also keywords and must be escaped via backslash (\\).
470 Note that this primitive does not chase the protocol header chain.
473 .BR getprotobyname (3)
476 file to translate protocol names to numbers, and the
477 .B "getent protocols"
478 command lists the protocols recognised by the function. This is not entirely
479 so in AIX (which does not have the command), Haiku (which has the file at
480 .IR \%/system/data/network/protocols
481 and does not have the command), on Linux with musl libc (which hard-codes the
482 list of protocols) and on hosts that use a network database to resolve
483 protocol names to numbers (see
484 .BR nsswitch.conf (5)).
485 If a protocol name fails to translate to a number, this version of libpcap
486 will treat the filter expression as invalid.
487 .IP "\fBcarp\fR, \fBvrrp\fR"
512 \fBip proto \fIigrpval\fR
517 is 88 on DragonFly BSD, FreeBSD and macOS, and 9 on all other OSes. This
518 abbreviation should not be used in portable applications and may be removed
520 .IP "\fBip6 proto \fIprotocol\fR"
521 True if the packet is an IPv6 packet of protocol type \fIprotocol\fP.
522 (See `\fBip proto\fP' above for the meaning of \fIprotocol\fR.)
523 Note that the IPv6 variant of ICMP uses a different protocol number, named
525 in AIX, FreeBSD, illumos, Haiku, GNU/Hurd, Linux, macOS, NetBSD, OpenBSD,
527 Note that this primitive does not chase the protocol header chain.
535 .IP "\fBproto \fIprotocol\fR"
536 True if the packet is an IPv4 or IPv6 packet of protocol type
537 \fIprotocol\fP. (See `\fBip proto\fP' above for the meaning of
538 \fIprotocol\fP.) Note that this primitive does not chase the protocol
540 .IP "\fBah\fR, \fBesp\fR, \fBpim\fR, \fBsctp\fR, \fBtcp\fR, \fBudp\fR"
544 \fBproto \\\fIprotocol\fR
547 where \fIprotocol\fR is one of the above protocols.
548 .IP "\fBip6 protochain \fIprotocol\fR"
549 True if the packet is IPv6 packet,
550 and contains protocol header with type \fIprotocol\fR
551 in its protocol header chain.
552 (See `\fBip proto\fP' above for the meaning of \fIprotocol\fP.)
556 \fBip6 protochain\fR 6
559 matches any IPv6 packet with TCP protocol header in the protocol header chain.
560 The packet may contain, for example,
561 authentication header, routing header, or hop-by-hop option header,
562 between IPv6 header and TCP header.
563 The BPF code emitted by this primitive is complex and
564 cannot be optimized by the BPF optimizer code, and is not supported by
565 filter engines in the kernel, so this can be somewhat slow, and may
566 cause more packets to be dropped.
567 .IP "\fBip protochain \fIprotocol\fR"
568 Equivalent to \fBip6 protochain \fIprotocol\fR, but this is for IPv4.
569 (See `\fBip proto\fP' above for the meaning of \fIprotocol\fP.)
570 .IP "\fBprotochain \fIprotocol\fR"
571 True if the packet is an IPv4 or IPv6 packet of protocol type
572 \fIprotocol\fP. (See `\fBip proto\fP' above for the meaning of
573 \fIprotocol\fP.) Note that this primitive chases the protocol
575 .IP "\fBether broadcast\fR"
576 True if the destination Ethernet/802.11/IPFC/ARCnet/ATM LANE/FDDI/Token Ring address of
577 the packet is the broadcast address (e.g.
582 .IP "\fBip broadcast\fR"
583 True if the packet is an IPv4 packet with the host part of the destination
584 address being either all-ones or all-zeroes. This primitive requires to
585 specify the netmask, which cannot be done in the filter expression; the only
586 way to specify a netmask is via the
589 .BR \%pcap_compile ()
590 function. If a netmask has not been specified, an attempt to compile a
591 filter expression with this primitive will return an error.
593 Note that this primitive ignores the network part of the destination address,
594 thus it can match more packets than expected, especially if the interface has
595 multiple IPv4 addresses with different netmasks. For example, if the
596 interface has addresses 10.1.2.100/29 and 192.168.202.200/24 configured and
599 argument corresponds to the first address, its value will be
601 and the host mask value will be
603 This will match the expected two addresses in the first prefix (10.1.2.96 and
604 10.1.2.103), as well as 64 addresses in the second prefix (192.168.202.0,
605 192.168.202.7, 192.168.202.8, 192.168.202.15, 192.168.202.16 and so on), as
606 well as any other IPv4 address with the lowest 3 bits being all-ones or
607 all-zeroes (for example: 10.73.74.151, 192.168.50.63, 172.19.0.128) -- in
608 other words, 25% of the complete IPv4 address space. This is why in use
609 cases that require more precision it would be better to match the required
610 address(es) explicitly, for example:
613 \fBip dst host 10.1.2.96 or 10.1.2.103\fR
616 .IP "\fBether multicast\fR"
617 True if the destination Ethernet/802.11/IPFC/ARCnet/ATM LANE/FDDI/Token Ring address of
618 the packet is a multicast address (e.g.
619 .B "\%ether[0] & 1 != 0"
623 .IP "\fBip multicast\fR"
624 True if the packet is an IPv4 multicast packet.
625 .IP "\fBip6 multicast\fR"
626 True if the packet is an IPv6 multicast packet.
627 .IP "\fBether proto \fIprotocol\fR"
628 True if the packet is of ether type \fIprotocol\fR.
629 \fIProtocol\fP can be a number or one of the names
630 \fBaarp\fP, \fBarp\fP, \fBatalk\fP, \fBdecnet\fP, \fBip\fP, \fBip6\fP,
631 \fBipx\fP, \fBiso\fP, \fBlat\fP, \fBloopback\fP, \fBmopdl\fP, \fBmoprc\fP, \fBnetbeui\fP,
632 \fBrarp\fP, \fBsca\fP or \fBstp\fP.
633 Note these identifiers (except \fBloopback\fP) are also keywords
634 and must be escaped via backslash (\\).
636 [In the case of FDDI (e.g., `\fBfddi proto \\arp\fR'), Token Ring
637 (e.g., `\fBtr proto \\arp\fR'), and IEEE 802.11 wireless LANs (e.g.,
638 `\fBwlan proto \\arp\fR'), for most of those protocols, the
639 protocol identification comes from the 802.2 Logical Link Control (LLC)
640 header, which is usually layered on top of the FDDI, Token Ring, or
643 When filtering for most protocol identifiers on FDDI, Token Ring, or
644 802.11, the filter checks only the protocol ID field of an LLC header
645 in so-called SNAP format with an Organizational Unit Identifier (OUI) of
646 0x000000, for encapsulated Ethernet; it doesn't check whether the packet
647 is in SNAP format with an OUI of 0x000000.
652 the filter checks the DSAP (Destination Service Access Point) and
653 SSAP (Source Service Access Point) fields of the LLC header;
655 \fBstp\fP and \fBnetbeui\fP
656 the filter checks the DSAP of the LLC header;
659 the filter checks for a SNAP-format packet with an OUI of 0x080007
660 and the AppleTalk etype.
663 In the case of Ethernet, the filter checks the Ethernet type field
664 for most of those protocols. The exceptions are:
667 \fBiso\fP, \fBstp\fP, and \fBnetbeui\fP
668 the filter checks for an 802.3 frame and then checks the LLC header as
669 it does for FDDI, Token Ring, and 802.11;
672 the filter checks both for the AppleTalk etype in an Ethernet frame and
673 for a SNAP-format packet as it does for FDDI, Token Ring, and 802.11;
676 the filter checks for the AppleTalk ARP etype in either an Ethernet
677 frame or an 802.2 SNAP frame with an OUI of 0x000000;
680 the filter checks for the IPX etype in an Ethernet frame, the IPX
681 DSAP in the LLC header, the 802.3-with-no-LLC-header encapsulation of
682 IPX, and the IPX etype in a SNAP frame.
684 .IP "\fBip\fR, \fBip6\fR, \fBarp\fR, \fBrarp\fR, \fBatalk\fR, \fBaarp\fR, \fBdecnet\fR, \fBiso\fR, \fBstp\fR, \fBipx\fR, \fBnetbeui\fP"
688 \fBether proto \\\fIprotocol\fR
691 where \fIprotocol\fR is one of the above protocols.
692 .IP "\fBlat\fR, \fBmopdl\fR, \fBmoprc\fR, \fBsca\fR"
696 \fBether proto \\\fIprotocol\fR
699 where \fIprotocol\fR is one of the above protocols, all of which originated
700 at DEC, but are not the same as DECnet. Namely,
702 is Local Area Transport (LAT),
704 is DNA Dump/Load (MOP),
706 is DNA Remote Console (MOP) and
708 is System Communication Architecture (SCA).
709 .IP "\fBdecnet host \fIdecnetaddr\fR"
710 True if the source or the destination DECnet address of the packet is
712 May be qualified with a different direction
721 is an address of the form
722 .BR AREANUMBER.NODENUMBER ,
723 where the area number can be between 0 and 63 (both inclusive) and the node
724 number can be between 0 and 1023 (both inclusive) and both numbers always use
725 decimal base. For example:
728 \fBdecnet src \fP10.123\fR
732 True if the packet has an 802.2 LLC header. This includes:
734 Ethernet packets with a length field rather than a type field that
735 aren't raw NetWare-over-802.3 packets;
737 IEEE 802.11 data packets;
739 Token Ring packets (no check is done for LLC frames);
741 FDDI packets (no check is done for LLC frames);
743 LLC-encapsulated ATM packets, for SunATM on Solaris.
744 .IP "\fBllc\fP \fItype\fR"
745 True if the packet has an 802.2 LLC header and has the specified
761 Receiver Ready (RR) S PDUs
764 Receiver Not Ready (RNR) S PDUs
770 Unnumbered Information (UI) U PDUs
773 Unnumbered Acknowledgment (UA) U PDUs
776 Disconnect (DISC) U PDUs
779 Disconnected Mode (DM) U PDUs
782 Set Asynchronous Balanced Mode Extended (SABME) U PDUs
788 Exchange Identification (XID) U PDUs
791 Frame Reject (FRMR) U PDUs
794 Packet was received by the host performing the capture rather than being
795 sent by that host. This is only supported for certain link-layer types,
796 such as SLIP and the ``cooked'' Linux capture mode
797 used for the ``any'' device and for some other device types.
799 Packet was sent by the host performing the capture rather than being
800 received by that host. This is only supported for certain link-layer types,
801 such as SLIP and the ``cooked'' Linux capture mode
802 used for the ``any'' device and for some other device types.
803 .IP "\fBifindex \fIinterface_index\fR"
804 True if the packet was logged via the specified interface (applies only to
805 packets logged by the Linux "any" cooked v2 interface).
806 .IP "\fBifname \fIinterface\fR"
809 only, if the packet was logged as coming from the specified interface.
810 .IP "\fBon \fIinterface\fR"
814 .IP "\fBrnr \fInum\fR"
817 only, if the packet was logged as matching the specified PF rule number.
818 .IP "\fBrulenum \fInum\fR"
822 .IP "\fBreason \fIcode\fR"
825 only, if the packet was logged with the specified PF reason code. Valid
833 .BR \%bad-timestamp ,
837 .BR \%state-mismatch ,
849 (on OpenBSD only) and
852 .IP "\fBrset \fIname\fR"
855 only, if the packet was logged as matching the specified PF ruleset
856 name of an anchored ruleset.
857 .IP "\fBruleset \fIname\fR"
861 .IP "\fBsrnr \fInum\fR"
864 only, if the packet was logged as matching the specified PF rule number
865 of an anchored ruleset.
866 .IP "\fBsubrulenum \fInum\fR"
870 .IP "\fBaction \fIact\fR"
873 only, if PF took the specified action when the packet was logged. Valid
881 and, with later versions of
891 .BR \%synproxy-drop ,
893 (on FreeBSD and OpenBSD only),
910 .IP "\fBwlan ra \fIehost\fR"
911 True if the IEEE 802.11 RA is
913 The RA field is used in all frames except for management frames.
914 .IP "\fBwlan ta \fIehost\fR"
915 True if the IEEE 802.11 TA is
917 The TA field is used in all frames except for management frames and
918 CTS (Clear To Send) and ACK (Acknowledgment) control frames.
919 .IP "\fBwlan addr1 \fIehost\fR"
920 True if the first IEEE 802.11 address is
922 .IP "\fBwlan addr2 \fIehost\fR"
923 True if the second IEEE 802.11 address, if present, is
925 The second address field is used in all frames except for CTS (Clear To
926 Send) and ACK (Acknowledgment) control frames.
927 .IP "\fBwlan addr3 \fIehost\fR"
928 True if the third IEEE 802.11 address, if present, is
930 The third address field is used in management and data frames, but not
932 .IP "\fBwlan addr4 \fIehost\fR"
933 True if the fourth IEEE 802.11 address, if present, is
935 The fourth address field is only used for
936 WDS (Wireless Distribution System) frames.
937 .IP "\fBwlan type \fIwlan_type\fR"
938 True if the IEEE 802.11 frame type matches the specified \fIwlan_type\fR.
939 Valid \fIwlan_type\fRs are:
946 .IP "\fBwlan type \fIwlan_type \fBsubtype \fIwlan_subtype\fR"
947 True if the IEEE 802.11 frame type matches the specified \fIwlan_type\fR
948 and frame subtype matches the specified \fIwlan_subtype\fR.
953 If the specified \fIwlan_type\fR is \fBmgt\fP,
954 then valid \fIwlan_subtype\fRs are:
967 If the specified \fIwlan_type\fR is \fBctl\fP,
968 then valid \fIwlan_subtype\fRs are:
978 If the specified \fIwlan_type\fR is \fBdata\fP,
979 then valid \fIwlan_subtype\fRs are:
983 .BR \%data-cf-ack-poll ,
989 .BR \%qos-data-cf-ack ,
990 .BR \%qos-data-cf-poll ,
991 .BR \%qos-data-cf-ack-poll ,
995 .BR \%qos-cf-ack-poll .
996 .IP "\fBwlan subtype \fIwlan_subtype\fR"
997 True if the IEEE 802.11 frame subtype matches the specified \fIwlan_subtype\fR
998 and frame has the type to which the specified \fIwlan_subtype\fR belongs.
1001 keyword is optional.
1002 .IP "\fBwlan dir \fIdirection\fR"
1003 True if the IEEE 802.11 frame direction matches the specified
1005 Valid directions are:
1013 keyword is optional.
1014 .IP "\fBvlan \fI[vlan_id]\fR"
1015 True if the packet is an IEEE 802.1Q VLAN packet.
1016 If the optional \fIvlan_id\fR is specified, only true if the packet has the specified
1018 Note that the first \fBvlan\fR keyword encountered in an expression
1019 changes the decoding offsets for the remainder of the expression on
1020 the assumption that the packet is a VLAN packet. The `\fBvlan
1021 \fI[vlan_id]\fR` keyword may be used more than once, to filter on VLAN
1022 hierarchies. Each use of that keyword increments the filter offsets
1028 \fBvlan\fP 100 \fB&& vlan\fR 200
1031 filters on VLAN 200 encapsulated within VLAN 100, and
1034 \fBvlan && vlan \fP300 \fB&& ip\fR
1037 filters IPv4 protocol encapsulated in VLAN 300 encapsulated within any
1039 .IP "\fBmpls \fI[label_num]\fR"
1040 True if the packet is an MPLS packet.
1041 If the optional \fIlabel_num\fR is specified, only true if the packet has the specified
1043 Note that the first \fBmpls\fR keyword encountered in an expression
1044 changes the decoding offsets for the remainder of the expression on
1045 the assumption that the packet is a MPLS-encapsulated IP packet. The
1046 `\fBmpls \fI[label_num]\fR` keyword may be used more than once, to
1047 filter on MPLS hierarchies. Each use of that keyword increments the
1048 filter offsets by 4.
1053 \fBmpls\fP 100000 \fB&& mpls\fR 1024
1056 filters packets with an outer label of 100000 and an inner label of
1060 \fBmpls && mpls\fP 1024 \fB&& host\fR 192.9.200.1
1063 filters packets to or from 192.9.200.1 with an inner label of 1024 and
1066 True if the packet is a PPP-over-Ethernet Discovery packet (Ethernet
1068 .IP "\fBpppoes \fI[session_id]\fR"
1069 True if the packet is a PPP-over-Ethernet Session packet (Ethernet
1071 If the optional \fIsession_id\fR is specified, only true if the packet has the specified
1073 Note that the first \fBpppoes\fR keyword encountered in an expression
1074 changes the decoding offsets for the remainder of the expression on
1075 the assumption that the packet is a PPPoE session packet.
1080 \fBpppoes\fP 0x27 \fB&& ip\fR
1083 filters IPv4 protocol encapsulated in PPPoE session id 0x27.
1084 .IP "\fBgeneve \fI[vni]\fR"
1085 True if the packet is a Geneve packet (UDP port 6081). If the optional \fIvni\fR
1086 is specified, only true if the packet has the specified \fIvni\fR.
1087 Note that when the \fBgeneve\fR keyword is encountered in
1088 an expression, it changes the decoding offsets for the remainder of
1089 the expression on the assumption that the packet is a Geneve packet.
1094 \fBgeneve\fP 0xb \fB&& ip\fR
1097 filters IPv4 protocol encapsulated in Geneve with VNI 0xb. This will
1098 match both IPv4 directly encapsulated in Geneve as well as IPv4 contained
1099 inside an Ethernet frame.
1100 .IP "\fBvxlan \fI[vni]\fR"
1101 True if the packet is a VXLAN packet (UDP port 4789). If the optional
1102 \fIvni\fR is specified, only true if the packet has the specified
1103 \fIvni\fR. Note that when the \fBvxlan\fR keyword is encountered in
1104 an expression, it changes the decoding offsets for the remainder of
1105 the expression on the assumption that the packet is a VXLAN packet.
1110 \fBvxlan\fP 0x7 \fB&& ip6 \fR
1113 filters IPv6 protocol encapsulated in VXLAN with VNI 0x7.
1114 .IP "\fBiso proto \fIprotocol\fR"
1115 True if the packet is an OSI packet of protocol type \fIprotocol\fP.
1116 \fIProtocol\fP can be a number or one of the names
1117 \fBclnp\fP, \fBesis\fP, or \fBisis\fP.
1118 .IP "\fBclnp\fR, \fBesis\fR, \fBisis\fR"
1122 \fBiso proto \\\fIprotocol\fR
1125 where \fIprotocol\fR is one of the above protocols. Also in this context
1133 .IP "\fBisis proto \fIprotocol\fR"
1134 True if the packet is an IS-IS packet of protocol type
1136 which can be a number only.
1137 .IP "\fBl1\fR, \fBl2\fR, \fBiih\fR, \fBlsp\fR, \fBsnp\fR, \fBcsnp\fR, \fBpsnp\fR"
1138 Abbreviations for IS-IS PDU types.
1139 .IP "\fIatmfield relop val\fR"
1140 True if the packet is an ATM packet, for SunATM on Solaris, and the relation
1164 stand for the virtual path identifier (VPI) and the virtual channel
1165 identifier (VCI) fields respectively.
1166 .IP "\fIatmfield\fP \fIval\fR"
1170 \fIatmfield\fR == \fIval\fR
1173 in the expression above.
1174 .IP "\fIatmfield\fP (\fIval1\fR \fBor\fP ... \fBor\fP \fIvalN\fR)"
1178 (\fIatmfield\fP == \fIval1\fP \fBor\fP ... \fBor\fP \fIatmfield\fP == \fIvalN\fR)
1181 in the expression above.
1183 True if the packet is an ATM packet, for SunATM on Solaris, and is
1185 Note that the first \fBlane\fR keyword encountered in an expression
1186 changes the tests done in the remainder of the expression
1187 on the assumption that the packet is either a LANE emulated Ethernet
1188 packet or a LANE LE Control packet. If \fBlane\fR isn't specified, the
1189 tests are done under the assumption that the packet is an
1190 LLC-encapsulated packet.
1194 keyword enables primitives that do not apply to ATM in general, such as
1197 .BR "link multicast" .
1199 True if the packet is an ATM packet, for SunATM on Solaris, and is
1200 a segment OAM F4 flow cell (VPI=0 & VCI=3).
1202 True if the packet is an ATM packet, for SunATM on Solaris, and is
1203 an end-to-end OAM F4 flow cell (VPI=0 & VCI=4).
1205 True if the packet is an ATM packet, for SunATM on Solaris, and is
1206 a segment or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 | VCI=4)).
1208 True if the packet is an ATM packet, for SunATM on Solaris, and is
1209 a segment or end-to-end OAM F4 flow cell (VPI=0 & (VCI=3 | VCI=4)).
1211 True if the packet is an ATM packet, for SunATM on Solaris, and is
1212 on a meta signaling circuit (VPI=0 & VCI=1).
1214 True if the packet is an ATM packet, for SunATM on Solaris, and is
1215 on a broadcast signaling circuit (VPI=0 & VCI=2).
1217 True if the packet is an ATM packet, for SunATM on Solaris, and is
1218 on a signaling circuit (VPI=0 & VCI=5).
1220 True if the packet is an ATM packet, for SunATM on Solaris, and is
1221 on an ILMI circuit (VPI=0 & VCI=16).
1222 .IP \fBconnectmsg\fP
1223 True if the packet is an ATM packet, for SunATM on Solaris, and is
1224 on a signaling circuit and is a Q.2931 Setup, Call Proceeding, Connect,
1225 Connect Ack, Release, or Release Done message.
1226 .IP \fBmetaconnect\fP
1227 True if the packet is an ATM packet, for SunATM on Solaris, and is
1228 on a meta signaling circuit and is a Q.2931 Setup, Call Proceeding, Connect,
1229 Release, or Release Done message.
1231 True if the packet is a Fill-In Signal Unit (FISU) MTP2 packet.
1233 True if the packet is a Link Status Signal Unit (LSSU) MTP2 packet.
1235 True if the packet is a Message Signal Unit (MSU) MTP2 packet.
1236 .IP "\fImtpfield relop val\fR"
1237 True if the relation holds.
1260 stands for the Service Information Octet (SIO) field of the MTP2 MSU header.
1265 stand for the Destination Point Code (DPC), Originating Point Code (OPC) and
1266 Signalling Link Selection (SLS) fields respectively of the MTP3 standard
1268 .IP "\fImtpfield\fP \fIval\fR"
1272 \fImtpfield\fR == \fIval\fR
1275 in the expression above.
1276 .IP "\fImtpfield\fP (\fIval1\fR \fBor\fP ... \fBor\fP \fIvalN\fR)"
1280 (\fImtpfield\fP == \fIval1\fP \fBor\fP ... \fBor\fP \fImtpfield\fP == \fIvalN\fR)
1283 in the expression above.
1284 .IP "\fBhfisu\fR, \fBhlssu\fR, \fBhmsu\fR, \fBhsio\fR, \fBhdpc\fR, \fBhopc\fR, \fBhsls\fP"
1294 respectively, but only if the MTP2 link uses the extended sequence numbers
1295 encoding specified for high speed signalling links (HSL) in ITU-T
1296 Recommendation Q.703 Annex A.
1297 .IP "\fBlink host \fIarcnetaddr\fR"
1301 .BR \%DLT_ARCNET_LINUX ,
1302 if the source or the destination ARCnet address of the packet is
1304 May be qualified with a different direction
1307 .BR "src and dst" ),
1310 keyword is optional.
1313 is a string of the form
1317 where "x" is a hexadecimal digit. For example:
1320 \fBlink host \fP$2b\fR
1324 Also in ARCnet context
1329 .BR "\%link dst $0" .
1331 Note that this address syntax clashes with the parameter expansion syntax
1332 in POSIX-compatible shells and elsewhere, so depending on the use case the
1333 filter string may require the use of single quotes or a backslash.
1334 .IP "\fBbyte \fIidx op val\fR"
1335 True if the value of the link layer byte number
1337 satisfies a condition with regard to
1339 which can be a number only. The condition is one of: "equals to" (if
1351 "the result of bitwise AND is not zero" (if
1355 "the result of bitwise OR is not zero" (if
1360 The arithmetic expressions and packet data accessors below implement all of
1361 these and many other things much better, so this primitive will be removed in
1362 a future release and should not be used in applications that require forward
1364 .SH ARITHMETIC EXPRESSIONS
1365 Arithmetic expressions are the operands of a relational operator in a
1366 relation of the following form:
1369 \fIexpr1 relop expr2\fR
1372 This evaluates to true if and only if the relation holds.
1374 (the relational operator) is one of
1386 Each of \fIexpr1\fR and \fIexpr2\fR is an arithmetic expression composed of
1387 integer constants (expressed in standard C syntax), the common arithmetic and
1388 bitwise binary operations
1399 a length operator, and packet data accessors. All arithmetic expressions
1400 regardless of the complexity and composition resolve to an integer value.
1401 Note that all comparisons are unsigned, so that, for example, both 0x80000000
1402 and 0xffffffff are > 0.
1408 operators are currently only supported for filtering in the kernel on
1409 particular operating systems (for example: FreeBSD, Linux with 3.7 and later
1410 kernels, NetBSD); on all other systems (for example: AIX, Hurd, illumos, Solaris,
1412 those operators are used, filtering will be done in user mode, which
1413 will increase the overhead of capturing packets and may cause more
1414 packets to be dropped.
1416 The length operator, indicated by the keyword \fBlen\fP, gives the
1417 length of the packet.
1418 .SH PACKET DATA ACCESSORS
1419 To use the packet data in an arithmetic expression, use the following syntax:
1422 \fIproto\fB [ \fIexpr\fB : \fIsize\fB ]\fR
1457 indicates the protocol layer for the index operation.
1467 link layer, \fBradio\fR refers to the "radio header" added to some
1469 Note that \fBtcp\fR, \fBudp\fR and other upper-layer protocol types only
1470 apply to IPv4, not IPv6 (this will be fixed in the future).
1471 The byte offset, relative to the indicated protocol layer, is
1472 given by \fIexpr\fR, which can be an integer constant or any other valid
1473 arithmetic expression.
1474 \fISize\fR is optional and indicates the number of bytes in the
1475 field of interest; it can be either one, two, or four, and defaults to one;
1476 also it must be one of these valid integer constants only and cannot be a
1477 more complex expression.
1479 For example, `\fBether[\fP0\fB] &\fP 1 \fB!=\fP 0' catches all multicast traffic.
1480 The expression `\fBip[\fP0\fB] &\fP 0xf \fB!=\fP 5'
1481 catches all IPv4 packets with options.
1483 `\fBip[\fP6:2\fB] &\fP 0x1fff \fB=\fP 0'
1484 catches only unfragmented IPv4 datagrams and frag zero of fragmented
1486 This check is implicitly applied to the
1498 For instance, \fBtcp[\fP0\fB]\fP always means the first
1499 byte of the TCP \fIheader\fP, and never means the first byte of an
1500 intervening fragment.
1502 Some offsets and field values may be expressed as names rather than
1504 The following protocol header field offsets are
1505 available: \fBicmptype\fP (ICMP type field), \fBicmp6type\fP (ICMPv6 type field),
1506 \fBicmpcode\fP (ICMP code field), \fBicmp6code\fP (ICMPv6 code field) and
1507 \fBtcpflags\fP (TCP flags field).
1509 The following ICMP type field values are available:
1510 .BR \%icmp-echoreply ,
1511 .BR \%icmp-unreach ,
1512 .BR \%icmp-sourcequench ,
1513 .BR \%icmp-redirect ,
1515 .BR \%icmp-routeradvert ,
1516 .BR \%icmp-routersolicit ,
1517 .BR \%icmp-timxceed ,
1518 .BR \%icmp-paramprob ,
1520 .BR \%icmp-tstampreply ,
1522 .BR \%icmp-ireqreply ,
1523 .BR \%icmp-maskreq ,
1524 .BR \%icmp-maskreply .
1526 The following ICMPv6 type field values are available:
1527 .BR \%icmp6-destinationunreach ,
1528 .BR \%icmp6-packettoobig ,
1529 .BR \%icmp6-timeexceeded ,
1530 .BR \%icmp6-parameterproblem ,
1532 .BR \%icmp6-echoreply ,
1533 .BR \%icmp6-multicastlistenerquery ,
1534 .BR \%icmp6-multicastlistenerreportv1 ,
1535 .BR \%icmp6-multicastlistenerdone ,
1536 .BR \%icmp6-routersolicit ,
1537 .BR \%icmp6-routeradvert ,
1538 .BR \%icmp6-neighborsolicit ,
1539 .BR \%icmp6-neighboradvert ,
1540 .BR \%icmp6-redirect ,
1541 .BR \%icmp6-routerrenum ,
1542 .BR \%icmp6-nodeinformationquery ,
1543 .BR \%icmp6-nodeinformationresponse ,
1544 .BR \%icmp6-ineighbordiscoverysolicit ,
1545 .BR \%icmp6-ineighbordiscoveryadvert ,
1546 .BR \%icmp6-multicastlistenerreportv2 ,
1547 .BR \%icmp6-homeagentdiscoveryrequest ,
1548 .BR \%icmp6-homeagentdiscoveryreply ,
1549 .BR \%icmp6-mobileprefixsolicit ,
1550 .BR \%icmp6-mobileprefixadvert ,
1551 .BR \%icmp6-certpathsolicit ,
1552 .BR \%icmp6-certpathadvert ,
1553 .BR \%icmp6-multicastrouteradvert ,
1554 .BR \%icmp6-multicastroutersolicit ,
1555 .BR \%icmp6-multicastrouterterm .
1557 The following TCP flags field values are available: \fBtcp-fin\fP,
1558 \fBtcp-syn\fP, \fBtcp-rst\fP, \fBtcp-push\fP,
1559 \fBtcp-ack\fP, \fBtcp-urg\fP, \fBtcp-ece\fP,
1561 .SH COMPOUND EXPRESSIONS
1562 Primitives and relations may be combined using:
1566 Negation (`\fB!\fP' or `\fBnot\fP').
1568 Concatenation (`\fB&&\fP' or `\fBand\fP').
1570 Alternation (`\fB||\fP' or `\fBor\fP').
1572 Negation has the highest precedence.
1573 Alternation and concatenation have equal precedence and associate
1576 For primitives, if an identifier is given without a keyword, the most recent
1577 keyword is assumed. For example,
1580 \fBnot host\fP vs \fBand\fR ace
1586 \fBnot host\fP vs \fBand host\fR ace
1589 which should not be confused with
1592 \fBnot (host \fPvs\fB and host \fPace\fB)\fR
1595 .SH PROTOCOL NAMES IN VARIOUS CONTEXTS
1596 The table below shows which protocol names can be used in which contexts of
1597 the currently implemented syntax. The "name" column contains a protocol name,
1598 which often can be used as an ID in primitives that take a protocol name
1599 argument; in all cases except
1601 the protocol name is also a keyword. If the keyword is an alias, the "see"
1602 column refers to the main keyword. The "abbr" column tells whether the
1603 keyword can be used as an abbreviation (that is, if the keyword is the only
1604 contents of a primitive, it means a more complex expression). The "PDA"
1605 column tells whether the keyword can be used in a packet data accessor. The
1606 "pqual" column tells whether the keyword can be used as a case of the
1608 qualifier kind. If the name can be used as an ID for the
1612 qualifier kind, the "tqual ID" column shows the valid context(s).
1617 lB |lB |l |l |l |lB.
1618 name see abbr PDA pqual tqual ID
1620 aarp yes no no link proto \\aarp
1621 ah yes no no [ip|ip6] proto \\ah
1622 arp yes yes yes link proto \\arp
1623 atalk yes yes no link proto \\atalk
1624 carp yes yes no ip proto \\carp
1625 clnp yes no no iso proto \\clnp
1627 decnet yes yes yes link proto \\decnet
1628 esis yes no no iso proto \\esis
1630 esp yes no no [ip|ip6] proto \\esp
1633 icmp yes yes no ip proto \\icmp
1635 igmp yes yes no ip proto \\igmp
1636 igrp yes yes no ip proto \\igrp
1638 ip yes yes yes link proto \\ip
1639 ip6 yes yes yes link proto \\ip6
1640 ipx yes no no link proto \\ipx
1641 isis yes no yes iso proto \\isis
1643 iso yes no yes link proto \\iso
1646 lat yes yes no link proto \\lat
1648 loopback link proto loopback
1650 mopdl yes yes no link proto \\mopdl
1651 moprc yes yes no link proto \\moprc
1652 netbeui yes no no link proto \\netbeui
1653 pim yes yes no [ip|ip6] proto \\pim
1657 rarp yes yes yes link proto \\rarp
1658 sca yes yes no link proto \\sca
1659 sctp yes yes yes [ip|ip6] proto \\sctp
1662 stp yes no no link proto \\stp
1663 tcp yes yes yes [ip|ip6] proto \\tcp
1665 udp yes yes yes [ip|ip6] proto \\udp
1666 vrrp yes yes no ip proto \\vrrp
1672 To select all packets arriving at or departing from `sundown':
1679 To select traffic between `helios' and either `hot' or `ace':
1682 \fBhost\fP helios \fBand (\fPhot \fBor\fP ace\fB)\fP
1686 To select all IPv4 packets between `ace' and any host except `helios':
1689 \fBip host\fP ace \fBand not\fP helios
1693 To select all traffic between local hosts and hosts at Berkeley:
1700 To select all FTP traffic through Internet gateway `snup':
1703 \fBgateway\fP snup \fBand (port\fP ftp \fBor\fP ftp-data\fB)\fP
1707 To select IPv4 traffic neither sourced from nor destined for local hosts
1708 (if you gateway to one other net, this stuff should never make it
1709 onto your local net).
1712 \fBip and not net \fPlocalnet
1716 To select the start and end packets (the SYN and FIN packets) of each
1717 TCP conversation that involves a non-local host.
1720 \fBtcp[tcpflags] & (tcp-syn|tcp-fin) !=\fP 0 \fBand not src and dst net\fP localnet
1724 To select the TCP packets with flags RST and ACK both set.
1725 (i.e. select only the RST and ACK flags in the flags field, and if the result
1726 is "RST and ACK both set", match)
1730 tcp[tcpflags] & (tcp-rst|tcp-ack) == (tcp-rst|tcp-ack)
1734 To select all IPv4 HTTP packets to and from port 80, i.e. print only
1735 packets that contain data, not, for example, SYN and FIN packets and
1736 ACK-only packets. (IPv6 is left as an exercise for the reader.)
1739 \fBtcp port\fP 80 \fBand (((ip[\fP2:2\fB] - ((ip[\fP0\fB]&\fP0xf\fB)<<\fP2\fB)) - ((tcp[\fP12\fB]&\fP0xf0\fB)>>\fP2\fB)) != \fP0\fB)
1743 To select IPv4 packets longer than 576 bytes sent through gateway `snup':
1746 \fBgateway\fP snup \fBand ip[\fP2:2\fB] >\fP 576
1750 To select IPv4 broadcast or multicast packets that were
1752 sent via Ethernet broadcast or multicast:
1755 \fBether[\fP0\fB] &\fP 1 \fB=\fP 0 \fBand ip[\fP16\fB] >=\fP 224
1759 To select all ICMP packets that are not echo requests/replies (i.e., not
1764 icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
1766 icmp6[icmp6type] != icmp6-echo and icmp6[icmp6type] != icmp6-echoreply
1769 .SH BACKWARD COMPATIBILITY
1772 keyword became available in libpcap 1.2.1.
1783 keywords became available in libpcap 1.5.3.
1789 binary operators became available in libpcap 1.6.2.
1793 keyword became available in libpcap 1.8.0.
1795 The ICMPv6 type code names, as well as the
1799 TCP flag names became available in libpcap 1.9.0.
1803 keyword became available in libpcap 1.10.0.
1807 keyword became available in libpcap 1.11.0.
1811 To report a security issue please send an e-mail to \%security@tcpdump.org.
1813 To report bugs and other problems, contribute patches, request a
1814 feature, provide generic feedback etc please see the file
1816 in the libpcap source tree root.
1818 Filter expressions on fields other than those in Token Ring headers will
1819 not correctly handle source-routed Token Ring packets.
1821 Filter expressions on fields other than those in 802.11 headers will not
1822 correctly handle 802.11 data packets with both To DS and From DS set.
1825 should chase header chain, but at this moment it does not.
1826 `\fBip6 protochain\fP'
1827 is supplied for this behavior. For example, to match IPv6 fragments:
1828 `\fBip6 protochain\fP 44'
1830 Arithmetic expression against transport layer headers, like \fBtcp[0]\fP,
1831 does not work against IPv6 packets.
1832 It only looks at IPv4 packets.
1838 keywords do not test whether the packet is an MSU packet. The
1846 keywords do not test whether the packet is an MTP3 packet.
1848 For ARP and RARP the current implementation assumes IPv4 over Ethernet and may
1849 incorrectly match packets that have a different combination of protocol and