Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/windows/native/libnet/net_util_md.h
41119 views
1
/*
2
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle 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 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.
24
*/
25
#include <winsock2.h>
26
#include <WS2tcpip.h>
27
#include <iphlpapi.h>
28
#include <icmpapi.h>
29
#include <mstcpip.h>
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) && \
40
((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0) && \
41
((a)->s6_words[6] == 0) && ((a)->s6_words[7] == 0))
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 {
57
struct sockaddr sa;
58
struct sockaddr_in sa4;
59
struct sockaddr_in6 sa6;
60
} SOCKETADDRESS;
61
62
/*
63
* passed to NET_BindV6. Both ipv4_fd and ipv6_fd must be created and unbound
64
* sockets. On return they may refer to different sockets.
65
*/
66
struct ipv6bind {
67
SOCKETADDRESS *addr;
68
SOCKET ipv4_fd;
69
SOCKET ipv6_fd;
70
};
71
72
#define SOCKETADDRESS_COPY(DST,SRC) { \
73
if ((SRC)->sa_family == AF_INET6) { \
74
memcpy ((DST), (SRC), sizeof (struct sockaddr_in6)); \
75
} else { \
76
memcpy ((DST), (SRC), sizeof (struct sockaddr_in)); \
77
} \
78
}
79
80
#define SET_PORT(X,Y) { \
81
if ((X)->sa.sa_family == AF_INET) { \
82
(X)->sa4.sin_port = (Y); \
83
} else { \
84
(X)->sa6.sin6_port = (Y); \
85
} \
86
}
87
88
#define GET_PORT(X) ((X)->sa.sa_family == AF_INET ? (X)->sa4.sin_port : (X)->sa6.sin6_port)
89
90
/**
91
* With dual socket implementation the
92
* IPv4 addresseses might be mapped as IPv6.
93
* The IPv4 loopback adapter address ranges (127.0.0.0 through 127.255.255.255) will
94
* be mapped as the following IPv6 ::ffff:127.0.0.0 through ::ffff:127.255.255.255.
95
* For example, this is done by NET_InetAddressToSockaddr.
96
*/
97
#define IN6_IS_ADDR_V4MAPPED_LOOPBACK(x) ( \
98
(((x)->s6_words[0] == 0) && \
99
((x)->s6_words[1] == 0) && \
100
((x)->s6_words[2] == 0) && \
101
((x)->s6_words[3] == 0) && \
102
((x)->s6_words[4] == 0) && \
103
((x)->s6_words[5] == 0xFFFF) && \
104
(((x)->s6_words[6] & 0x00FF) == 0x007F)) \
105
)
106
107
/**
108
* Check for IPv4 loopback adapter address ranges (127.0.0.0 through 127.255.255.255)
109
*/
110
#define IN4_IS_ADDR_NETLONG_LOOPBACK(l) ( \
111
((l & 0xFF000000) == 0x7F000000) \
112
)
113
114
#define IS_LOOPBACK_ADDRESS(x) ( \
115
((x)->sa.sa_family == AF_INET) ? \
116
(IN4_IS_ADDR_NETLONG_LOOPBACK(ntohl((x)->sa4.sin_addr.s_addr))) : \
117
((IN6_IS_ADDR_LOOPBACK(&(x)->sa6.sin6_addr)) || \
118
(IN6_IS_ADDR_V4MAPPED_LOOPBACK(&(x)->sa6.sin6_addr))) \
119
)
120
121
JNIEXPORT int JNICALL NET_SocketClose(int fd);
122
123
JNIEXPORT int JNICALL NET_Timeout(int fd, long timeout);
124
125
int NET_Socket(int domain, int type, int protocol);
126
127
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
128
const char *defaultDetail);
129
130
/*
131
* differs from NET_Timeout() as follows:
132
*
133
* If timeout = -1, it blocks forever.
134
*
135
* returns 1 or 2 depending if only one or both sockets
136
* fire at same time.
137
*
138
* *fdret is (one of) the active fds. If both sockets
139
* fire at same time, *fd == fd always.
140
*/
141
JNIEXPORT int JNICALL NET_Timeout2(int fd, int fd1, long timeout, int *fdret);
142
143
JNIEXPORT int JNICALL NET_BindV6(struct ipv6bind *b, jboolean exclBind);
144
145
JNIEXPORT int JNICALL NET_WinBind(int s, SOCKETADDRESS *sa, int len,
146
jboolean exclBind);
147
148
JNIEXPORT jint JNICALL NET_EnableFastTcpLoopbackConnect(int fd);
149
150
/* XP versions of the native routines */
151
152
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0_XP
153
(JNIEnv *env, jclass cls, jstring name);
154
155
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0_XP
156
(JNIEnv *env, jclass cls, jint index);
157
158
JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0_XP
159
(JNIEnv *env, jclass cls, jobject iaObj);
160
161
JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll_XP
162
(JNIEnv *env, jclass cls);
163
164
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0_XP
165
(JNIEnv *env, jclass cls, jstring name, jint index);
166
167
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0_XP
168
(JNIEnv *env, jclass cls, jstring name, jint index);
169
170
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0_XP
171
(JNIEnv *env, jclass cls, jstring name, jint index);
172
173
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP
174
(JNIEnv *env, jclass cls, jstring name, jint index);
175
176
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0_XP
177
(JNIEnv *env, jclass class, jstring name, jint index);
178
179
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0_XP
180
(JNIEnv *env, jclass cls, jstring name, jint index);
181
182