Synopsis

Description

From a datalink or IP interface, snoop captures packets and displays their
contents. If the datalink or IP interface is not specified, snoop will
pick a datalink to use, giving priority to datalinks that have been
plumbed for IP traffic. snoop uses the pfmod(7M) and bufmod(7M) STREAMS modules to provide
efficient capture of packets from the network. Captured packets can be displayed
as they are received or saved to a file (which is RFC 1761-compliant)
for later inspection.

snoop can display packets in a single-line summary form or in verbose
multi-line forms. In summary form, with the exception of certain VLAN packets,
only the data pertaining to the highest level protocol is displayed. If
a packet has a VLAN header and its VLAN ID is non-zero,
then snoop will show that the packet is VLAN tagged. For example,
an NFS packet will have only NFS information displayed. Except for VLAN
information under the condition just described, the underlying RPC, UDP, IP, and
Ethernet frame information is suppressed, but can be displayed if either of
the verbose options are chosen.

In the absence of a name service, such as LDAP or NIS,
snoop displays host names as numeric IP addresses.

snoop requires an interactive interface.

Note - The snoop command is Obsolete. It is recommended that you use Wireshark
or its non-GUI version, Tshark instead. These programs are available in the
following packages:

pkg://solaris/diagnostic/wireshark

pkg://solaris/diagnostic/wireshark/tshark

These packages are available in the Solaris package repository.

Options

-C

List the code generated from the filter expression for either the kernel packet filter, or snoop's own filter.

-D

Display number of packets dropped during capture on the summary line.

-N

Create an IP address-to-name file from a capture file. This must be set together with the -ifilename option that names a capture file. The address-to-name file has the same name as the capture file with .names appended. This file records the IP address to hostname mapping at the capture site and increases the portability of the capture file. Generate a .names file if the capture file is to be analyzed elsewhere. Packets are not displayed when this flag is used.

-IIP_interface

Capture IP packets from the network using the IP interface specified by IP_interface, for example, lo0. The ipadm(1M) command can be used to list available IP interfaces. The -I and -d options are mutually exclusive.

-P

Capture packets in non-promiscuous mode. Only broadcast, multicast, or packets addressed to the host machine will be seen.

-S

Display size of the entire link layer frame in bytes on the summary line.

-V

Verbose summary mode. This is halfway between summary mode and verbose mode in degree of verbosity. Instead of displaying just the summary line for the highest level protocol in a packet, it displays a summary line for each protocol layer in the packet. For instance, for an NFS packet it will display a line each for the ETHER, IP, UDP, RPC and NFS layers. Verbose summary mode output may be easily piped through grep to extract packets of interest. For example, to view only RPC summary lines, enter the following: example#snoop -i rpc.cap -V | grep RPC

-a

Listen to packets on /dev/audio (warning: can be noisy).

-cmaxcount

Quit after capturing maxcount packets. Otherwise keep capturing until there is no disk space left or until interrupted with Control-C.

-ddatalink

Capture link-layer packets from the network using the DLPI datalink specified by datalink, for example, bge0 or net0. The dladm(1M)show-link subcommand can be used to list available datalinks. The -d and -I options are mutually exclusive.

-ifilename

Display packets previously captured in filename. Without this option, snoop reads packets from the first network interface. If a filename.names file is present, it is automatically loaded into the snoop IP address-to-name mapping table (See -N flag).

-nfilename

Use filename as an IP address-to-name mapping table. This file must have the same format as the /etc/hosts file (IP address followed by the hostname).

-ofilename

Save captured packets in filename as they are captured. (This filename is referred to as the “capture file”.) The format of the capture file is RFC 1761–compliant. During packet capture, a count of the number of packets saved in the file is displayed. If you wish just to count packets without saving to a file, name the file /dev/null.

-pfirst [ , last ]

Select one or more packets to be displayed from a capture file. The first packet in the file is packet number 1.

-q

When capturing network packets into a file, do not display the packet count. This can improve packet capturing performance.

-r

Do not resolve the IP address to the symbolic name. This prevents snoop from generating network traffic while capturing and displaying packets. However, if the -n option is used, and an address is found in the mapping file, its corresponding name will be used.

-ssnaplen

Truncate each packet after snaplen bytes. Usually the whole packet is captured. This option is useful if only certain packet header information is required. The packet truncation is done within the kernel giving better utilization of the streams packet buffer. This means less chance of dropped packets due to buffer overflow during periods of high traffic. It also saves disk space when capturing large traces to a capture file. To capture only IP headers (no options) use a snaplen of 34. For UDP use 42, and for TCP use 54. You can capture RPC headers with a snaplen of 80 bytes. NFS headers can be captured in 120 bytes.

-t [ r | a | d ]

Time-stamp presentation. Time-stamps are accurate to within 4 microseconds. The default is for times to be presented in d (delta) format (the time since receiving the previous packet). Option a (absolute) gives wall-clock time. Option r (relative) gives time relative to the first packet displayed. This can be used with the -p option to display time relative to any selected packet.

-v

Verbose mode. Print packet headers in lots of detail. This display consumes many lines per packet and should be used only on selected packets.

-xoffset [ , length]

Display packet data in hexadecimal and ASCII format. The offset and length values select a portion of the packet to be displayed. To display the whole packet, use an offset of 0. If a length value is not provided, the rest of the packet is displayed.

Operands

expression

Select packets either from the network or from a capture file. Only packets for which the expression is true will be selected. If no expression is provided it is assumed to be true.

Given a filter expression, snoop generates code for either the kernel packet filter or for its own internal filter. If capturing packets with the network interface, code for the kernel packet filter is generated. This filter is implemented as a streams module, upstream of the buffer module. The buffer module accumulates packets until it becomes full and passes the packets on to snoop. The kernel packet filter is very efficient, since it rejects unwanted packets in the kernel before they reach the packet buffer or snoop. The kernel packet filter has some limitations in its implementation; it is possible to construct filter expressions that it cannot handle. In this event, snoop tries to split the filter and do as much filtering in the kernel as possible. The remaining filtering is done by the packet filter for snoop. The -C flag can be used to view generated code for either the packet filter for the kernel or the packet filter for snoop. If packets are read from a capture file using the -ifilename option, only the packet filter for snoop is used.

A filter expression consists of a series of one or more boolean primitives that may be combined with boolean operators (AND, OR, and NOT). Normal precedence rules for boolean operators apply. Order of evaluation of these operators may be controlled with parentheses. Since parentheses and other filter expression characters are known to the shell, it is often necessary to enclose the filter expression in quotes. Refer to Example 2 for information about setting up more efficient filters.

The primitives are:

hosthostname

True if the source or destination address is that of hostname. The hostname argument may be a literal address. The keyword host may be omitted if the name does not conflict with the name of another expression primitive. For example, pinky selects packets transmitted to or received from the host pinky, whereas pinky and dinky selects packets exchanged between hosts pinky AND dinky.

The type of address used depends on the primitive which precedes the host primitive. The possible qualifiers are inet, inet6, ether, or none. These three primitives are discussed below. Having none of the primitives present is equivalent to “inet host hostname or inet6 host hostname”. In other words, snoop tries to filter on all IP addresses associated with hostname.

inet or inet6

A qualifier that modifies the host primitive that follows. If it is inet, then snoop tries to filter on all IPv4 addresses returned from a name lookup. If it is inet6, snoop tries to filter on all IPv6 addresses returned from a name lookup.

“2::9255:a00:20ff:fe73:6e35” matches all packets with that IPv6 address as source or destination;

“65281.13” matches all packets with that AppleTalk address;

“8:0:20:f:b1:51” matches all packets with the Ethernet address as source or destination.

An Ethernet address beginning with a letter is interpreted as a hostname. To avoid this, prepend a zero when specifying the address. For example, if the Ethernet address is aa:0:45:23:52:44, then specify it by add a leading zero to make it 0aa:0:45:23:52:44.

from or src

A qualifier that modifies the following host, net, ipaddr, atalkaddr, etheraddr, port or rpc primitive to match just the source address, port, or RPC reply.

to or dst

A qualifier that modifies the following host, net, ipaddr, atalkaddr, etheraddr, port or rpc primitive to match just the destination address, port, or RPC call.

ether

A qualifier that modifies the following host primitive to resolve a name to an Ethernet address. Normally, IP address matching is performed. This option is not supported on media such as IPoIB (IP over InfiniBand).

ethertypenumber

True if the Ethernet type field has value number. If number is not 0x8100 (VLAN) and the packet is VLAN tagged, then the expression will match the encapsulated Ethernet type.

ip, ip6, arp, rarp, pppoed, pppoes

True if the packet is of the appropriate ethertype.

vlan

True if the packet has ethertype VLAN and the VLAN ID is not zero.

vlan-idid

True for packets of ethertype VLAN with the id id.

pppoe

True if the ethertype of the packet is either pppoed or pppoes.

broadcast

True if the packet is a broadcast packet. Equivalent to ether[2:4] = 0xffffffff for Ethernet. This option is not supported on media such as IPoIB (IP over InfiniBand).

multicast

True if the packet is a multicast packet. Equivalent to “ether[0] & 1 = 1” on Ethernet. This option is not supported on media such as IPoIB (IP over InfiniBand).

bootp, dhcp

True if the packet is an unfragmented IPv4 UDP packet with either a source port of BOOTPS (67) and a destination port of BOOTPC (68), or a source port of BOOTPC (68) and a destination of BOOTPS (67).

dhcp6

True if the packet is an unfragmented IPv6 UDP packet with either a source port of DHCPV6-SERVER (547) and a destination port of DHCPV6-CLIENT (546), or a source port of DHCPV6-CLIENT (546) and a destination of DHCPV6-SERVER (547).

apple

True if the packet is an Apple Ethertalk packet. Equivalent to “ethertype 0x809b or ethertype 0x80f3”.

decnet

True if the packet is a DECNET packet.

greaterlength

True if the packet is longer than length.

lesslength

True if the packet is shorter than length.

udp, tcp, icmp, icmp6, ah, esp

True if the IP or IPv6 protocol is of the appropriate type.

netnet

True if either the IP source or destination address has a network number of net. The from or to qualifier may be used to select packets for which the network number occurs only in the source or destination address.

portport

True if either the source or destination port is port. The port may be either a port number or name from /etc/services. The tcp or udp primitives may be used to select TCP or UDP ports only. The from or to qualifier may be used to select packets for which the port occurs only as the source or destination.

rpcprog [ , vers [ , proc ] ]

True if the packet is an RPC call or reply packet for the protocol identified by prog. The prog may be either the name of an RPC protocol from /etc/rpc or a program number. The vers and proc may be used to further qualify the program version and procedure number, for example, rpc nfs,2,0 selects all calls and replies for the NFS null procedure. The to or from qualifier may be used to select either call or reply packets only.

zonezoneid

True if zoneid matches either the source or destination zoneid of a packet received on an ipnet device.

ldap

True if the packet is an LDAP packet on port 389.

gatewayhost

True if the packet used host as a gateway, that is, the Ethernet source or destination address was for host but not the IP address. Equivalent to “ether hosthost and not host host”.

nofrag

True if the packet is unfragmented or is the first in a series of IP fragments. Equivalent to ip[6:2] & 0x1fff = 0.

exprrelopexpr

True if the relation holds, where relop is one of >, <, >=, <=, =, !=, and expr is an arithmetic expression composed of numbers, packet field selectors, the length primitive, and arithmetic operators +, -, *, &, |, ^, and %. The arithmetic operators within expr are evaluated before the relational operator and normal precedence rules apply between the arithmetic operators, such as multiplication before addition. Parentheses may be used to control the order of evaluation. To use the value of a field in the packet use the following syntax:

base[expr [:size ] ]

where expr evaluates the value of an offset into the packet from a base offset which may be ether, ip, ip6, udp, tcp, or icmp. The size value specifies the size of the field. If not given, 1 is assumed. Other legal values are 2 and 4. For example,

ether[0] & 1 = 1

is equivalent to multicast

ether[2:4] = 0xffffffff

is equivalent to broadcast.

ip[ip[0] & 0xf * 4 : 2] = 2049

is equivalent to udp[0:2] = 2049

ip[0] & 0xf > 5

selects IP packets with options.

ip[6:2] & 0x1fff = 0

eliminates IP fragments.

udp and ip[6:2]&0x1fff = 0 and udp[6:2] != 0

finds all packets with UDP checksums.

The length primitive may be used to obtain the length of the packet. For instance “length > 60” is equivalent to “greater 60”, and “ether[length - 1]” obtains the value of the last byte in a packet.

and

Perform a logical AND operation between two boolean values. The AND operation is implied by the juxtaposition of two boolean expressions, for example “dinky pinky” is the same as “dinky AND pinky”.

or or ,

Perform a logical OR operation between two boolean values. A comma may be used instead, for example, “dinky,pinky” is the same as “dinky OR pinky”.

not or !

Perform a logical NOT operation on the following boolean value. This operator is evaluated before AND or OR.

slp

True if the packet is an SLP packet.

sctp

True if the packet is an SCTP packet.

ospf

True if the packet is an OSPF packet.

Examples

Example 1 Using the snoop Command

Capture all packets and display them as they are received:

example# snoop

Capture packets with host funky as either the source or destination and
display them as they are received:

example# snoop funky

Capture packets between funky and pinky and save them to a file.
Then inspect the packets using times (in seconds) relative to the first
captured packet:

To set up a more efficient filter, the following filters should be
used toward the end of the expression, so that the first part
of the expression can be set up in the kernel: greater, less,
port, rpc, nofrag, and relop. The presence of OR makes it difficult to
split the filtering when using these primitives that cannot be set in
the kernel. Instead, use parentheses to enforce the primitives that should be
OR'd.

To capture packets between funky and pinky of type tcp or udp
on port 80:

example# snoop funky and pinky and port 80 and tcp or udp

Since the primitive port cannot be handled by the kernel filter, and
there is also an OR in the expression, a more efficient way
to filter is to move the OR to the end of the
expression and to use parentheses to enforce the OR between tcp and
udp:

Warnings

The processing overhead is much higher for real-time packet interpretation. Consequently, the
packet drop count may be higher. For more reliable capture, output raw
packets to a file using the -o option and analyze the packets
offline.

Unfiltered packet capture imposes a heavy processing load on the host computer,
particularly if the captured packets are interpreted real-time. This processing load further
increases if verbose options are used. Since heavy use of snoop may
deny computing resources to other processes, it should not be used on production
servers. Heavy use of snoop should be restricted to a dedicated computer.

snoop does not reassemble IP fragments. Interpretation of higher level protocol halts
at the end of the first IP fragment.

snoop may generate extra packets as a side-effect of its use. For
example it may use a network name service (NIS) to convert IP
addresses to host names for display. Capturing into a file for later
display can be used to postpone the address-to-name mapping until after the capture
session is complete. Capturing into an NFS-mounted file may also generate extra
packets.

Setting the snaplen (-s option) to small values may remove header information
that is needed to interpret higher level protocols. The exact cutoff value
depends on the network and protocols being used. For NFS Version 2
traffic using UDP on 10 Mb/s Ethernet, do not set snaplen less
than 150 bytes. For NFS Version 3 traffic using TCP on 100
Mb/s Ethernet, snaplen should be 250 bytes or more.

snoop requires information from an RPC request to fully interpret an RPC
reply. If an RPC reply in a capture file or packet range
does not have a request preceding it, then only the RPC reply
header will be displayed.