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