1/* 2 * Copyright (c) 1997, 2017, 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 26#ifndef NET_UTILS_MD_H 27#define NET_UTILS_MD_H 28 29#include <netdb.h> 30#include <poll.h> 31#include <sys/socket.h> 32 33/************************************************************************ 34 * Macros and constants 35 */ 36 37#define NET_NSEC_PER_MSEC 1000000 38#define NET_NSEC_PER_SEC 1000000000 39#define NET_NSEC_PER_USEC 1000 40 41/* Defines SO_REUSEPORT */ 42#ifndef SO_REUSEPORT 43#ifdef __linux__ 44#define SO_REUSEPORT 15 45#elif __solaris__ 46#define SO_REUSEPORT 0x100e 47#elif defined(AIX) || defined(MACOSX) 48#define SO_REUSEPORT 0x0200 49#else 50#define SO_REUSEPORT 0 51#endif 52#endif 53 54/* 55 * On 64-bit JDKs we use a much larger stack and heap buffer. 56 */ 57#ifdef _LP64 58#define MAX_BUFFER_LEN 65536 59#define MAX_HEAP_BUFFER_LEN 131072 60#else 61#define MAX_BUFFER_LEN 8192 62#define MAX_HEAP_BUFFER_LEN 65536 63#endif 64 65typedef union { 66 struct sockaddr sa; 67 struct sockaddr_in sa4; 68 struct sockaddr_in6 sa6; 69} SOCKETADDRESS; 70 71/************************************************************************ 72 * Functions 73 */ 74 75int NET_Timeout(JNIEnv *env, int s, long timeout, jlong nanoTimeStamp); 76int NET_Read(int s, void* buf, size_t len); 77int NET_NonBlockingRead(int s, void* buf, size_t len); 78int NET_RecvFrom(int s, void *buf, int len, unsigned int flags, 79 struct sockaddr *from, socklen_t *fromlen); 80int NET_ReadV(int s, const struct iovec * vector, int count); 81int NET_Send(int s, void *msg, int len, unsigned int flags); 82int NET_SendTo(int s, const void *msg, int len, unsigned int 83 flags, const struct sockaddr *to, int tolen); 84int NET_Writev(int s, const struct iovec * vector, int count); 85int NET_Connect(int s, struct sockaddr *addr, int addrlen); 86int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen); 87int NET_SocketClose(int s); 88int NET_Dup2(int oldfd, int newfd); 89int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout); 90int NET_SocketAvailable(int s, jint *pbytes); 91 92void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env, 93 const char* hostname, 94 int gai_error); 95void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name, 96 const char *defaultDetail); 97void NET_SetTrafficClass(SOCKETADDRESS *sa, int trafficClass); 98 99#ifdef __linux__ 100int kernelIsV24(); 101int getDefaultIPv6Interface(struct in6_addr *target_addr); 102#endif 103 104#ifdef __solaris__ 105int net_getParam(char *driver, char *param); 106#endif 107 108#endif /* NET_UTILS_MD_H */ 109