Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/java/net/net_util.h
38829 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#ifndef NET_UTILS_H26#define NET_UTILS_H2728#include "jvm.h"29#include "jni_util.h"30#include "net_util_md.h"3132/************************************************************************33* Macros and misc constants34*/3536#define MAX_PACKET_LEN 655363738#define IPv4 139#define IPv6 24041#define NET_ERROR(env, ex, msg) \42{ if (!(*env)->ExceptionOccurred(env)) JNU_ThrowByName(env, ex, msg); }4344/************************************************************************45* Cached field IDs46*47* The naming convention for field IDs is48* <class abbrv>_<fieldName>ID49* i.e. psi_timeoutID is PlainSocketImpl's timeout field's ID.50*/51extern jclass ia_class;52extern jfieldID iac_addressID;53extern jfieldID iac_familyID;54extern jfieldID iac_hostNameID;55extern jfieldID iac_origHostNameID;56extern jfieldID ia_preferIPv6AddressID;5758JNIEXPORT void JNICALL initInetAddressIDs(JNIEnv *env);5960/** (Inet6Address accessors)61* set_ methods return JNI_TRUE on success JNI_FALSE on error62* get_ methods that return int/boolean, return -1 on error63* get_ methods that return objects return NULL on error.64*/65extern jobject getInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj);66extern int setInet6Address_scopeifname(JNIEnv *env, jobject ia6Obj, jobject scopeifname);67extern int getInet6Address_scopeid_set(JNIEnv *env, jobject ia6Obj);68extern int getInet6Address_scopeid(JNIEnv *env, jobject ia6Obj);69extern int setInet6Address_scopeid(JNIEnv *env, jobject ia6Obj, int scopeid);70extern int getInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *dest);71extern int setInet6Address_ipaddress(JNIEnv *env, jobject ia6Obj, char *address);7273extern void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address);74extern void setInetAddress_family(JNIEnv *env, jobject iaObj, int family);75extern void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject h);76extern int getInetAddress_addr(JNIEnv *env, jobject iaObj);77extern int getInetAddress_family(JNIEnv *env, jobject iaObj);78extern jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj);7980extern jclass ia4_class;81extern jmethodID ia4_ctrID;8283/* NetworkInterface fields */84extern jclass ni_class;85extern jfieldID ni_nameID;86extern jfieldID ni_indexID;87extern jfieldID ni_addrsID;88extern jfieldID ni_descID;89extern jmethodID ni_ctrID;9091/* PlainSocketImpl fields */92extern jfieldID psi_timeoutID;93extern jfieldID psi_fdID;94extern jfieldID psi_addressID;95extern jfieldID psi_portID;96extern jfieldID psi_localportID;9798/* DatagramPacket fields */99extern jfieldID dp_addressID;100extern jfieldID dp_portID;101extern jfieldID dp_bufID;102extern jfieldID dp_offsetID;103extern jfieldID dp_lengthID;104extern jfieldID dp_bufLengthID;105106/* Inet6Address fields */107extern jclass ia6_class;108extern jfieldID ia6_holder6ID;109extern jfieldID ia6_ipaddressID;110extern jfieldID ia6_scopeidID;111extern jfieldID ia6_cachedscopeidID;112extern jfieldID ia6_scopeidsetID;113extern jfieldID ia6_scopeifnameID;114extern jmethodID ia6_ctrID;115116/************************************************************************117* Utilities118*/119JNIEXPORT void JNICALL Java_java_net_InetAddress_init(JNIEnv *env, jclass cls);120JNIEXPORT void JNICALL Java_java_net_Inet4Address_init(JNIEnv *env, jclass cls);121JNIEXPORT void JNICALL Java_java_net_Inet6Address_init(JNIEnv *env, jclass cls);122JNIEXPORT void JNICALL Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls);123124JNIEXPORT void JNICALL NET_ThrowNew(JNIEnv *env, int errorNum, char *msg);125int NET_GetError();126127void NET_ThrowCurrent(JNIEnv *env, char *msg);128129jfieldID NET_GetFileDescriptorID(JNIEnv *env);130131JNIEXPORT jint JNICALL ipv6_available() ;132133void134NET_AllocSockaddr(struct sockaddr **him, int *len);135136JNIEXPORT int JNICALL137NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him, int *len, jboolean v4MappedAddress);138139JNIEXPORT jobject JNICALL140NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port);141142void platformInit();143void parseExclusiveBindProperty(JNIEnv *env);144145void146NET_SetTrafficClass(struct sockaddr *him, int trafficClass);147148JNIEXPORT jint JNICALL149NET_GetPortFromSockaddr(struct sockaddr *him);150151JNIEXPORT jint JNICALL152NET_SockaddrEqualsInetAddress(JNIEnv *env,struct sockaddr *him, jobject iaObj);153154int155NET_IsIPv4Mapped(jbyte* caddr);156157int158NET_IPv4MappedToIPv4(jbyte* caddr);159160int161NET_IsEqual(jbyte* caddr1, jbyte* caddr2);162163int164NET_IsZeroAddr(jbyte* caddr);165166/* Socket operations167*168* These work just like the JVM_* procedures, except that they may do some169* platform-specific pre/post processing of the arguments and/or results.170*/171172JNIEXPORT int JNICALL173NET_GetSockOpt(int fd, int level, int opt, void *result, int *len);174175JNIEXPORT int JNICALL176NET_SetSockOpt(int fd, int level, int opt, const void *arg, int len);177178JNIEXPORT int JNICALL179NET_Bind(int fd, struct sockaddr *him, int len);180181JNIEXPORT int JNICALL182NET_MapSocketOption(jint cmd, int *level, int *optname);183184JNIEXPORT int JNICALL185NET_MapSocketOptionV6(jint cmd, int *level, int *optname);186187JNIEXPORT jint JNICALL188NET_EnableFastTcpLoopback(int fd);189190int getScopeID (struct sockaddr *);191192int cmpScopeID (unsigned int, struct sockaddr *);193194unsigned short in_cksum(unsigned short *addr, int len);195196#endif /* NET_UTILS_H */197198199