1 /* 2 * Copyright (c) 1997, 2012, 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_RecvFrom(int s, void *buf, int len, unsigned int flags, 40 struct sockaddr *from, socklen_t *fromlen); 41 int NET_ReadV(int s, const struct iovec * vector, int count); 42 int NET_Send(int s, void *msg, int len, unsigned int flags); 43 int NET_SendTo(int s, const void *msg, int len, unsigned int 44 flags, const struct sockaddr *to, int tolen); 45 int NET_Writev(int s, const struct iovec * vector, int count); 46 int NET_Connect(int s, struct sockaddr *addr, int addrlen); 47 int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen); 48 int NET_SocketClose(int s); 49 int NET_Dup2(int oldfd, int newfd); 50 int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout); 51 int NET_SocketAvailable(int s, jint *pbytes); 52 53 void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env, 54 const char* hostname, 55 int gai_error); 56 void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name, 57 const char *defaultDetail); 58 59 #define NET_WAIT_READ 0x01 60 #define NET_WAIT_WRITE 0x02 61 #define NET_WAIT_CONNECT 0x04 62 63 jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout); 64 65 /************************************************************************ 66 * Macros and constants 67 */ 68 69 /* 70 * On 64-bit JDKs we use a much larger stack and heap buffer. 71 */ 72 #ifdef _LP64 73 #define MAX_BUFFER_LEN 65536 74 #define MAX_HEAP_BUFFER_LEN 131072 75 #else 76 #define MAX_BUFFER_LEN 8192 77 #define MAX_HEAP_BUFFER_LEN 65536 78 #endif 79 80 #ifdef AF_INET6 81 82 #define SOCKADDR union { \ 83 struct sockaddr_in him4; \ 84 struct sockaddr_in6 him6; \ 85 } 86 87 #define SOCKADDR_LEN (ipv6_available() ? sizeof(SOCKADDR) : \ 88 sizeof(struct sockaddr_in)) 89 90 #else 91 92 #define SOCKADDR union { struct sockaddr_in him4; } 93 #define SOCKADDR_LEN sizeof(SOCKADDR) 94 95 #endif 96 97 /************************************************************************ 98 * Utilities 99 */ 100 101 #ifdef __linux__ 102 int kernelIsV24(); 103 #ifdef AF_INET6 104 int getDefaultIPv6Interface(struct in6_addr *target_addr); 105 #endif 106 #endif 107 108 #ifdef __solaris__ 109 int net_getParam(char *driver, char *param); 110 111 #ifndef SO_FLOW_SLA 112 #define SO_FLOW_SLA 0x1018 113 114 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 115 #pragma pack(4) 116 #endif 117 118 /* 119 * Used with the setsockopt(SO_FLOW_SLA, ...) call to set 120 * per socket service level properties. 121 * When the application uses per-socket API, we will enforce the properties 122 * on both outbound and inbound packets. 123 * 124 * For now, only priority and maxbw are supported in SOCK_FLOW_PROP_VERSION1. 125 */ 126 typedef struct sock_flow_props_s { 127 int sfp_version; 128 uint32_t sfp_mask; 129 int sfp_priority; /* flow priority */ 130 uint64_t sfp_maxbw; /* bandwidth limit in bps */ 131 int sfp_status; /* flow create status for getsockopt */ 132 } sock_flow_props_t; 133 134 #define SOCK_FLOW_PROP_VERSION1 1 135 136 /* bit mask values for sfp_mask */ 137 #define SFP_MAXBW 0x00000001 /* Flow Bandwidth Limit */ 138 #define SFP_PRIORITY 0x00000008 /* Flow priority */ 139 140 /* possible values for sfp_priority */ 141 #define SFP_PRIO_NORMAL 1 142 #define SFP_PRIO_HIGH 2 143 144 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 145 #pragma pack() 146 #endif /* _LONG_LONG_ALIGNMENT */ 147 148 #endif /* SO_FLOW_SLA */ 149 #endif /* __solaris__ */ 150 151 JNIEXPORT jboolean JNICALL NET_IsFlowSupported(); 152 153 #endif /* NET_UTILS_MD_H */