1 /* 2 * Copyright (c) 1997, 2016, 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 <sys/socket.h> 30 #include <sys/types.h> 31 #include <netdb.h> 32 #include <netinet/in.h> 33 #include <unistd.h> 34 35 #include <sys/poll.h> 36 37 int NET_Timeout(int s, long timeout); 38 int NET_Read(int s, void* buf, size_t len); 39 int NET_NonBlockingRead(int s, void* buf, size_t len); 40 int NET_TimeoutWithCurrentTime(int s, long timeout, long currentTime); 41 int NET_RecvFrom(int s, void *buf, int len, unsigned int flags, 42 struct sockaddr *from, socklen_t *fromlen); 43 int NET_ReadV(int s, const struct iovec * vector, int count); 44 int NET_Send(int s, void *msg, int len, unsigned int flags); 45 int NET_SendTo(int s, const void *msg, int len, unsigned int 46 flags, const struct sockaddr *to, int tolen); 47 int NET_Writev(int s, const struct iovec * vector, int count); 48 int NET_Connect(int s, struct sockaddr *addr, int addrlen); 49 int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen); 50 int NET_SocketClose(int s); 51 int NET_Dup2(int oldfd, int newfd); 52 int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout); 53 int NET_SocketAvailable(int s, jint *pbytes); 54 55 void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env, 56 const char* hostname, 57 int gai_error); 58 void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name, 59 const char *defaultDetail); 60 61 #define NET_WAIT_READ 0x01 62 #define NET_WAIT_WRITE 0x02 63 #define NET_WAIT_CONNECT 0x04 64 65 /* Defines SO_REUSEPORT */ 66 #ifndef SO_REUSEPORT 67 #ifdef __linux__ 68 #define SO_REUSEPORT 15 69 #elif __solaris__ 70 #define SO_REUSEPORT 0x100e 71 #elif defined(AIX) || defined(MACOSX) 72 #define SO_REUSEPORT 0x0200 73 #else 74 #define SO_REUSEPORT 0 75 #endif 76 #endif 77 78 jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout); 79 80 /************************************************************************ 81 * Macros and constants 82 */ 83 84 /* 85 * On 64-bit JDKs we use a much larger stack and heap buffer. 86 */ 87 #ifdef _LP64 88 #define MAX_BUFFER_LEN 65536 89 #define MAX_HEAP_BUFFER_LEN 131072 90 #else 91 #define MAX_BUFFER_LEN 8192 92 #define MAX_HEAP_BUFFER_LEN 65536 93 #endif 94 95 #ifdef AF_INET6 96 97 #define SOCKADDR union { \ 98 struct sockaddr_in him4; \ 99 struct sockaddr_in6 him6; \ 100 } 101 102 #define SOCKADDR_LEN (ipv6_available() ? sizeof(SOCKADDR) : \ 103 sizeof(struct sockaddr_in)) 104 105 #else 106 107 #define SOCKADDR union { struct sockaddr_in him4; } 108 #define SOCKADDR_LEN sizeof(SOCKADDR) 109 110 #endif 111 112 /************************************************************************ 113 * Utilities 114 */ 115 116 #ifdef __linux__ 117 int kernelIsV24(); 118 #ifdef AF_INET6 119 int getDefaultIPv6Interface(struct in6_addr *target_addr); 120 #endif 121 #endif 122 123 #ifdef __solaris__ 124 int net_getParam(char *driver, char *param); 125 #endif 126 127 #endif /* NET_UTILS_MD_H */