author | michaelm |
Thu, 18 Jul 2013 18:52:14 +0100 | |
changeset 20821 | e0d0a585aa49 |
parent 16870 | f35b2bd19761 |
child 22597 | 7515a991bb37 |
child 22258 | db80f864ed8f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, 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 |
||
39 |
#define IPv4 1 |
|
40 |
#define IPv6 2 |
|
41 |
||
42 |
#define NET_ERROR(env, ex, msg) \ |
|
43 |
{ if (!(*env)->ExceptionOccurred(env)) JNU_ThrowByName(env, ex, msg) } |
|
44 |
||
45 |
#define CHECK_NULL(x) if ((x) == NULL) return; |
|
46 |
#define CHECK_NULL_RETURN(x, y) if ((x) == NULL) return y; |
|
47 |
||
48 |
/************************************************************************ |
|
49 |
* Cached field IDs |
|
50 |
* |
|
51 |
* The naming convention for field IDs is |
|
52 |
* <class abbrv>_<fieldName>ID |
|
53 |
* i.e. psi_timeoutID is PlainSocketImpl's timeout field's ID. |
|
54 |
*/ |
|
55 |
extern jclass ia_class; |
|
16870 | 56 |
extern jfieldID iac_addressID; |
57 |
extern jfieldID iac_familyID; |
|
58 |
extern jfieldID iac_hostNameID; |
|
2 | 59 |
extern jfieldID ia_preferIPv6AddressID; |
60 |
||
20821 | 61 |
/** (Inet6Address accessors) |
62 |
* set_ methods return JNI_TRUE on success JNI_FALSE on error |
|
63 |
* get_ methods that return int/boolean, return -1 on error |
|
64 |
* get_ methods that return objects return NULL on error. |
|
65 |
*/ |
|
66 |
extern jobject getInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj); |
|
67 |
extern int setInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj, jobject scopeifname); |
|
68 |
extern int getInet6Address_scopeid_set(JNIEnv *env, jobject ia6Obj); |
|
69 |
extern int getInet6Address_scopeid(JNIEnv *env, jobject ia6Obj); |
|
70 |
extern int setInet6Address_scopeid(JNIEnv *env, jobject ia6Obj, int scopeid); |
|
71 |
extern int getInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *dest); |
|
72 |
extern int setInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *address); |
|
73 |
||
16870 | 74 |
extern void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address); |
75 |
extern void setInetAddress_family(JNIEnv *env, jobject iaObj, int family); |
|
76 |
extern void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject h); |
|
77 |
extern int getInetAddress_addr(JNIEnv *env, jobject iaObj); |
|
78 |
extern int getInetAddress_family(JNIEnv *env, jobject iaObj); |
|
79 |
extern jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj); |
|
80 |
||
2 | 81 |
extern jclass ia4_class; |
82 |
extern jmethodID ia4_ctrID; |
|
83 |
||
84 |
/* NetworkInterface fields */ |
|
85 |
extern jclass ni_class; |
|
86 |
extern jfieldID ni_nameID; |
|
87 |
extern jfieldID ni_indexID; |
|
88 |
extern jfieldID ni_addrsID; |
|
89 |
extern jfieldID ni_descID; |
|
90 |
extern jmethodID ni_ctrID; |
|
91 |
||
92 |
/* PlainSocketImpl fields */ |
|
93 |
extern jfieldID psi_timeoutID; |
|
94 |
extern jfieldID psi_fdID; |
|
95 |
extern jfieldID psi_addressID; |
|
96 |
extern jfieldID psi_portID; |
|
97 |
extern jfieldID psi_localportID; |
|
98 |
||
99 |
/* DatagramPacket fields */ |
|
100 |
extern jfieldID dp_addressID; |
|
101 |
extern jfieldID dp_portID; |
|
102 |
extern jfieldID dp_bufID; |
|
103 |
extern jfieldID dp_offsetID; |
|
104 |
extern jfieldID dp_lengthID; |
|
105 |
extern jfieldID dp_bufLengthID; |
|
106 |
||
107 |
/* Inet6Address fields */ |
|
108 |
extern jclass ia6_class; |
|
20821 | 109 |
extern jfieldID ia6_holder6ID; |
2 | 110 |
extern jfieldID ia6_ipaddressID; |
111 |
extern jfieldID ia6_scopeidID; |
|
112 |
extern jfieldID ia6_cachedscopeidID; |
|
113 |
extern jfieldID ia6_scopeidsetID; |
|
114 |
extern jfieldID ia6_scopeifnameID; |
|
115 |
extern jmethodID ia6_ctrID; |
|
116 |
||
117 |
/************************************************************************ |
|
118 |
* Utilities |
|
119 |
*/ |
|
120 |
JNIEXPORT void JNICALL Java_java_net_InetAddress_init(JNIEnv *env, jclass cls); |
|
121 |
JNIEXPORT void JNICALL Java_java_net_Inet4Address_init(JNIEnv *env, jclass cls); |
|
122 |
JNIEXPORT void JNICALL Java_java_net_Inet6Address_init(JNIEnv *env, jclass cls); |
|
123 |
JNIEXPORT void JNICALL Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls); |
|
124 |
||
125 |
JNIEXPORT void JNICALL NET_ThrowNew(JNIEnv *env, int errorNum, char *msg); |
|
126 |
int NET_GetError(); |
|
127 |
||
128 |
void NET_ThrowCurrent(JNIEnv *env, char *msg); |
|
129 |
||
130 |
jfieldID NET_GetFileDescriptorID(JNIEnv *env); |
|
131 |
||
132 |
JNIEXPORT jint JNICALL ipv6_available() ; |
|
133 |
||
134 |
void |
|
135 |
NET_AllocSockaddr(struct sockaddr **him, int *len); |
|
136 |
||
137 |
JNIEXPORT int JNICALL |
|
138 |
NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him, int *len, jboolean v4MappedAddress); |
|
139 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
140 |
JNIEXPORT jobject JNICALL |
2 | 141 |
NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port); |
142 |
||
143 |
void initLocalAddrTable (); |
|
13043
10fa4f21ea0f
7123896: Unexpected behavior due to Solaris using separate IPv4 and IPv6 port spaces
coffeys
parents:
5506
diff
changeset
|
144 |
void parseExclusiveBindProperty(JNIEnv *env); |
2 | 145 |
|
146 |
void |
|
147 |
NET_SetTrafficClass(struct sockaddr *him, int trafficClass); |
|
148 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
149 |
JNIEXPORT jint JNICALL |
2 | 150 |
NET_GetPortFromSockaddr(struct sockaddr *him); |
151 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
152 |
JNIEXPORT jint JNICALL |
2 | 153 |
NET_SockaddrEqualsInetAddress(JNIEnv *env,struct sockaddr *him, jobject iaObj); |
154 |
||
155 |
int |
|
156 |
NET_IsIPv4Mapped(jbyte* caddr); |
|
157 |
||
158 |
int |
|
159 |
NET_IPv4MappedToIPv4(jbyte* caddr); |
|
160 |
||
161 |
int |
|
162 |
NET_IsEqual(jbyte* caddr1, jbyte* caddr2); |
|
163 |
||
12688
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
5506
diff
changeset
|
164 |
int |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
5506
diff
changeset
|
165 |
NET_IsZeroAddr(jbyte* caddr); |
f15fd32c975e
7163874: InetAddress.isReachable should support pinging 0.0.0.0
youdwei
parents:
5506
diff
changeset
|
166 |
|
2 | 167 |
/* Socket operations |
168 |
* |
|
169 |
* These work just like the JVM_* procedures, except that they may do some |
|
170 |
* platform-specific pre/post processing of the arguments and/or results. |
|
171 |
*/ |
|
172 |
||
173 |
JNIEXPORT int JNICALL |
|
174 |
NET_GetSockOpt(int fd, int level, int opt, void *result, int *len); |
|
175 |
||
176 |
JNIEXPORT int JNICALL |
|
177 |
NET_SetSockOpt(int fd, int level, int opt, const void *arg, int len); |
|
178 |
||
179 |
JNIEXPORT int JNICALL |
|
180 |
NET_Bind(int fd, struct sockaddr *him, int len); |
|
181 |
||
182 |
JNIEXPORT int JNICALL |
|
183 |
NET_MapSocketOption(jint cmd, int *level, int *optname); |
|
184 |
||
185 |
JNIEXPORT int JNICALL |
|
186 |
NET_MapSocketOptionV6(jint cmd, int *level, int *optname); |
|
187 |
||
188 |
int getScopeID (struct sockaddr *); |
|
189 |
||
190 |
int cmpScopeID (unsigned int, struct sockaddr *); |
|
191 |
||
192 |
unsigned short in_cksum(unsigned short *addr, int len); |
|
193 |
#endif /* NET_UTILS_H */ |