Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/java/net/net_util_md.h
32287 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <winsock2.h>26#include <WS2tcpip.h>2728/* typedefs that were defined correctly for the first time29* in Nov. 2001 SDK, which we need to include here.30* Specifically, in6_addr and sockaddr_in6 (which is defined but31* not correctly). When moving to a later SDK remove following32* code between START and END33*/3435/* --- START --- */3637/* WIN64 already uses newer SDK */38#ifdef _WIN643940#define SOCKADDR_IN6 sockaddr_in64142#else4344#ifdef _MSC_VER45#define WS2TCPIP_INLINE __inline46#else47#define WS2TCPIP_INLINE extern inline /* GNU style */48#endif4950#if defined(_MSC_VER) && _MSC_VER >= 13105152#define SOCKADDR_IN6 sockaddr_in65354#else5556/* Retain this code a little longer to support building in57* old environments. _MSC_VER is defined as:58* 1200 for MSVC++ 6.059* 1310 for Vc760*/6162#define IPPROTO_IPV6 4163#define IPV6_MULTICAST_IF 96465struct in6_addr {66union {67u_char Byte[16];68u_short Word[8];69} u;70};7172/*73** Defines to match RFC 2553.74*/75#define _S6_un u76#define _S6_u8 Byte77#define s6_addr _S6_un._S6_u87879/*80** Defines for our implementation.81*/82#define s6_bytes u.Byte83#define s6_words u.Word8485/* IPv6 socket address structure, RFC 2553 */8687struct SOCKADDR_IN6 {88short sin6_family; /* AF_INET6 */89u_short sin6_port; /* Transport level port number */90u_long sin6_flowinfo; /* IPv6 flow information */91struct in6_addr sin6_addr; /* IPv6 address */92u_long sin6_scope_id; /* set of interfaces for a scope */93};949596/* Error codes from getaddrinfo() */9798#define EAI_AGAIN WSATRY_AGAIN99#define EAI_BADFLAGS WSAEINVAL100#define EAI_FAIL WSANO_RECOVERY101#define EAI_FAMILY WSAEAFNOSUPPORT102#define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY103//#define EAI_NODATA WSANO_DATA104#define EAI_NONAME WSAHOST_NOT_FOUND105#define EAI_SERVICE WSATYPE_NOT_FOUND106#define EAI_SOCKTYPE WSAESOCKTNOSUPPORT107108#define EAI_NODATA EAI_NONAME109110/* Structure used in getaddrinfo() call */111112typedef struct addrinfo {113int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */114int ai_family; /* PF_xxx */115int ai_socktype; /* SOCK_xxx */116int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */117size_t ai_addrlen; /* Length of ai_addr */118char *ai_canonname; /* Canonical name for nodename */119struct sockaddr *ai_addr; /* Binary address */120struct addrinfo *ai_next; /* Next structure in linked list */121} ADDRINFO, FAR * LPADDRINFO;122123/* Flags used in "hints" argument to getaddrinfo() */124125#define AI_PASSIVE 0x1 /* Socket address will be used in bind() call */126#define AI_CANONNAME 0x2 /* Return canonical name in first ai_canonname */127#define AI_NUMERICHOST 0x4 /* Nodename must be a numeric address string */128129/* IPv6 Multicasting definitions */130131/* Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP */132133typedef struct ipv6_mreq {134struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address */135unsigned int ipv6mr_interface; /* Interface index */136} IPV6_MREQ;137138#define IPV6_ADD_MEMBERSHIP 12 /* Add an IP group membership */139#define IPV6_DROP_MEMBERSHIP 13 /* Drop an IP group membership */140#define IPV6_MULTICAST_LOOP 11 /* Set/get IP multicast loopback */141142WS2TCPIP_INLINE int143IN6_IS_ADDR_MULTICAST(const struct in6_addr *a)144{145return (a->s6_bytes[0] == 0xff);146}147148WS2TCPIP_INLINE int149IN6_IS_ADDR_LINKLOCAL(const struct in6_addr *a)150{151return (a->s6_bytes[0] == 0xfe152&& a->s6_bytes[1] == 0x80);153}154155#define NI_MAXHOST 1025 /* Max size of a fully-qualified domain name */156#define NI_MAXSERV 32 /* Max size of a service name */157158#define INET_ADDRSTRLEN 16 /* Max size of numeric form of IPv4 address */159#define INET6_ADDRSTRLEN 46 /* Max size of numeric form of IPv6 address */160161/* Flags for getnameinfo() */162163#define NI_NOFQDN 0x01 /* Only return nodename portion for local hosts */164#define NI_NUMERICHOST 0x02 /* Return numeric form of the host's address */165#define NI_NAMEREQD 0x04 /* Error if the host's name not in DNS */166#define NI_NUMERICSERV 0x08 /* Return numeric form of the service (port #) */167#define NI_DGRAM 0x10 /* Service is a datagram service */168169170#define IN6_IS_ADDR_V4MAPPED(a) \171(((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \172((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \173((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0xffff))174175176/* --- END --- */177#endif /* end 'else older build environment' */178179#endif180181#if !INCL_WINSOCK_API_TYPEDEFS182183typedef184int185(WSAAPI * LPFN_GETADDRINFO)(186IN const char FAR * nodename,187IN const char FAR * servname,188IN const struct addrinfo FAR * hints,189OUT struct addrinfo FAR * FAR * res190);191192typedef193void194(WSAAPI * LPFN_FREEADDRINFO)(195IN struct addrinfo FAR * ai196);197198typedef199int200(WSAAPI * LPFN_GETNAMEINFO)(201IN const struct sockaddr FAR * sa,202IN int salen,203OUT char FAR * host,204IN DWORD hostlen,205OUT char FAR * serv,206IN DWORD servlen,207IN int flags208);209#endif210211/* used to disable connection reset messages on Windows XP */212#ifndef SIO_UDP_CONNRESET213#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)214#endif215216#ifndef IN6_IS_ADDR_ANY217#define IN6_IS_ADDR_ANY(a) \218(((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \219((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \220((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0) && \221((a)->s6_words[6] == 0) && ((a)->s6_words[7] == 0))222#endif223224#ifndef IPV6_V6ONLY225#define IPV6_V6ONLY 27 /* Treat wildcard bind as AF_INET6-only. */226#endif227228#include "java_io_FileDescriptor.h"229#include "java_net_SocketOptions.h"230231#define MAX_BUFFER_LEN 2048232#define MAX_HEAP_BUFFER_LEN 65536233234235/* true if SO_RCVTIMEO is supported by underlying provider */236extern jboolean isRcvTimeoutSupported;237238void NET_ThrowCurrent(JNIEnv *env, char *msg);239240/*241* Return default Type Of Service242*/243int NET_GetDefaultTOS(void);244245typedef union {246struct sockaddr him;247struct sockaddr_in him4;248struct SOCKADDR_IN6 him6;249} SOCKETADDRESS;250251/*252* passed to NET_BindV6. Both ipv4_fd and ipv6_fd must be created and unbound253* sockets. On return they may refer to different sockets.254*/255struct ipv6bind {256SOCKETADDRESS *addr;257SOCKET ipv4_fd;258SOCKET ipv6_fd;259};260261#define SOCKETADDRESS_LEN(X) \262(((X)->him.sa_family==AF_INET6)? sizeof(struct SOCKADDR_IN6) : \263sizeof(struct sockaddr_in))264265#define SOCKETADDRESS_COPY(DST,SRC) { \266if ((SRC)->sa_family == AF_INET6) { \267memcpy ((DST), (SRC), sizeof (struct SOCKADDR_IN6)); \268} else { \269memcpy ((DST), (SRC), sizeof (struct sockaddr_in)); \270} \271}272273#define SET_PORT(X,Y) { \274if ((X)->him.sa_family == AF_INET) { \275(X)->him4.sin_port = (Y); \276} else { \277(X)->him6.sin6_port = (Y); \278} \279}280281#define GET_PORT(X) ((X)->him.sa_family==AF_INET ?(X)->him4.sin_port: (X)->him6.sin6_port)282283#define IS_LOOPBACK_ADDRESS(x) ( \284((x)->him.sa_family == AF_INET) ? \285(ntohl((x)->him4.sin_addr.s_addr)==INADDR_LOOPBACK) : \286(IN6ADDR_ISLOOPBACK (x)) \287)288289JNIEXPORT int JNICALL NET_SocketClose(int fd);290291JNIEXPORT int JNICALL NET_Timeout(int fd, long timeout);292293int NET_Socket(int domain, int type, int protocol);294295void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,296const char *defaultDetail);297298void NET_ThrowSocketException(JNIEnv *env, char* msg);299300/*301* differs from NET_Timeout() as follows:302*303* If timeout = -1, it blocks forever.304*305* returns 1 or 2 depending if only one or both sockets306* fire at same time.307*308* *fdret is (one of) the active fds. If both sockets309* fire at same time, *fd == fd always.310*/311JNIEXPORT int JNICALL NET_Timeout2(int fd, int fd1, long timeout, int *fdret);312313JNIEXPORT int JNICALL NET_BindV6(struct ipv6bind* b, jboolean exclBind);314315#define NET_WAIT_READ 0x01316#define NET_WAIT_WRITE 0x02317#define NET_WAIT_CONNECT 0x04318319extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);320321JNIEXPORT int JNICALL NET_WinBind(int s, struct sockaddr *him, int len,322jboolean exclBind);323324/* XP versions of the native routines */325326JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0_XP327(JNIEnv *env, jclass cls, jstring name);328329JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0_XP330(JNIEnv *env, jclass cls, jint index);331332JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0_XP333(JNIEnv *env, jclass cls, jobject iaObj);334335JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll_XP336(JNIEnv *env, jclass cls);337338JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0_XP339(JNIEnv *env, jclass cls, jstring name, jint index);340341JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0_XP342(JNIEnv *env, jclass cls, jstring name, jint index);343344JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0_XP345(JNIEnv *env, jclass cls, jstring name, jint index);346347JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP348(JNIEnv *env, jclass cls, jstring name, jint index);349350JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0_XP351(JNIEnv *env, jclass class, jstring name, jint index);352353JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0_XP354(JNIEnv *env, jclass cls, jstring name, jint index);355356357