Skip to content

Commit a479709

Browse files
committed
man: Document devices, interfaces and "any" better.
In pcap_create(3PCAP) and pcap_open_live(3PCAP) spell device/interface and replace an explanation of the difference with a reference to pcap_findalldevs(3PCAP). In the latter man page remove the text that used to say "does not have sufficient privileges... those devices will not appear" since libpcap 1.1.1 because it does not seem to match even what old libpcap versions implemented (e.g. skip only if IFF_UP is not set in fad-gifc.c). Add a paragraph to explain the difference between listing devices and activating a device in the current implementation. Explain that a capture device is a generic case of a network interface and how the "any" pseudo-interface relates with network interfaces. Show that a device name can be used with pcap_create() too. This resolves GitHub bug report #1055.
1 parent 2afd5f2 commit a479709

File tree

4 files changed

+51
-35
lines changed

4 files changed

+51
-35
lines changed

CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
6868
pcap_lib_version(3PCAP): Add details and examples.
6969
Discuss Linux BPF extensions in the man pages.
7070
Note endianness in pcap_compile(3PCAP) and pcap_lookupnet(3PCAP).
71+
man: Document devices, interfaces and "any" better.
7172
Building and testing:
7273
Apply GNU Hurd support patch from the Debian package.
7374
CI: Introduce and use LIBPCAP_CMAKE_TAINTED.

pcap_create.3pcap

+7-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1818
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1919
.\"
20-
.TH PCAP_CREATE 3PCAP "6 September 2024"
20+
.TH PCAP_CREATE 3PCAP "11 March 2025"
2121
.SH NAME
2222
pcap_create \- create a live capture handle
2323
.SH SYNOPSIS
@@ -37,18 +37,14 @@ pcap_t *pcap_create(const char *source, char *errbuf);
3737
.fi
3838
.SH DESCRIPTION
3939
.BR pcap_create ()
40-
is used to create a packet capture handle to look
41-
at packets on the network.
40+
is used to create a packet capture handle to capture packets on a device
41+
(typically a network interface, see
42+
.BR \%pcap_findalldevs (3PCAP)
43+
for a more detailed explanation).
4244
.I source
43-
is a string that specifies the network device to open; on all supported Linux
44-
systems, as well as on recent versions of macOS and Solaris, a
45-
.I source
46-
argument of "any" or
45+
is a string that specifies the capture device to open, in this function
4746
.B NULL
48-
can be used to capture packets from all network interfaces. The latter should
49-
not be confused with all available capture devices as seen by
50-
.BR pcap_findalldevs (3PCAP),
51-
which may also include D-Bus, USB etc.
47+
means the same as the string "any".
5248
.I errbuf
5349
is a buffer large enough to hold at least
5450
.B PCAP_ERRBUF_SIZE

pcap_findalldevs.3pcap

+35-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1818
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1919
.\"
20-
.TH PCAP_FINDALLDEVS 3PCAP "9 August 2024"
20+
.TH PCAP_FINDALLDEVS 3PCAP "11 March 2025"
2121
.SH NAME
2222
pcap_findalldevs, pcap_freealldevs \- get a list of capture devices, and
2323
free that list
@@ -39,26 +39,47 @@ void pcap_freealldevs(pcap_if_t *alldevs);
3939
.fi
4040
.SH DESCRIPTION
4141
.BR pcap_findalldevs ()
42-
constructs a list of network devices that can be opened with
43-
.BR pcap_create (3PCAP)
42+
constructs a list of packet capture devices that potentially can be opened
43+
with
44+
.BR \%pcap_create (3PCAP)
4445
and
45-
.BR pcap_activate (3PCAP)
46+
.BR \%pcap_activate (3PCAP)
4647
or with
47-
.BR pcap_open_live (3PCAP).
48-
(Note that there may be network devices that cannot be opened by the
49-
process calling
50-
.BR pcap_findalldevs (),
51-
because, for example, that process does not have sufficient privileges
52-
to open them for capturing; if so, those devices will not appear on the
53-
list.)
48+
.BR \%pcap_open_live (3PCAP).
5449
.I alldevsp
5550
is a pointer to a
5651
.BR "pcap_if_t *" ;
5752
.I errbuf
5853
is a buffer large enough to hold at least
59-
.B PCAP_ERRBUF_SIZE
54+
.B \%PCAP_ERRBUF_SIZE
6055
chars.
6156
.PP
57+
The most common type of a capture device is a regular network interface, in
58+
which case the capture device name is the same as the OS network interface
59+
name, for example, "eth0". All supported Linux systems, as well as recent
60+
versions of macOS and Solaris, implement a special "any" pseudo-interface,
61+
which captures packets from all regular network interfaces and does not
62+
support promiscuous mode. If the "any" pseudo-interface is available, the
63+
list of capture devices includes it. What is considered a regular network
64+
interface is an implementation detail of the OS (for example, on Linux this
65+
includes SocketCAN devices), so packets captured on the "any" pseudo-interface
66+
may represent more different network protocols than expected. The list of
67+
capture devices, depending on how libpcap was compiled and how the host is
68+
configured, often also includes at least some of the following types:
69+
Bluetooth, DAG, D-Bus, Netlink, SNF and USB.
70+
.PP
71+
For most capture device types enumeration of devices does not require special
72+
privileges or a specific device state (i.e. being "up" or ready in any other
73+
sense). However, capturing of packets on a device usually depends on some
74+
conditions, so
75+
.BR \%pcap_findalldevs ()
76+
may list devices that a subsequent call to
77+
.BR pcap_activate ()
78+
would reject -- then, for example, the error code
79+
.B \%PCAP_ERROR_PERM_DENIED
80+
would make the same sense as not being able to read from a particular file in
81+
a directory that allows to list the files. This is the intended design.
82+
.PP
6283
If
6384
.BR pcap_findalldevs ()
6485
succeeds, the pointer pointed to by
@@ -80,6 +101,8 @@ for the last element of the list
80101
.TP
81102
.B name
82103
a pointer to a string giving a name for the device to pass to
104+
.BR pcap_create ()
105+
or
83106
.BR pcap_open_live ()
84107
.TP
85108
.B description

pcap_open_live.3pcap

+8-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1818
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1919
.\"
20-
.TH PCAP_OPEN_LIVE 3PCAP "4 March 2024"
20+
.TH PCAP_OPEN_LIVE 3PCAP "11 March 2025"
2121
.SH NAME
2222
pcap_open_live \- open a device for capturing
2323
.SH SYNOPSIS
@@ -38,18 +38,14 @@ pcap_t *pcap_open_live(const char *device, int snaplen,
3838
.fi
3939
.SH DESCRIPTION
4040
.BR pcap_open_live ()
41-
is used to obtain a packet capture handle to look
42-
at packets on the network.
41+
is used to obtain a packet capture handle to capture packets on a device
42+
(typically a network interface, see
43+
.BR \%pcap_findalldevs (3PCAP)
44+
for a more detailed explanation).
4345
.I device
44-
is a string that specifies the network device to open; on all supported Linux
45-
systems, as well as on recent versions of macOS and Solaris, a
46-
.I device
47-
argument of "any" or
46+
is a string that specifies the capture device to open, in this function
4847
.B NULL
49-
can be used to capture packets from all network interfaces. The latter should
50-
not be confused with all available capture devices as seen by
51-
.BR pcap_findalldevs (3PCAP),
52-
which may also include D-Bus, USB etc.
48+
means the same as the string "any".
5349
.PP
5450
.I snaplen
5551
specifies the snapshot length to be set on the handle. If the packet
@@ -58,7 +54,7 @@ sufficient for most devices, but D-Bus devices require a value of 128MiB
5854
(128*1024*1024).
5955
.PP
6056
.I promisc
61-
specifies whether the interface is to be put into promiscuous mode.
57+
specifies whether the device is to be put into promiscuous mode.
6258
If
6359
.I promisc
6460
is non-zero, promiscuous mode will be set, otherwise it will not be set.

0 commit comments

Comments
 (0)