annotate 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
rev   line source
alanb@1040 1 /*
alanb@1040 2 * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
alanb@1040 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
alanb@1040 4 *
alanb@1040 5 * This code is free software; you can redistribute it and/or modify it
alanb@1040 6 * under the terms of the GNU General Public License version 2 only, as
alanb@1040 7 * published by the Free Software Foundation. Sun designates this
alanb@1040 8 * particular file as subject to the "Classpath" exception as provided
alanb@1040 9 * by Sun in the LICENSE file that accompanied this code.
alanb@1040 10 *
alanb@1040 11 * This code is distributed in the hope that it will be useful, but WITHOUT
alanb@1040 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
alanb@1040 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
alanb@1040 14 * version 2 for more details (a copy is included in the LICENSE file that
alanb@1040 15 * accompanied this code).
alanb@1040 16 *
alanb@1040 17 * You should have received a copy of the GNU General Public License version
alanb@1040 18 * 2 along with this work; if not, write to the Free Software Foundation,
alanb@1040 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
alanb@1040 20 *
alanb@1040 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
alanb@1040 22 * CA 95054 USA or visit www.sun.com if you need additional information or
alanb@1040 23 * have any questions.
alanb@1040 24 */
alanb@1040 25
alanb@1040 26 #include <sys/types.h>
alanb@1040 27 #include <sys/socket.h>
alanb@1040 28
alanb@1040 29 #if defined(__solaris__) && !defined(PROTO_SDP)
alanb@1040 30 #define PROTO_SDP 257
alanb@1040 31 #endif
alanb@1040 32
alanb@1040 33 #include "jni.h"
alanb@1040 34 #include "jni_util.h"
alanb@1040 35 #include "net_util.h"
alanb@1040 36
alanb@1040 37 #define RESTARTABLE(_cmd, _result) do { \
alanb@1040 38 do { \
alanb@1040 39 _result = _cmd; \
alanb@1040 40 } while((_result == -1) && (errno == EINTR)); \
alanb@1040 41 } while(0)
alanb@1040 42
alanb@1040 43 JNIEXPORT void JNICALL
alanb@1040 44 Java_sun_net_spi_SdpProvider_convert(JNIEnv *env, jclass cls, jint fd)
alanb@1040 45 {
alanb@1040 46 #ifdef PROTO_SDP
alanb@1040 47 int domain = ipv6_available() ? AF_INET6 : AF_INET;
alanb@1040 48 int s = socket(domain, SOCK_STREAM, PROTO_SDP);
alanb@1040 49 if (s < 0) {
alanb@1040 50 JNU_ThrowIOExceptionWithLastError(env, "socket");
alanb@1040 51 } else {
alanb@1040 52 int arg, len, res;
alanb@1040 53 struct linger linger;
alanb@1040 54
alanb@1040 55 /* copy socket options that are relevant to SDP */
alanb@1040 56 len = sizeof(arg);
alanb@1040 57 if (getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, &len) == 0)
alanb@1040 58 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, len);
alanb@1040 59 len = sizeof(arg);
alanb@1040 60 if (getsockopt(fd, SOL_SOCKET, SO_OOBINLINE, (char*)&arg, &len) == 0)
alanb@1040 61 setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char*)&arg, len);
alanb@1040 62 len = sizeof(linger);
alanb@1040 63 if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (void*)&linger, &len) == 0)
alanb@1040 64 setsockopt(s, SOL_SOCKET, SO_LINGER, (char*)&linger, len);
alanb@1040 65
alanb@1040 66 RESTARTABLE(dup2(s, fd), res);
alanb@1040 67 if (res < 0)
alanb@1040 68 JNU_ThrowIOExceptionWithLastError(env, "dup2");
alanb@1040 69 RESTARTABLE(close(s), res);
alanb@1040 70 }
alanb@1040 71 #else
alanb@1040 72 JNU_ThrowInternalError(env, "should not reach here");
alanb@1040 73 #endif
alanb@1040 74 }