1PCAP_FINDALLDEVS(3PCAP)                                PCAP_FINDALLDEVS(3PCAP)
2
3
4

NAME

6       pcap_findalldevs, pcap_freealldevs - get a list of capture devices, and
7       free that list
8

SYNOPSIS

10       #include <pcap/pcap.h>
11
12       char errbuf[PCAP_ERRBUF_SIZE];
13
14       int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf);
15       void pcap_freealldevs(pcap_if_t *alldevs);
16

DESCRIPTION

18       pcap_findalldevs() constructs a list of network  devices  that  can  be
19       opened with pcap_create() and pcap_activate() or with pcap_open_live().
20       (Note that there may be network devices that cannot be  opened  by  the
21       process  calling pcap_findalldevs(), because, for example, that process
22       does not have sufficient privileges to open them for capturing; if  so,
23       those devices will not appear on the list.)  If pcap_findalldevs() suc‐
24       ceeds, the pointer pointed to by alldevsp is set to point to the  first
25       element  of the list, or to NULL if no devices were found (this is con‐
26       sidered success).  Each element of the list is of type  pcap_if_t,  and
27       has the following members:
28
29              next   if  not  NULL, a pointer to the next element in the list;
30                     NULL for the last element of the list
31
32              name   a pointer to a string giving a name  for  the  device  to
33                     pass to pcap_open_live()
34
35              description
36                     if  not  NULL, a pointer to a string giving a human-read‐
37                     able description of the device
38
39              addresses
40                     a pointer to the first  element  of  a  list  of  network
41                     addresses  for  the  device, or NULL if the device has no
42                     addresses
43
44              flags  device flags:
45
46                     PCAP_IF_LOOPBACK
47                            set if the device is a loopback interface
48
49       Each element of the list of addresses is of type pcap_addr_t,  and  has
50       the following members:
51
52              next   if  not  NULL, a pointer to the next element in the list;
53                     NULL for the last element of the list
54
55              addr   a pointer to a struct sockaddr containing an address
56
57              netmask
58                     if not NULL, a pointer to a struct sockaddr that contains
59                     the  netmask  corresponding  to the address pointed to by
60                     addr
61
62              broadaddr
63                     if not NULL, a pointer to a struct sockaddr that contains
64                     the   broadcast  address  corresponding  to  the  address
65                     pointed to by addr; may be null  if  the  device  doesn't
66                     support broadcasts
67
68              dstaddr
69                     if not NULL, a pointer to a struct sockaddr that contains
70                     the destination  address  corresponding  to  the  address
71                     pointed  to  by  addr;  may be null if the device isn't a
72                     point-to-point interface
73
74       Note that the  addresses  in  the  list  of  addresses  might  be  IPv4
75       addresses, IPv6 addresses, or some other type of addresses, so you must
76       check the sa_family member of the struct sockaddr  before  interpreting
77       the  contents  of the address; do not assume that the addresses are all
78       IPv4 addresses, or even all IPv4 or  IPv6  addresses.   IPv4  addresses
79       have  the  value AF_INET, IPv6 addresses have the value AF_INET6 (which
80       older operating systems that don't support IPv6 might not define),  and
81       other  addresses  have  other  values.   Whether  other  addresses  are
82       returned, and what types they might have  is  platform-dependent.   For
83       IPv4 addresses, the struct sockaddr pointer can be interpreted as if it
84       pointed to a struct sockaddr_in; for IPv6 addresses, it can  be  inter‐
85       preted as if it pointed to a struct sockaddr_in6.
86
87       The  list  of devices must be freed with pcap_freealldevs(), whch frees
88       the list pointed to by alldevs.
89

RETURN VALUE

91       pcap_findalldevs() returns 0 on success and -1  on  failure;  as  indi‐
92       cated,  finding  no devices is considered success, rather than failure,
93       so 0 will be returned in that case.   If  -1  is  returned,  errbuf  is
94       filled  in  with an appropriate error message.  errbuf is assumed to be
95       able to hold at least PCAP_ERRBUF_SIZE chars.
96

SEE ALSO

98       pcap(3PCAP),         pcap_create(3PCAP),          pcap_activate(3PCAP),
99       pcap_open_live(3PCAP)
100
101
102
103                                22 August 2010         PCAP_FINDALLDEVS(3PCAP)
Impressum