author | michaelm |
Fri, 25 Oct 2019 15:56:35 +0100 | |
branch | unixdomainchannels |
changeset 58801 | 119ac9128c1b |
parent 49892 | 8bed781a8d9c |
child 59019 | dafa6389ed47 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49892
8bed781a8d9c
8202154: Remove unused code in java.base/windows/native/libnet
igerasim
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
#include <winsock2.h> |
|
26 |
#include <WS2tcpip.h> |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
27 |
#include <iphlpapi.h> |
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
28 |
#include <icmpapi.h> |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
49892
diff
changeset
|
29 |
#include <afunix.h> |
2 | 30 |
|
31 |
/* used to disable connection reset messages on Windows XP */ |
|
32 |
#ifndef SIO_UDP_CONNRESET |
|
33 |
#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12) |
|
34 |
#endif |
|
35 |
||
36 |
#ifndef IN6_IS_ADDR_ANY |
|
37 |
#define IN6_IS_ADDR_ANY(a) \ |
|
38 |
(((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \ |
|
39 |
((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \ |
|
5456
40ff273941a2
6718504: IN6_IS_ADDR_ANY tests only 12 bytes of 16-byte address
chegar
parents:
1247
diff
changeset
|
40 |
((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0) && \ |
40ff273941a2
6718504: IN6_IS_ADDR_ANY tests only 12 bytes of 16-byte address
chegar
parents:
1247
diff
changeset
|
41 |
((a)->s6_words[6] == 0) && ((a)->s6_words[7] == 0)) |
2 | 42 |
#endif |
43 |
||
44 |
#ifndef IPV6_V6ONLY |
|
45 |
#define IPV6_V6ONLY 27 /* Treat wildcard bind as AF_INET6-only. */ |
|
46 |
#endif |
|
47 |
||
48 |
#define MAX_BUFFER_LEN 2048 |
|
49 |
#define MAX_HEAP_BUFFER_LEN 65536 |
|
50 |
||
51 |
/* true if SO_RCVTIMEO is supported by underlying provider */ |
|
52 |
extern jboolean isRcvTimeoutSupported; |
|
53 |
||
54 |
void NET_ThrowCurrent(JNIEnv *env, char *msg); |
|
55 |
||
56 |
typedef union { |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
57 |
struct sockaddr sa; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
58 |
struct sockaddr_in sa4; |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
59 |
struct sockaddr_in6 sa6; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
49892
diff
changeset
|
60 |
struct sockaddr_un saun; |
2 | 61 |
} SOCKETADDRESS; |
62 |
||
63 |
/* |
|
64 |
* passed to NET_BindV6. Both ipv4_fd and ipv6_fd must be created and unbound |
|
65 |
* sockets. On return they may refer to different sockets. |
|
66 |
*/ |
|
67 |
struct ipv6bind { |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
68 |
SOCKETADDRESS *addr; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
69 |
SOCKET ipv4_fd; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
70 |
SOCKET ipv6_fd; |
2 | 71 |
}; |
72 |
||
73 |
#define SOCKETADDRESS_COPY(DST,SRC) { \ |
|
74 |
if ((SRC)->sa_family == AF_INET6) { \ |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
75 |
memcpy ((DST), (SRC), sizeof (struct sockaddr_in6)); \ |
2 | 76 |
} else { \ |
77 |
memcpy ((DST), (SRC), sizeof (struct sockaddr_in)); \ |
|
78 |
} \ |
|
79 |
} |
|
80 |
||
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
81 |
#define SET_PORT(X,Y) { \ |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
82 |
if ((X)->sa.sa_family == AF_INET) { \ |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
83 |
(X)->sa4.sin_port = (Y); \ |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
84 |
} else { \ |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
85 |
(X)->sa6.sin6_port = (Y); \ |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
86 |
} \ |
2 | 87 |
} |
88 |
||
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
89 |
#define GET_PORT(X) ((X)->sa.sa_family == AF_INET ? (X)->sa4.sin_port : (X)->sa6.sin6_port) |
2 | 90 |
|
91 |
#define IS_LOOPBACK_ADDRESS(x) ( \ |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
92 |
((x)->sa.sa_family == AF_INET) ? \ |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
93 |
(ntohl((x)->sa4.sin_addr.s_addr) == INADDR_LOOPBACK) : \ |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
94 |
(IN6ADDR_ISLOOPBACK(x)) \ |
2 | 95 |
) |
96 |
||
97 |
JNIEXPORT int JNICALL NET_SocketClose(int fd); |
|
98 |
||
99 |
JNIEXPORT int JNICALL NET_Timeout(int fd, long timeout); |
|
100 |
||
910 | 101 |
int NET_Socket(int domain, int type, int protocol); |
102 |
||
103 |
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name, |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
104 |
const char *defaultDetail); |
910 | 105 |
|
2 | 106 |
/* |
107 |
* differs from NET_Timeout() as follows: |
|
108 |
* |
|
109 |
* If timeout = -1, it blocks forever. |
|
110 |
* |
|
111 |
* returns 1 or 2 depending if only one or both sockets |
|
112 |
* fire at same time. |
|
113 |
* |
|
114 |
* *fdret is (one of) the active fds. If both sockets |
|
115 |
* fire at same time, *fd == fd always. |
|
116 |
*/ |
|
117 |
JNIEXPORT int JNICALL NET_Timeout2(int fd, int fd1, long timeout, int *fdret); |
|
118 |
||
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
119 |
JNIEXPORT int JNICALL NET_BindV6(struct ipv6bind *b, jboolean exclBind); |
2 | 120 |
|
43100 | 121 |
JNIEXPORT int JNICALL NET_WinBind(int s, SOCKETADDRESS *sa, int len, |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
122 |
jboolean exclBind); |
18192 | 123 |
|
2 | 124 |
/* XP versions of the native routines */ |
125 |
||
126 |
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0_XP |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
127 |
(JNIEnv *env, jclass cls, jstring name); |
2 | 128 |
|
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
910
diff
changeset
|
129 |
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0_XP |
2 | 130 |
(JNIEnv *env, jclass cls, jint index); |
131 |
||
132 |
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0_XP |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
133 |
(JNIEnv *env, jclass cls, jobject iaObj); |
2 | 134 |
|
135 |
JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll_XP |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
136 |
(JNIEnv *env, jclass cls); |
2 | 137 |
|
138 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0_XP |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
139 |
(JNIEnv *env, jclass cls, jstring name, jint index); |
2 | 140 |
|
141 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0_XP |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
142 |
(JNIEnv *env, jclass cls, jstring name, jint index); |
2 | 143 |
|
144 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0_XP |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
145 |
(JNIEnv *env, jclass cls, jstring name, jint index); |
2 | 146 |
|
147 |
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
148 |
(JNIEnv *env, jclass cls, jstring name, jint index); |
2 | 149 |
|
150 |
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0_XP |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
151 |
(JNIEnv *env, jclass class, jstring name, jint index); |
2 | 152 |
|
153 |
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0_XP |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
41210
diff
changeset
|
154 |
(JNIEnv *env, jclass cls, jstring name, jint index); |