comparison src/solaris/native/sun/net/spi/SdpProvider.c @ 1040:93d1fbe001b8

4890703: Support SDP (sol) Reviewed-by: michaelm
author alanb
date Mon, 06 Apr 2009 08:59:33 +0100
parents
children 8df0ffac7f4d
comparison
equal deleted inserted replaced
-1:000000000000 0:67af429d0131
1 /*
2 * Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 #include <sys/types.h>
27 #include <sys/socket.h>
28
29 #if defined(__solaris__) && !defined(PROTO_SDP)
30 #define PROTO_SDP 257
31 #endif
32
33 #include "jni.h"
34 #include "jni_util.h"
35 #include "net_util.h"
36
37 #define RESTARTABLE(_cmd, _result) do { \
38 do { \
39 _result = _cmd; \
40 } while((_result == -1) && (errno == EINTR)); \
41 } while(0)
42
43 JNIEXPORT void JNICALL
44 Java_sun_net_spi_SdpProvider_convert(JNIEnv *env, jclass cls, jint fd)
45 {
46 #ifdef PROTO_SDP
47 int domain = ipv6_available() ? AF_INET6 : AF_INET;
48 int s = socket(domain, SOCK_STREAM, PROTO_SDP);
49 if (s < 0) {
50 JNU_ThrowIOExceptionWithLastError(env, "socket");
51 } else {
52 int arg, len, res;
53 struct linger linger;
54
55 /* copy socket options that are relevant to SDP */
56 len = sizeof(arg);
57 if (getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, &len) == 0)
58 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, len);
59 len = sizeof(arg);
60 if (getsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char*)&arg, &len) == 0)
61 setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char*)&arg, len);
62 len = sizeof(linger);
63 if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (void*)&linger, &len) == 0)
64 setsockopt(s, SOL_SOCKET, SO_LINGER, (char*)&linger, len);
65
66 RESTARTABLE(dup2(s, fd), res);
67 if (res < 0)
68 JNU_ThrowIOExceptionWithLastError(env, "dup2");
69 RESTARTABLE(close(s), res);
70 }
71 #else
72 JNU_ThrowInternalError(env, "should not reach here");
73 #endif
74 }