1 /*
2 * Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 #ifndef NETWORK_INTERFACE_H
27 #define NETWORK_INTERFACE_H
28
29 #include <iphlpapi.h>
30 #include "net_util.h"
31
32 /*
33 * Structures used when enumerating interfaces and addresses
34 */
35 typedef struct _netaddr {
36 SOCKETADDRESS addr; /* IPv4 or IPv6 address */
37 SOCKETADDRESS brdcast;
38 short mask;
39 struct _netaddr *next;
40 } netaddr;
41
42 typedef struct _netif {
43 char *name;
44 char *displayName;
45 DWORD dwIndex; /* Internal index */
46 DWORD ifType; /* Interface type */
47 int index; /* Friendly index */
48 struct _netif *next;
49
50 /* Following fields used on Windows XP when IPv6 is used only */
51 jboolean hasIpv6Address; /* true when following fields valid */
52 jboolean dNameIsUnicode; /* Display Name is Unicode */
53 int naddrs; /* Number of addrs */
54 DWORD ipv6Index;
55 struct _netaddr *addrs; /* addr list for interfaces */
56 } netif;
57
58 extern void free_netif(netif *netifP);
59 extern void free_netaddr(netaddr *netaddrP);
60
61 /* various JNI ids */
62 extern jclass ni_class; /* NetworkInterface */
63
64 extern jmethodID ni_ctrID; /* NetworkInterface() */
65
66 extern jfieldID ni_indexID; /* NetworkInterface.index */
67 extern jfieldID ni_addrsID; /* NetworkInterface.addrs */
68 extern jfieldID ni_bindsID; /* NetworkInterface.bindings */
69 extern jfieldID ni_nameID; /* NetworkInterface.name */
70 extern jfieldID ni_displayNameID; /* NetworkInterface.displayName */
71 extern jfieldID ni_childsID; /* NetworkInterface.childs */
72
73 extern jclass ni_ibcls; /* InterfaceAddress */
74 extern jmethodID ni_ibctrID; /* InterfaceAddress() */
75 extern jfieldID ni_ibaddressID; /* InterfaceAddress.address */
76 extern jfieldID ni_ibbroadcastID; /* InterfaceAddress.broadcast */
77 extern jfieldID ni_ibmaskID; /* InterfaceAddress.maskLength */
78
79 int enumInterfaces_win(JNIEnv *env, netif **netifPP);
80
81 /* We have included iphlpapi.h which includes iptypes.h which has the definition
82 * for MAX_ADAPTER_DESCRIPTION_LENGTH (along with the other definitions in this
83 * ifndef block). Therefore if MAX_ADAPTER_DESCRIPTION_LENGTH is defined we can
84 * be sure that the other definitions are also defined */
85 #ifndef MAX_ADAPTER_DESCRIPTION_LENGTH
86
87 /*
88 * Following includes come from iptypes.h
89 */
90
91 #pragma warning(push)
92 #pragma warning(disable:4201)
93
94 #include <time.h>
95
96 // Definitions and structures used by getnetworkparams and getadaptersinfo apis
97
98 #define MAX_ADAPTER_DESCRIPTION_LENGTH 128 // arb.
99 #define MAX_ADAPTER_NAME_LENGTH 256 // arb.
100 #define MAX_ADAPTER_ADDRESS_LENGTH 8 // arb.
101 #define DEFAULT_MINIMUM_ENTITIES 32 // arb.
102 #define MAX_HOSTNAME_LEN 128 // arb.
103 #define MAX_DOMAIN_NAME_LEN 128 // arb.
104 #define MAX_SCOPE_ID_LEN 256 // arb.
105
106 //
107 // types
108 //
109
110 // Node Type
111
112 #define BROADCAST_NODETYPE 1
113 #define PEER_TO_PEER_NODETYPE 2
114 #define MIXED_NODETYPE 4
115 #define HYBRID_NODETYPE 8
116
117 //
118 // IP_ADDRESS_STRING - store an IP address as a dotted decimal string
119 //
120
121 typedef struct {
122 char String[4 * 4];
123 } IP_ADDRESS_STRING, *PIP_ADDRESS_STRING, IP_MASK_STRING, *PIP_MASK_STRING;
124
125 //
126 // IP_ADDR_STRING - store an IP address with its corresponding subnet mask,
127 // both as dotted decimal strings
128 //
129
130 typedef struct _IP_ADDR_STRING {
131 struct _IP_ADDR_STRING* Next;
132 IP_ADDRESS_STRING IpAddress;
133 IP_MASK_STRING IpMask;
134 DWORD Context;
135 } IP_ADDR_STRING, *PIP_ADDR_STRING;
136
137 //
138 // ADAPTER_INFO - per-adapter information. All IP addresses are stored as
139 // strings
140 //
141
142 typedef struct _IP_ADAPTER_INFO {
143 struct _IP_ADAPTER_INFO* Next;
144 DWORD ComboIndex;
145 char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
146 char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
147 UINT AddressLength;
148 BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
149 DWORD Index;
150 UINT Type;
151 UINT DhcpEnabled;
152 PIP_ADDR_STRING CurrentIpAddress;
153 IP_ADDR_STRING IpAddressList;
154 IP_ADDR_STRING GatewayList;
155 IP_ADDR_STRING DhcpServer;
156 BOOL HaveWins;
157 IP_ADDR_STRING PrimaryWinsServer;
158 IP_ADDR_STRING SecondaryWinsServer;
159 time_t LeaseObtained;
160 time_t LeaseExpires;
161 } IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;
162
163 #ifdef _WINSOCK2API_
164
165 //
166 // The following types require Winsock2.
167 //
168
169 typedef enum {
170 IpPrefixOriginOther = 0,
171 IpPrefixOriginManual,
172 IpPrefixOriginWellKnown,
173 IpPrefixOriginDhcp,
174 IpPrefixOriginRouterAdvertisement,
175 } IP_PREFIX_ORIGIN;
176
177 typedef enum {
178 IpSuffixOriginOther = 0,
179 IpSuffixOriginManual,
180 IpSuffixOriginWellKnown,
181 IpSuffixOriginDhcp,
182 IpSuffixOriginLinkLayerAddress,
183 IpSuffixOriginRandom,
184 } IP_SUFFIX_ORIGIN;
185
186 typedef enum {
187 IpDadStateInvalid = 0,
188 IpDadStateTentative,
189 IpDadStateDuplicate,
190 IpDadStateDeprecated,
191 IpDadStatePreferred,
192 } IP_DAD_STATE;
193
194 typedef struct _IP_ADAPTER_UNICAST_ADDRESS {
195 union {
196 ULONGLONG Alignment;
197 struct {
198 ULONG Length;
199 DWORD Flags;
200 };
201 };
202 struct _IP_ADAPTER_UNICAST_ADDRESS *Next;
203 SOCKET_ADDRESS Address;
204
205 IP_PREFIX_ORIGIN PrefixOrigin;
206 IP_SUFFIX_ORIGIN SuffixOrigin;
207 IP_DAD_STATE DadState;
208
209 ULONG ValidLifetime;
210 ULONG PreferredLifetime;
211 ULONG LeaseLifetime;
212 } IP_ADAPTER_UNICAST_ADDRESS, *PIP_ADAPTER_UNICAST_ADDRESS;
213
214 typedef struct _IP_ADAPTER_ANYCAST_ADDRESS {
215 union {
216 ULONGLONG Alignment;
217 struct {
218 ULONG Length;
219 DWORD Flags;
220 };
221 };
222 struct _IP_ADAPTER_ANYCAST_ADDRESS *Next;
223 SOCKET_ADDRESS Address;
224 } IP_ADAPTER_ANYCAST_ADDRESS, *PIP_ADAPTER_ANYCAST_ADDRESS;
225
226 typedef struct _IP_ADAPTER_MULTICAST_ADDRESS {
227 union {
228 ULONGLONG Alignment;
229 struct {
230 ULONG Length;
231 DWORD Flags;
232 };
233 };
234 struct _IP_ADAPTER_MULTICAST_ADDRESS *Next;
235 SOCKET_ADDRESS Address;
236 } IP_ADAPTER_MULTICAST_ADDRESS, *PIP_ADAPTER_MULTICAST_ADDRESS;
237
238 //
239 // Per-address Flags
240 //
241 #define IP_ADAPTER_ADDRESS_DNS_ELIGIBLE 0x01
242 #define IP_ADAPTER_ADDRESS_TRANSIENT 0x02
243
244 typedef struct _IP_ADAPTER_DNS_SERVER_ADDRESS {
245 union {
246 ULONGLONG Alignment;
247 struct {
248 ULONG Length;
249 DWORD Reserved;
250 };
251 };
252 struct _IP_ADAPTER_DNS_SERVER_ADDRESS *Next;
253 SOCKET_ADDRESS Address;
254 } IP_ADAPTER_DNS_SERVER_ADDRESS, *PIP_ADAPTER_DNS_SERVER_ADDRESS;
255
256 typedef struct _IP_ADAPTER_PREFIX {
257 union {
258 ULONGLONG Alignment;
259 struct {
260 ULONG Length;
261 DWORD Flags;
262 };
263 };
264 struct _IP_ADAPTER_PREFIX *Next;
265 SOCKET_ADDRESS Address;
266 ULONG PrefixLength;
267 } IP_ADAPTER_PREFIX, *PIP_ADAPTER_PREFIX;
268
269 //
270 // Per-adapter Flags
271 //
272 #define IP_ADAPTER_DDNS_ENABLED 0x01
273 #define IP_ADAPTER_REGISTER_ADAPTER_SUFFIX 0x02
274 #define IP_ADAPTER_DHCP_ENABLED 0x04
275 #define IP_ADAPTER_RECEIVE_ONLY 0x08
276 #define IP_ADAPTER_NO_MULTICAST 0x10
277 #define IP_ADAPTER_IPV6_OTHER_STATEFUL_CONFIG 0x20
278
279 //
280 // OperStatus values from RFC 2863
281 //
282 typedef enum {
283 IfOperStatusUp = 1,
284 IfOperStatusDown,
285 IfOperStatusTesting,
286 IfOperStatusUnknown,
287 IfOperStatusDormant,
288 IfOperStatusNotPresent,
289 IfOperStatusLowerLayerDown
290 } IF_OPER_STATUS;
291
292 //
293 // Scope levels from RFC 2373 used with ZoneIndices array.
294 //
295 typedef enum {
296 ScopeLevelInterface = 1,
297 ScopeLevelLink = 2,
298 ScopeLevelSubnet = 3,
299 ScopeLevelAdmin = 4,
300 ScopeLevelSite = 5,
301 ScopeLevelOrganization = 8,
302 ScopeLevelGlobal = 14
303 } SCOPE_LEVEL;
304
305 typedef struct _IP_ADAPTER_ADDRESSES {
306 union {
307 ULONGLONG Alignment;
308 struct {
309 ULONG Length;
310 DWORD IfIndex;
311 };
312 };
313 struct _IP_ADAPTER_ADDRESSES *Next;
314 PCHAR AdapterName;
315 PIP_ADAPTER_UNICAST_ADDRESS FirstUnicastAddress;
316 PIP_ADAPTER_ANYCAST_ADDRESS FirstAnycastAddress;
317 PIP_ADAPTER_MULTICAST_ADDRESS FirstMulticastAddress;
318 PIP_ADAPTER_DNS_SERVER_ADDRESS FirstDnsServerAddress;
319 PWCHAR DnsSuffix;
320 PWCHAR Description;
321 PWCHAR FriendlyName;
322 BYTE PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH];
323 DWORD PhysicalAddressLength;
324 DWORD Flags;
325 DWORD Mtu;
326 DWORD IfType;
327 IF_OPER_STATUS OperStatus;
328 DWORD Ipv6IfIndex;
329 DWORD ZoneIndices[16];
330 PIP_ADAPTER_PREFIX FirstPrefix;
331 } IP_ADAPTER_ADDRESSES, *PIP_ADAPTER_ADDRESSES;
332
333 //
334 // Flags used as argument to GetAdaptersAddresses().
335 // "SKIP" flags are added when the default is to include the information.
336 // "INCLUDE" flags are added when the default is to skip the information.
337 //
338 #define GAA_FLAG_SKIP_UNICAST 0x0001
339 #define GAA_FLAG_SKIP_ANYCAST 0x0002
340 #define GAA_FLAG_SKIP_MULTICAST 0x0004
341 #define GAA_FLAG_SKIP_DNS_SERVER 0x0008
342 #define GAA_FLAG_INCLUDE_PREFIX 0x0010
343 #define GAA_FLAG_SKIP_FRIENDLY_NAME 0x0020
344
345 #endif /* _WINSOCK2API_ */
346
347 //
348 // IP_PER_ADAPTER_INFO - per-adapter IP information such as DNS server list.
349 //
350
351 typedef struct _IP_PER_ADAPTER_INFO {
352 UINT AutoconfigEnabled;
353 UINT AutoconfigActive;
354 PIP_ADDR_STRING CurrentDnsServer;
355 IP_ADDR_STRING DnsServerList;
356 } IP_PER_ADAPTER_INFO, *PIP_PER_ADAPTER_INFO;
357
358 //
359 // FIXED_INFO - the set of IP-related information which does not depend on DHCP
360 //
361
362 typedef struct {
363 char HostName[MAX_HOSTNAME_LEN + 4] ;
364 char DomainName[MAX_DOMAIN_NAME_LEN + 4];
365 PIP_ADDR_STRING CurrentDnsServer;
366 IP_ADDR_STRING DnsServerList;
367 UINT NodeType;
368 char ScopeId[MAX_SCOPE_ID_LEN + 4];
369 UINT EnableRouting;
370 UINT EnableProxy;
371 UINT EnableDns;
372 } FIXED_INFO, *PFIXED_INFO;
373
374 #pragma warning(pop)
375
376 #endif /*!MAX_ADAPTER_DESCRIPTION_LENGTH*/
377
378 #ifndef IP_INTERFACE_NAME_INFO_DEFINED
379 #define IP_INTERFACE_NAME_INFO_DEFINED
380
381 typedef struct ip_interface_name_info {
382 ULONG Index; // Interface Index
383 ULONG MediaType; // Interface Types - see ipifcons.h
384 UCHAR ConnectionType;
385 UCHAR AccessType;
386 GUID DeviceGuid; // Device GUID is the guid of the device
387 // that IP exposes
388 GUID InterfaceGuid; // Interface GUID, if not GUID_NULL is the
389 // GUID for the interface mapped to the device.
390 } IP_INTERFACE_NAME_INFO, *PIP_INTERFACE_NAME_INFO;
391
392 #endif
393
394
395 /* from ipifcons.h */
396
397 #ifndef IF_TYPE_PPP
398 #define IF_TYPE_PPP 23
399 #endif
400
401 #ifndef IF_TYPE_SOFTWARE_LOOPBACK
402 #define IF_TYPE_SOFTWARE_LOOPBACK 24
403 #endif
404
405 #ifndef IF_TYPE_SLIP
406 #define IF_TYPE_SLIP 28
407 #endif
408
409 #ifndef IF_TYPE_TUNNEL
410 #define IF_TYPE_TUNNEL 131
411 #endif
412
413 #endif
--- EOF ---