Merge branch 'vendor/LIBPCAP'
[dragonfly.git] / contrib / libpcap / pcap_findalldevs.3pcap
1 .\" @(#) $Header: /tcpdump/master/libpcap/pcap_findalldevs.3pcap,v 1.3 2008-04-06 02:53:22 guy Exp $
2 .\"
3 .\" Copyright (c) 1994, 1996, 1997
4 .\"     The Regents of the University of California.  All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that: (1) source code distributions
8 .\" retain the above copyright notice and this paragraph in its entirety, (2)
9 .\" distributions including binary code include the above copyright notice and
10 .\" this paragraph in its entirety in the documentation or other materials
11 .\" provided with the distribution, and (3) all advertising materials mentioning
12 .\" features or use of this software display the following acknowledgement:
13 .\" ``This product includes software developed by the University of California,
14 .\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 .\" the University nor the names of its contributors may be used to endorse
16 .\" or promote products derived from this software without specific prior
17 .\" written permission.
18 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 .\"
22 .TH PCAP_FINDALLDEVS 3PCAP "22 August 2010"
23 .SH NAME
24 pcap_findalldevs, pcap_freealldevs \- get a list of capture devices, and
25 free that list
26 .SH SYNOPSIS
27 .nf
28 .ft B
29 #include <pcap/pcap.h>
30 .ft
31 .LP
32 .nf
33 .ft B
34 char errbuf[PCAP_ERRBUF_SIZE];
35 .ft
36 .LP
37 .ft B
38 int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf);
39 void pcap_freealldevs(pcap_if_t *alldevs);
40 .ft
41 .fi
42 .SH DESCRIPTION
43 .B pcap_findalldevs()
44 constructs a list of network devices that can be opened with
45 .B pcap_create()
46 and
47 .B pcap_activate()
48 or with
49 .BR pcap_open_live() .
50 (Note that there may be network devices that cannot be opened by the
51 process calling
52 .BR pcap_findalldevs() ,
53 because, for example, that process does not have sufficient privileges
54 to open them for capturing; if so, those devices will not appear on the
55 list.)
56 If
57 .B pcap_findalldevs()
58 succeeds, the pointer pointed to by
59 .I alldevsp
60 is set to point to the first element of the list, or to
61 .B NULL
62 if no devices were found (this is considered success).
63 Each element of the list is of type
64 .BR pcap_if_t ,
65 and has the following members:
66 .RS
67 .TP
68 .B next
69 if not
70 .BR NULL ,
71 a pointer to the next element in the list;
72 .B NULL
73 for the last element of the list
74 .TP
75 .B name
76 a pointer to a string giving a name for the device to pass to
77 .B pcap_open_live()
78 .TP
79 .B description
80 if not
81 .BR NULL ,
82 a pointer to a string giving a human-readable description of the device
83 .TP
84 .B addresses
85 a pointer to the first element of a list of network addresses for the
86 device,
87 or
88 .B NULL
89 if the device has no addresses
90 .TP
91 .B flags
92 device flags:
93 .RS
94 .TP
95 .B PCAP_IF_LOOPBACK
96 set if the device is a loopback interface
97 .RE
98 .RE
99 .PP
100 Each element of the list of addresses is of type
101 .BR pcap_addr_t ,
102 and has the following members:
103 .RS
104 .TP
105 .B next
106 if not
107 .BR NULL ,
108 a pointer to the next element in the list;
109 .B NULL
110 for the last element of the list
111 .TP
112 .B addr
113 a pointer to a
114 .B "struct sockaddr"
115 containing an address
116 .TP
117 .B netmask
118 if not
119 .BR NULL ,
120 a pointer to a
121 .B "struct sockaddr"
122 that contains the netmask corresponding to the address pointed to by
123 .B addr
124 .TP
125 .B broadaddr
126 if not
127 .BR NULL ,
128 a pointer to a
129 .B "struct sockaddr"
130 that contains the broadcast address corresponding to the address pointed
131 to by
132 .BR addr ;
133 may be null if the device doesn't support broadcasts
134 .TP
135 .B dstaddr
136 if not
137 .BR NULL ,
138 a pointer to a
139 .B "struct sockaddr"
140 that contains the destination address corresponding to the address pointed
141 to by
142 .BR addr ;
143 may be null if the device isn't a point-to-point interface
144 .RE
145 .PP
146 Note that the addresses in the list of addresses might be IPv4
147 addresses, IPv6 addresses, or some other type of addresses, so you must
148 check the
149 .B sa_family
150 member of the
151 .B "struct sockaddr"
152 before interpreting the contents of the address; do not assume that the
153 addresses are all IPv4 addresses, or even all IPv4 or IPv6 addresses.
154 IPv4 addresses have the value
155 .BR AF_INET ,
156 IPv6 addresses have the value
157 .B AF_INET6
158 (which older operating systems that don't support IPv6 might not
159 define), and other addresses have other values.  Whether other addresses
160 are returned, and what types they might have is platform-dependent.
161 For IPv4 addresses, the
162 .B "struct sockaddr"
163 pointer can be interpreted as if it pointed to a
164 .BR "struct sockaddr_in" ;
165 for IPv6 addresses, it can be interpreted as if it pointed to a
166 .BR "struct sockaddr_in6".
167 .PP
168 The list of devices must be freed with
169 .BR pcap_freealldevs() ,
170 whch frees the list pointed to by
171 .IR alldevs .
172 .SH RETURN VALUE
173 .B pcap_findalldevs()
174 returns 0 on success and \-1 on failure; as indicated, finding no
175 devices is considered success, rather than failure, so 0 will be
176 returned in that case.
177 If \-1 is returned,
178 .I errbuf
179 is filled in with an appropriate error message.
180 .I errbuf
181 is assumed to be able to hold at least
182 .B PCAP_ERRBUF_SIZE
183 chars.
184 .SH SEE ALSO
185 pcap(3PCAP), pcap_create(3PCAP), pcap_activate(3PCAP),
186 pcap_open_live(3PCAP)