author | mbaesken |
Fri, 22 Nov 2019 10:29:12 +0100 | |
changeset 59243 | fb1d9bf1be2b |
parent 55375 | 96c7427456f9 |
child 59256 | aa516a7cf95e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, 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 |
||
26 |
#ifndef NET_UTILS_H |
|
27 |
#define NET_UTILS_H |
|
28 |
||
29 |
#include "jvm.h" |
|
30 |
#include "jni_util.h" |
|
31 |
#include "net_util_md.h" |
|
32 |
||
33 |
/************************************************************************ |
|
34 |
* Macros and misc constants |
|
35 |
*/ |
|
36 |
||
37 |
#define MAX_PACKET_LEN 65536 |
|
38 |
||
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
39 |
#define NET_WAIT_READ 0x01 |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
40 |
#define NET_WAIT_WRITE 0x02 |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
41 |
#define NET_WAIT_CONNECT 0x04 |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
42 |
|
2 | 43 |
/************************************************************************ |
44 |
* Cached field IDs |
|
45 |
* |
|
46 |
* The naming convention for field IDs is |
|
47 |
* <class abbrv>_<fieldName>ID |
|
48 |
* i.e. psi_timeoutID is PlainSocketImpl's timeout field's ID. |
|
49 |
*/ |
|
50 |
extern jclass ia_class; |
|
16870 | 51 |
extern jfieldID iac_addressID; |
52 |
extern jfieldID iac_familyID; |
|
53 |
extern jfieldID iac_hostNameID; |
|
33301
9ee33abf5b4c
8133196: HTTPS hostname invalid issue with InetAddress
coffeys
parents:
27178
diff
changeset
|
54 |
extern jfieldID iac_origHostNameID; |
2 | 55 |
extern jfieldID ia_preferIPv6AddressID; |
56 |
||
22646
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
22607
diff
changeset
|
57 |
JNIEXPORT void JNICALL initInetAddressIDs(JNIEnv *env); |
5fa3669fd35d
8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents:
22607
diff
changeset
|
58 |
|
20821 | 59 |
/** (Inet6Address accessors) |
60 |
* set_ methods return JNI_TRUE on success JNI_FALSE on error |
|
61 |
* get_ methods that return int/boolean, return -1 on error |
|
62 |
* get_ methods that return objects return NULL on error. |
|
63 |
*/ |
|
22956 | 64 |
extern jboolean setInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj, jobject scopeifname); |
43100 | 65 |
extern unsigned int getInet6Address_scopeid(JNIEnv *env, jobject ia6Obj); |
22956 | 66 |
extern jboolean setInet6Address_scopeid(JNIEnv *env, jobject ia6Obj, int scopeid); |
67 |
extern jboolean getInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *dest); |
|
68 |
extern jboolean setInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *address); |
|
20821 | 69 |
|
16870 | 70 |
extern void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address); |
71 |
extern void setInetAddress_family(JNIEnv *env, jobject iaObj, int family); |
|
72 |
extern void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject h); |
|
73 |
extern int getInetAddress_addr(JNIEnv *env, jobject iaObj); |
|
74 |
extern int getInetAddress_family(JNIEnv *env, jobject iaObj); |
|
75 |
||
2 | 76 |
extern jclass ia4_class; |
77 |
extern jmethodID ia4_ctrID; |
|
78 |
||
79 |
/* NetworkInterface fields */ |
|
80 |
extern jclass ni_class; |
|
81 |
extern jfieldID ni_nameID; |
|
82 |
extern jfieldID ni_indexID; |
|
83 |
extern jfieldID ni_addrsID; |
|
84 |
extern jfieldID ni_descID; |
|
85 |
extern jmethodID ni_ctrID; |
|
86 |
||
87 |
/* PlainSocketImpl fields */ |
|
88 |
extern jfieldID psi_timeoutID; |
|
89 |
extern jfieldID psi_fdID; |
|
90 |
extern jfieldID psi_addressID; |
|
91 |
extern jfieldID psi_portID; |
|
92 |
extern jfieldID psi_localportID; |
|
93 |
||
94 |
/* DatagramPacket fields */ |
|
95 |
extern jfieldID dp_addressID; |
|
96 |
extern jfieldID dp_portID; |
|
97 |
extern jfieldID dp_bufID; |
|
98 |
extern jfieldID dp_offsetID; |
|
99 |
extern jfieldID dp_lengthID; |
|
100 |
extern jfieldID dp_bufLengthID; |
|
101 |
||
102 |
/* Inet6Address fields */ |
|
103 |
extern jclass ia6_class; |
|
20821 | 104 |
extern jfieldID ia6_holder6ID; |
2 | 105 |
extern jfieldID ia6_ipaddressID; |
106 |
extern jfieldID ia6_scopeidID; |
|
107 |
extern jfieldID ia6_scopeidsetID; |
|
108 |
extern jfieldID ia6_scopeifnameID; |
|
109 |
extern jmethodID ia6_ctrID; |
|
110 |
||
111 |
/************************************************************************ |
|
112 |
* Utilities |
|
113 |
*/ |
|
114 |
JNIEXPORT void JNICALL Java_java_net_InetAddress_init(JNIEnv *env, jclass cls); |
|
115 |
JNIEXPORT void JNICALL Java_java_net_Inet4Address_init(JNIEnv *env, jclass cls); |
|
116 |
JNIEXPORT void JNICALL Java_java_net_Inet6Address_init(JNIEnv *env, jclass cls); |
|
117 |
JNIEXPORT void JNICALL Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls); |
|
118 |
||
119 |
JNIEXPORT void JNICALL NET_ThrowNew(JNIEnv *env, int errorNum, char *msg); |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
120 |
|
2 | 121 |
void NET_ThrowCurrent(JNIEnv *env, char *msg); |
122 |
||
123 |
jfieldID NET_GetFileDescriptorID(JNIEnv *env); |
|
124 |
||
54627
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
53422
diff
changeset
|
125 |
JNIEXPORT jint JNICALL ipv4_available(); |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
126 |
JNIEXPORT jint JNICALL ipv6_available(); |
2 | 127 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
128 |
JNIEXPORT jint JNICALL reuseport_available(); |
36115 | 129 |
|
43100 | 130 |
/** |
131 |
* This function will fill a SOCKETADDRESS structure from an InetAddress |
|
132 |
* object. |
|
133 |
* |
|
134 |
* The parameter 'sa' must point to valid storage of size |
|
135 |
* 'sizeof(SOCKETADDRESS)'. |
|
136 |
* |
|
137 |
* The parameter 'len' is a pointer to an int and is used for returning |
|
138 |
* the actual sockaddr length, e.g. 'sizeof(struct sockaddr_in)' or |
|
139 |
* 'sizeof(struct sockaddr_in6)'. |
|
140 |
* |
|
141 |
* If the type of the InetAddress object is IPv6, the function will fill a |
|
142 |
* sockaddr_in6 structure. IPv6 must be available in that case, otherwise an |
|
143 |
* exception is thrown. |
|
144 |
* In the case of an IPv4 InetAddress, when IPv6 is available and |
|
145 |
* v4MappedAddress is TRUE, this method will fill a sockaddr_in6 structure |
|
146 |
* containing an IPv4 mapped IPv6 address. Otherwise a sockaddr_in |
|
147 |
* structure will be filled. |
|
148 |
*/ |
|
2 | 149 |
JNIEXPORT int JNICALL |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
150 |
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, |
43100 | 151 |
SOCKETADDRESS *sa, int *len, |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
152 |
jboolean v4MappedAddress); |
2 | 153 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
154 |
JNIEXPORT jobject JNICALL |
43100 | 155 |
NET_SockaddrToInetAddress(JNIEnv *env, SOCKETADDRESS *sa, int *port); |
2 | 156 |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20821
diff
changeset
|
157 |
void platformInit(); |
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
158 |
|
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
5506
diff
changeset
|
159 |
void parseExclusiveBindProperty(JNIEnv *env); |
2 | 160 |
|
43100 | 161 |
JNIEXPORT jint JNICALL NET_GetPortFromSockaddr(SOCKETADDRESS *sa); |
2 | 162 |
|
43100 | 163 |
JNIEXPORT jboolean JNICALL |
164 |
NET_SockaddrEqualsInetAddress(JNIEnv *env, SOCKETADDRESS *sa, jobject iaObj); |
|
2 | 165 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
166 |
int NET_IsIPv4Mapped(jbyte* caddr); |
2 | 167 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
168 |
int NET_IPv4MappedToIPv4(jbyte* caddr); |
2 | 169 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
170 |
int NET_IsEqual(jbyte* caddr1, jbyte* caddr2); |
2 | 171 |
|
41771
18c9669e76ca
8167481: cleanup of headers and includes for native libnet
clanger
parents:
41380
diff
changeset
|
172 |
int NET_IsZeroAddr(jbyte* caddr); |
12688
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
5506
diff
changeset
|
173 |
|
2 | 174 |
/* Socket operations |
175 |
* |
|
23015
73b21ab36615
8034174: Remove use of JVM_* functions from java.net code
chegar
parents:
23010
diff
changeset
|
176 |
* These work just like the system calls, except that they may do some |
2 | 177 |
* platform-specific pre/post processing of the arguments and/or results. |
178 |
*/ |
|
179 |
||
180 |
JNIEXPORT int JNICALL |
|
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
181 |
NET_SocketAvailable(int fd, int *pbytes); |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
182 |
|
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
183 |
JNIEXPORT int JNICALL |
2 | 184 |
NET_GetSockOpt(int fd, int level, int opt, void *result, int *len); |
185 |
||
186 |
JNIEXPORT int JNICALL |
|
187 |
NET_SetSockOpt(int fd, int level, int opt, const void *arg, int len); |
|
188 |
||
189 |
JNIEXPORT int JNICALL |
|
43100 | 190 |
NET_Bind(int fd, SOCKETADDRESS *sa, int len); |
2 | 191 |
|
192 |
JNIEXPORT int JNICALL |
|
193 |
NET_MapSocketOption(jint cmd, int *level, int *optname); |
|
194 |
||
195 |
JNIEXPORT int JNICALL |
|
196 |
NET_MapSocketOptionV6(jint cmd, int *level, int *optname); |
|
197 |
||
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
198 |
JNIEXPORT jint JNICALL |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
199 |
NET_EnableFastTcpLoopback(int fd); |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
200 |
|
2 | 201 |
unsigned short in_cksum(unsigned short *addr, int len); |
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
25859
diff
changeset
|
202 |
|
52073
1c8745e31fa3
8212000: Verify exported symbols in java.base (libnet, libnio/ch)
prappo
parents:
49440
diff
changeset
|
203 |
jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout); |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
204 |
|
2 | 205 |
#endif /* NET_UTILS_H */ |