1 /*
2 * Copyright (c) 1998, 2013, 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
179 dbgsysNetworkToHostLong(uint32_t netlong) {
180 return ntohl(netlong);
181 }
182
183
184 int
185 dbgsysSetSocketOption(int fd, jint cmd, jboolean on, jvalue value)
186 {
187 if (cmd == TCP_NODELAY) {
188 struct protoent *proto = getprotobyname("TCP");
189 int tcp_level = (proto == 0 ? IPPROTO_TCP: proto->p_proto);
190 uint32_t onl = (uint32_t)on;
191
192 if (setsockopt(fd, tcp_level, TCP_NODELAY,
193 (char *)&onl, sizeof(uint32_t)) < 0) {
194 return SYS_ERR;
195 }
196 } else if (cmd == SO_LINGER) {
197 struct linger arg;
198 arg.l_onoff = on;
199
200 if(on) {
201 arg.l_linger = (unsigned short)value.i;
202 if(setsockopt(fd, SOL_SOCKET, SO_LINGER,
203 (char*)&arg, sizeof(arg)) < 0) {
204 return SYS_ERR;
205 }
206 } else {
207 if (setsockopt(fd, SOL_SOCKET, SO_LINGER,
208 (char*)&arg, sizeof(arg)) < 0) {
209 return SYS_ERR;
210 }
211 }
212 } else if (cmd == SO_SNDBUF) {
213 jint buflen = value.i;
214 if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
215 (char *)&buflen, sizeof(buflen)) < 0) {
216 return SYS_ERR;
217 }
218 } else if (cmd == SO_REUSEADDR) {
219 int oni = (int)on;
220 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
221 (char *)&oni, sizeof(oni)) < 0) {
222 return SYS_ERR;
223
224 }
225 } else {
226 return SYS_ERR;
227 }
228 return SYS_OK;
229 }
230
|
1 /*
2 * Copyright (c) 1998, 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
179 dbgsysNetworkToHostLong(uint32_t netlong) {
180 return ntohl(netlong);
181 }
182
183
184 int
185 dbgsysSetSocketOption(int fd, jint cmd, jboolean on, jvalue value)
186 {
187 if (cmd == TCP_NODELAY) {
188 struct protoent *proto = getprotobyname("TCP");
189 int tcp_level = (proto == 0 ? IPPROTO_TCP: proto->p_proto);
190 uint32_t onl = (uint32_t)on;
191
192 if (setsockopt(fd, tcp_level, TCP_NODELAY,
193 (char *)&onl, sizeof(uint32_t)) < 0) {
194 return SYS_ERR;
195 }
196 } else if (cmd == SO_LINGER) {
197 struct linger arg;
198 arg.l_onoff = on;
199 arg.l_linger = (on) ? (unsigned short)value.i : 0;
200 if (setsockopt(fd, SOL_SOCKET, SO_LINGER,
201 (char*)&arg, sizeof(arg)) < 0) {
202 return SYS_ERR;
203 }
204 } else if (cmd == SO_SNDBUF) {
205 jint buflen = value.i;
206 if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
207 (char *)&buflen, sizeof(buflen)) < 0) {
208 return SYS_ERR;
209 }
210 } else if (cmd == SO_REUSEADDR) {
211 int oni = (int)on;
212 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
213 (char *)&oni, sizeof(oni)) < 0) {
214 return SYS_ERR;
215
216 }
217 } else {
218 return SYS_ERR;
219 }
220 return SYS_OK;
221 }
222
|