annotate src/windows/native/java/net/net_util_md.h @ 3261:a06412e13bf7

6962318: Update copyright year Reviewed-by: xdono
author ohair
date Tue, 28 Dec 2010 15:53:50 -0800
parents 00cd9dc3c2b5
children c250a66c3b54
rev   line source
duke@0 1 /*
ohair@3261 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
ohair@2362 7 * published by the Free Software Foundation. Oracle designates this
duke@0 8 * particular file as subject to the "Classpath" exception as provided
ohair@2362 9 * by Oracle in the LICENSE file that accompanied this code.
duke@0 10 *
duke@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 * accompanied this code).
duke@0 16 *
duke@0 17 * You should have received a copy of the GNU General Public License version
duke@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 *
ohair@2362 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@2362 22 * or visit www.oracle.com if you need additional information or have any
ohair@2362 23 * questions.
duke@0 24 */
duke@0 25
duke@0 26 #include <winsock2.h>
duke@0 27 #include <WS2tcpip.h>
duke@0 28
duke@0 29 /* typedefs that were defined correctly for the first time
duke@0 30 * in Nov. 2001 SDK, which we need to include here.
duke@0 31 * Specifically, in6_addr and sockaddr_in6 (which is defined but
duke@0 32 * not correctly). When moving to a later SDK remove following
duke@0 33 * code between START and END
duke@0 34 */
duke@0 35
duke@0 36 /* --- START --- */
duke@0 37
duke@0 38 /* WIN64 already uses newer SDK */
duke@0 39 #ifdef _WIN64
duke@0 40
duke@0 41 #define SOCKADDR_IN6 sockaddr_in6
duke@0 42
duke@0 43 #else
duke@0 44
duke@0 45 #ifdef _MSC_VER
duke@0 46 #define WS2TCPIP_INLINE __inline
duke@0 47 #else
duke@0 48 #define WS2TCPIP_INLINE extern inline /* GNU style */
duke@0 49 #endif
duke@0 50
duke@0 51 #if defined(_MSC_VER) && _MSC_VER >= 1310
duke@0 52
duke@0 53 #define SOCKADDR_IN6 sockaddr_in6
duke@0 54
duke@0 55 #else
duke@0 56
duke@0 57 /* Retain this code a little longer to support building in
duke@0 58 * old environments. _MSC_VER is defined as:
duke@0 59 * 1200 for MSVC++ 6.0
duke@0 60 * 1310 for Vc7
duke@0 61 */
duke@0 62
duke@0 63 #define IPPROTO_IPV6 41
duke@0 64 #define IPV6_MULTICAST_IF 9
duke@0 65
duke@0 66 struct in6_addr {
duke@0 67 union {
duke@0 68 u_char Byte[16];
duke@0 69 u_short Word[8];
duke@0 70 } u;
duke@0 71 };
duke@0 72
duke@0 73 /*
duke@0 74 ** Defines to match RFC 2553.
duke@0 75 */
duke@0 76 #define _S6_un u
duke@0 77 #define _S6_u8 Byte
duke@0 78 #define s6_addr _S6_un._S6_u8
duke@0 79
duke@0 80 /*
duke@0 81 ** Defines for our implementation.
duke@0 82 */
duke@0 83 #define s6_bytes u.Byte
duke@0 84 #define s6_words u.Word
duke@0 85
duke@0 86 /* IPv6 socket address structure, RFC 2553 */
duke@0 87
duke@0 88 struct SOCKADDR_IN6 {
duke@0 89 short sin6_family; /* AF_INET6 */
duke@0 90 u_short sin6_port; /* Transport level port number */
duke@0 91 u_long sin6_flowinfo; /* IPv6 flow information */
duke@0 92 struct in6_addr sin6_addr; /* IPv6 address */
duke@0 93 u_long sin6_scope_id; /* set of interfaces for a scope */
duke@0 94 };
duke@0 95
duke@0 96
duke@0 97 /* Error codes from getaddrinfo() */
duke@0 98
duke@0 99 #define EAI_AGAIN WSATRY_AGAIN
duke@0 100 #define EAI_BADFLAGS WSAEINVAL
duke@0 101 #define EAI_FAIL WSANO_RECOVERY
duke@0 102 #define EAI_FAMILY WSAEAFNOSUPPORT
duke@0 103 #define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
duke@0 104 //#define EAI_NODATA WSANO_DATA
duke@0 105 #define EAI_NONAME WSAHOST_NOT_FOUND
duke@0 106 #define EAI_SERVICE WSATYPE_NOT_FOUND
duke@0 107 #define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
duke@0 108
duke@0 109 #define EAI_NODATA EAI_NONAME
duke@0 110
duke@0 111 /* Structure used in getaddrinfo() call */
duke@0 112
duke@0 113 typedef struct addrinfo {
duke@0 114 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
duke@0 115 int ai_family; /* PF_xxx */
duke@0 116 int ai_socktype; /* SOCK_xxx */
duke@0 117 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
duke@0 118 size_t ai_addrlen; /* Length of ai_addr */
duke@0 119 char *ai_canonname; /* Canonical name for nodename */
duke@0 120 struct sockaddr *ai_addr; /* Binary address */
duke@0 121 struct addrinfo *ai_next; /* Next structure in linked list */
duke@0 122 } ADDRINFO, FAR * LPADDRINFO;
duke@0 123
duke@0 124 /* Flags used in "hints" argument to getaddrinfo() */
duke@0 125
duke@0 126 #define AI_PASSIVE 0x1 /* Socket address will be used in bind() call */
duke@0 127 #define AI_CANONNAME 0x2 /* Return canonical name in first ai_canonname */
duke@0 128 #define AI_NUMERICHOST 0x4 /* Nodename must be a numeric address string */
duke@0 129
duke@0 130 /* IPv6 Multicasting definitions */
duke@0 131
duke@0 132 /* Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP */
duke@0 133
duke@0 134 typedef struct ipv6_mreq {
duke@0 135 struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address */
duke@0 136 unsigned int ipv6mr_interface; /* Interface index */
duke@0 137 } IPV6_MREQ;
duke@0 138
duke@0 139 #define IPV6_ADD_MEMBERSHIP 12 /* Add an IP group membership */
duke@0 140 #define IPV6_DROP_MEMBERSHIP 13 /* Drop an IP group membership */
duke@0 141 #define IPV6_MULTICAST_LOOP 11 /* Set/get IP multicast loopback */
duke@0 142
duke@0 143 WS2TCPIP_INLINE int
duke@0 144 IN6_IS_ADDR_MULTICAST(const struct in6_addr *a)
duke@0 145 {
duke@0 146 return (a->s6_bytes[0] == 0xff);
duke@0 147 }
duke@0 148
duke@0 149 WS2TCPIP_INLINE int
duke@0 150 IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *a)
duke@0 151 {
duke@0 152 return (a->s6_bytes[0] == 0xfe
duke@0 153 && a->s6_bytes[1] == 0x80);
duke@0 154 }
duke@0 155
duke@0 156 #define NI_MAXHOST 1025 /* Max size of a fully-qualified domain name */
duke@0 157 #define NI_MAXSERV 32 /* Max size of a service name */
duke@0 158
duke@0 159 #define INET_ADDRSTRLEN 16 /* Max size of numeric form of IPv4 address */
duke@0 160 #define INET6_ADDRSTRLEN 46 /* Max size of numeric form of IPv6 address */
duke@0 161
duke@0 162 /* Flags for getnameinfo() */
duke@0 163
duke@0 164 #define NI_NOFQDN 0x01 /* Only return nodename portion for local hosts */
duke@0 165 #define NI_NUMERICHOST 0x02 /* Return numeric form of the host's address */
duke@0 166 #define NI_NAMEREQD 0x04 /* Error if the host's name not in DNS */
duke@0 167 #define NI_NUMERICSERV 0x08 /* Return numeric form of the service (port #) */
duke@0 168 #define NI_DGRAM 0x10 /* Service is a datagram service */
duke@0 169
duke@0 170
duke@0 171 #define IN6_IS_ADDR_V4MAPPED(a) \
duke@0 172 (((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \
duke@0 173 ((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \
duke@0 174 ((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0xffff))
duke@0 175
duke@0 176
duke@0 177 /* --- END --- */
duke@0 178 #endif /* end 'else older build environment' */
duke@0 179
duke@0 180 #endif
duke@0 181
duke@0 182 #if !INCL_WINSOCK_API_TYPEDEFS
duke@0 183
duke@0 184 typedef
duke@0 185 int
duke@0 186 (WSAAPI * LPFN_GETADDRINFO)(
duke@0 187 IN const char FAR * nodename,
duke@0 188 IN const char FAR * servname,
duke@0 189 IN const struct addrinfo FAR * hints,
duke@0 190 OUT struct addrinfo FAR * FAR * res
duke@0 191 );
duke@0 192
duke@0 193 typedef
duke@0 194 void
duke@0 195 (WSAAPI * LPFN_FREEADDRINFO)(
duke@0 196 IN struct addrinfo FAR * ai
duke@0 197 );
duke@0 198
duke@0 199 typedef
duke@0 200 int
duke@0 201 (WSAAPI * LPFN_GETNAMEINFO)(
duke@0 202 IN const struct sockaddr FAR * sa,
duke@0 203 IN int salen,
duke@0 204 OUT char FAR * host,
duke@0 205 IN DWORD hostlen,
duke@0 206 OUT char FAR * serv,
duke@0 207 IN DWORD servlen,
duke@0 208 IN int flags
duke@0 209 );
duke@0 210 #endif
duke@0 211
duke@0 212 LPFN_GETADDRINFO getaddrinfo_ptr;
duke@0 213 LPFN_FREEADDRINFO freeaddrinfo_ptr;
duke@0 214 LPFN_GETNAMEINFO getnameinfo_ptr;
duke@0 215
duke@0 216 /* used to disable connection reset messages on Windows XP */
duke@0 217 #ifndef SIO_UDP_CONNRESET
duke@0 218 #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)
duke@0 219 #endif
duke@0 220
duke@0 221 #ifndef IN6_IS_ADDR_ANY
duke@0 222 #define IN6_IS_ADDR_ANY(a) \
duke@0 223 (((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \
duke@0 224 ((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \
chegar@2340 225 ((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0) && \
chegar@2340 226 ((a)->s6_words[6] == 0) && ((a)->s6_words[7] == 0))
duke@0 227 #endif
duke@0 228
duke@0 229 #ifndef IPV6_V6ONLY
duke@0 230 #define IPV6_V6ONLY 27 /* Treat wildcard bind as AF_INET6-only. */
duke@0 231 #endif
duke@0 232
duke@0 233 #include "java_io_FileDescriptor.h"
duke@0 234 #include "java_net_SocketOptions.h"
duke@0 235
duke@0 236 #define MAX_BUFFER_LEN 2048
duke@0 237 #define MAX_HEAP_BUFFER_LEN 65536
duke@0 238
duke@0 239
duke@0 240 /* true if SO_RCVTIMEO is supported by underlying provider */
duke@0 241 extern jboolean isRcvTimeoutSupported;
duke@0 242
duke@0 243 void NET_ThrowCurrent(JNIEnv *env, char *msg);
duke@0 244
duke@0 245 /*
duke@0 246 * Return default Type Of Service
duke@0 247 */
duke@0 248 int NET_GetDefaultTOS(void);
duke@0 249
duke@0 250 typedef union {
duke@0 251 struct sockaddr him;
duke@0 252 struct sockaddr_in him4;
duke@0 253 struct SOCKADDR_IN6 him6;
duke@0 254 } SOCKETADDRESS;
duke@0 255
duke@0 256 /*
duke@0 257 * passed to NET_BindV6. Both ipv4_fd and ipv6_fd must be created and unbound
duke@0 258 * sockets. On return they may refer to different sockets.
duke@0 259 */
duke@0 260 struct ipv6bind {
duke@0 261 SOCKETADDRESS *addr;
duke@0 262 SOCKET ipv4_fd;
duke@0 263 SOCKET ipv6_fd;
duke@0 264 };
duke@0 265
duke@0 266 #define SOCKETADDRESS_LEN(X) \
duke@0 267 (((X)->him.sa_family==AF_INET6)? sizeof(struct SOCKADDR_IN6) : \
duke@0 268 sizeof(struct sockaddr_in))
duke@0 269
duke@0 270 #define SOCKETADDRESS_COPY(DST,SRC) { \
duke@0 271 if ((SRC)->sa_family == AF_INET6) { \
duke@0 272 memcpy ((DST), (SRC), sizeof (struct SOCKADDR_IN6)); \
duke@0 273 } else { \
duke@0 274 memcpy ((DST), (SRC), sizeof (struct sockaddr_in)); \
duke@0 275 } \
duke@0 276 }
duke@0 277
duke@0 278 #define SET_PORT(X,Y) { \
duke@0 279 if ((X)->him.sa_family == AF_INET) { \
duke@0 280 (X)->him4.sin_port = (Y); \
duke@0 281 } else { \
duke@0 282 (X)->him6.sin6_port = (Y); \
duke@0 283 } \
duke@0 284 }
duke@0 285
duke@0 286 #define GET_PORT(X) ((X)->him.sa_family==AF_INET ?(X)->him4.sin_port: (X)->him6.sin6_port)
duke@0 287
duke@0 288 #define IS_LOOPBACK_ADDRESS(x) ( \
duke@0 289 ((x)->him.sa_family == AF_INET) ? \
duke@0 290 (ntohl((x)->him4.sin_addr.s_addr)==INADDR_LOOPBACK) : \
duke@0 291 (IN6ADDR_ISLOOPBACK (x)) \
duke@0 292 )
duke@0 293
duke@0 294 JNIEXPORT int JNICALL NET_SocketClose(int fd);
duke@0 295
duke@0 296 JNIEXPORT int JNICALL NET_Timeout(int fd, long timeout);
duke@0 297
chegar@453 298 int NET_Socket(int domain, int type, int protocol);
chegar@453 299
chegar@453 300 void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
chegar@453 301 const char *defaultDetail);
chegar@453 302
chegar@453 303 void NET_ThrowSocketException(JNIEnv *env, char* msg);
chegar@453 304
chegar@453 305 jboolean NET_addrtransAvailable();
chegar@453 306
duke@0 307 /*
duke@0 308 * differs from NET_Timeout() as follows:
duke@0 309 *
duke@0 310 * If timeout = -1, it blocks forever.
duke@0 311 *
duke@0 312 * returns 1 or 2 depending if only one or both sockets
duke@0 313 * fire at same time.
duke@0 314 *
duke@0 315 * *fdret is (one of) the active fds. If both sockets
duke@0 316 * fire at same time, *fd == fd always.
duke@0 317 */
duke@0 318 JNIEXPORT int JNICALL NET_Timeout2(int fd, int fd1, long timeout, int *fdret);
duke@0 319
duke@0 320 JNIEXPORT int JNICALL NET_BindV6(struct ipv6bind* b);
duke@0 321
duke@0 322 #define NET_WAIT_READ 0x01
duke@0 323 #define NET_WAIT_WRITE 0x02
duke@0 324 #define NET_WAIT_CONNECT 0x04
duke@0 325
duke@0 326 extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
duke@0 327
duke@0 328 /* XP versions of the native routines */
duke@0 329
duke@0 330 JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0_XP
duke@0 331 (JNIEnv *env, jclass cls, jstring name);
duke@0 332
jccollet@509 333 JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0_XP
duke@0 334 (JNIEnv *env, jclass cls, jint index);
duke@0 335
duke@0 336 JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0_XP
duke@0 337 (JNIEnv *env, jclass cls, jobject iaObj);
duke@0 338
duke@0 339 JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll_XP
duke@0 340 (JNIEnv *env, jclass cls);
duke@0 341
duke@0 342 JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0_XP
duke@0 343 (JNIEnv *env, jclass cls, jstring name, jint index);
duke@0 344
duke@0 345 JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0_XP
duke@0 346 (JNIEnv *env, jclass cls, jstring name, jint index);
duke@0 347
duke@0 348 JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0_XP
duke@0 349 (JNIEnv *env, jclass cls, jstring name, jint index);
duke@0 350
duke@0 351 JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP
duke@0 352 (JNIEnv *env, jclass cls, jstring name, jint index);
duke@0 353
duke@0 354 JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0_XP
duke@0 355 (JNIEnv *env, jclass class, jstring name, jint index);
duke@0 356
duke@0 357 JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0_XP
duke@0 358 (JNIEnv *env, jclass cls, jstring name, jint index);