1 .\" Copyright (c) 1994, 1996, 1997
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that: (1) source code distributions
6 .\" retain the above copyright notice and this paragraph in its entirety, (2)
7 .\" distributions including binary code include the above copyright notice and
8 .\" this paragraph in its entirety in the documentation or other materials
9 .\" provided with the distribution, and (3) all advertising materials mentioning
10 .\" features or use of this software display the following acknowledgement:
11 .\" ``This product includes software developed by the University of California,
12 .\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13 .\" the University nor the names of its contributors may be used to endorse
14 .\" or promote products derived from this software without specific prior
15 .\" written permission.
16 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 .TH PCAP_FINDALLDEVS 3PCAP "11 March 2025"
22 pcap_findalldevs, pcap_freealldevs \- get a list of capture devices, and
27 #include <pcap/pcap.h>
32 char errbuf[PCAP_ERRBUF_SIZE];
36 int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf);
37 void pcap_freealldevs(pcap_if_t *alldevs);
41 .BR pcap_findalldevs ()
42 constructs a list of packet capture devices that potentially can be opened
44 .BR \%pcap_create (3PCAP)
46 .BR \%pcap_activate (3PCAP)
48 .BR \%pcap_open_live (3PCAP).
53 is a buffer large enough to hold at least
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.
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
75 .BR \%pcap_findalldevs ()
76 may list devices that a subsequent call to
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.
84 .BR pcap_findalldevs ()
85 succeeds, the pointer pointed to by
87 is set to point to the first element of the list, or to
89 if no devices were found (this is considered success).
90 Each element of the list is of type
92 and has the following members:
98 a pointer to the next element in the list;
100 for the last element of the list
103 a pointer to a string giving a name for the device to pass to
106 .BR pcap_open_live ()
111 a pointer to a string giving a human-readable description of the device
114 a pointer to the first element of a list of network addresses for the
118 if the device has no addresses
125 set if the device is a loopback interface
128 set if the device is up
131 set if the device is running
134 set if the device is a wireless interface; this includes IrDA as well as
135 radio-based networks such as IEEE 802.15.4 and IEEE 802.11, so it
136 doesn't just mean Wi-Fi
138 .B PCAP_IF_CONNECTION_STATUS
139 a bitmask for an indication of whether the adapter is connected or not;
140 for wireless interfaces, "connected" means "associated with a network"
142 The possible values for the connection status bits are:
144 .B PCAP_IF_CONNECTION_STATUS_UNKNOWN
145 it's unknown whether the adapter is connected or not
147 .B PCAP_IF_CONNECTION_STATUS_CONNECTED
148 the adapter is connected
150 .B PCAP_IF_CONNECTION_STATUS_DISCONNECTED
151 the adapter is disconnected
153 .B PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE
154 the notion of "connected" and "disconnected" don't apply to this
155 interface; for example, it doesn't apply to a loopback device
159 Each element of the list of addresses is of type
161 and has the following members:
167 a pointer to the next element in the list;
169 for the last element of the list
174 containing an address
181 that contains the netmask corresponding to the address pointed to by
189 that contains the broadcast address corresponding to the address pointed
194 if the device doesn't support broadcasts
201 that contains the destination address corresponding to the address pointed
206 if the device isn't a point-to-point interface
209 Note that the addresses in the list of addresses might be IPv4
210 addresses, IPv6 addresses, or some other type of addresses, so you must
215 before interpreting the contents of the address; do not assume that the
216 addresses are all IPv4 addresses, or even all IPv4 or IPv6 addresses.
217 IPv4 addresses have the value
219 IPv6 addresses have the value
221 (which older operating systems that don't support IPv6 might not
222 define), and other addresses have other values. Whether other addresses
223 are returned, and what types they might have is platform-dependent.
224 Namely, link-layer addresses, such as Ethernet MAC addresses, have the value
228 (on AIX, FreeBSD, Haiku, illumos, macOS, NetBSD and OpenBSD) or are not
229 returned at all (on GNU/Hurd and Solaris).
231 For IPv4 addresses, the
233 pointer can be interpreted as if it pointed to a
234 .BR "struct sockaddr_in" ;
235 for IPv6 addresses, it can be interpreted as if it pointed to a
236 .BR "struct sockaddr_in6".
237 For link-layer addresses, it can be interpreted as if it pointed to a
238 .B "struct sockaddr_ll"
244 .B "struct sockaddr_dl"
248 The list of devices must be freed with
249 .BR pcap_freealldevs (),
250 which frees the list pointed to by
253 .BR pcap_findalldevs ()
258 on failure; as indicated, finding no
259 devices is considered success, rather than failure, so
262 returned in that case. If
266 is filled in with an appropriate error message,
267 and the pointer pointed to by
271 .SH BACKWARD COMPATIBILITY
277 constants became available in libpcap release 1.6.1.
280 .BR PCAP_IF_WIRELESS ,
281 .BR PCAP_IF_CONNECTION_STATUS ,
282 .BR PCAP_IF_CONNECTION_STATUS_UNKNOWN ,
283 .BR PCAP_IF_CONNECTION_STATUS_CONNECTED ,
284 .BR PCAP_IF_CONNECTION_STATUS_DISCONNECTED ,
286 .B PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE
287 constants became available in libpcap release 1.9.0.