jdk/src/jdk.sctp/unix/native/libsctp/SctpNet.c
author msheppar
Wed, 25 Feb 2015 19:36:29 +0000
changeset 29118 8782a8e91d4c
parent 28680 79674c06a625
child 33653 c1ee09fe3274
permissions -rw-r--r--
8046901: Check jdk/src/solaris/native/sun/nio for Parfait flagged uninitialized memory Reviewed-by: rriggs, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 11823
diff changeset
     2
 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     4
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    10
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    15
 * accompanied this code).
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    16
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    23
 * questions.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    24
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    25
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    26
#include <stdlib.h>
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    27
#include <string.h>
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    28
#include <dlfcn.h>
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    29
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    30
#include "Sctp.h"
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    31
#include "jni.h"
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    32
#include "jni_util.h"
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    33
#include "nio_util.h"
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    34
#include "nio.h"
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    35
#include "net_util.h"
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    36
#include "net_util_md.h"
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
    37
#include "sun_nio_ch_sctp_SctpNet.h"
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
    38
#include "sun_nio_ch_sctp_SctpStdSocketOption.h"
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    39
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    40
static jclass isaCls = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    41
static jmethodID isaCtrID = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    42
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    43
static const char* nativeSctpLib = "libsctp.so.1";
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    44
static jboolean funcsLoaded = JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    45
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    46
JNIEXPORT jint JNICALL JNI_OnLoad
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    47
  (JavaVM *vm, void *reserved) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    48
    return JNI_VERSION_1_2;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    49
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    50
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    51
static int preCloseFD = -1;     /* File descriptor to which we dup other fd's
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    52
                                   before closing them for real */
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
    53
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
/**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
 * Loads the native sctp library that contains the socket extension
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    56
 * functions, as well as locating the individual functions.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    57
 * There will be a pending exception if this method returns false.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    58
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    59
jboolean loadSocketExtensionFuncs
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    60
  (JNIEnv* env) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    61
    if (dlopen(nativeSctpLib, RTLD_GLOBAL | RTLD_LAZY) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    62
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    63
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    64
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    65
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    66
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    67
    if ((nio_sctp_getladdrs = (sctp_getladdrs_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    68
            dlsym(RTLD_DEFAULT, "sctp_getladdrs")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    69
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    70
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    71
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    72
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    73
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    74
    if ((nio_sctp_freeladdrs = (sctp_freeladdrs_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    75
            dlsym(RTLD_DEFAULT, "sctp_freeladdrs")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    76
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    77
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    78
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    80
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    81
    if ((nio_sctp_getpaddrs = (sctp_getpaddrs_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
            dlsym(RTLD_DEFAULT, "sctp_getpaddrs")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    86
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
    if ((nio_sctp_freepaddrs = (sctp_freepaddrs_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    89
            dlsym(RTLD_DEFAULT, "sctp_freepaddrs")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    90
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    95
    if ((nio_sctp_bindx = (sctp_bindx_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
            dlsym(RTLD_DEFAULT, "sctp_bindx")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    98
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    99
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   100
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   101
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   102
    if ((nio_sctp_peeloff = (sctp_peeloff_func*)
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   103
            dlsym(RTLD_DEFAULT, "sctp_peeloff")) == NULL) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   104
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   105
              dlerror());
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   106
        return JNI_FALSE;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   107
    }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   108
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
    funcsLoaded = JNI_TRUE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
    return JNI_TRUE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   111
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   112
4678
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   113
jint
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   114
handleSocketError(JNIEnv *env, jint errorValue)
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   115
{
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   116
    char *xn;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   117
    switch (errorValue) {
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   118
        case EINPROGRESS:     /* Non-blocking connect */
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   119
            return 0;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   120
        case EPROTO:
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   121
            xn= JNU_JAVANETPKG "ProtocolException";
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   122
            break;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   123
        case ECONNREFUSED:
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   124
            xn = JNU_JAVANETPKG "ConnectException";
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   125
            break;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   126
        case ETIMEDOUT:
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   127
            xn = JNU_JAVANETPKG "ConnectException";
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   128
            break;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   129
        case EHOSTUNREACH:
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   130
            xn = JNU_JAVANETPKG "NoRouteToHostException";
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   131
            break;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   132
        case EADDRINUSE:  /* Fall through */
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   133
        case EADDRNOTAVAIL:
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   134
            xn = JNU_JAVANETPKG "BindException";
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   135
            break;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   136
        default:
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   137
            xn = JNU_JAVANETPKG "SocketException";
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   138
            break;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   139
    }
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   140
    errno = errorValue;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   141
    JNU_ThrowByNameWithLastError(env, xn, "NioSocketError");
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   142
    return IOS_THROWN;
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   143
}
99fdf34405de 6917317: (sctp) Remove dependency on handleSocketError
chegar
parents: 4675
diff changeset
   144
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   145
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   146
 * Class:     sun_nio_ch_sctp_SctpNet
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   147
 * Method:    init
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   148
 * Signature: ()V
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   149
 */
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   150
JNIEXPORT void JNICALL
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   151
Java_sun_nio_ch_sctp_SctpNet_init
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   152
  (JNIEnv *env, jclass cl) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   153
    int sp[2];
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   154
    if (socketpair(PF_UNIX, SOCK_STREAM, 0, sp) < 0) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   155
        JNU_ThrowIOExceptionWithLastError(env, "socketpair failed");
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   156
        return;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   157
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   158
    preCloseFD = sp[0];
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   159
    close(sp[1]);
22646
5fa3669fd35d 8025306: Inet[4|6]Address class and fieldID initialization in networking native code
chegar
parents: 22631
diff changeset
   160
    initInetAddressIDs(env);
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   161
}
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   162
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   163
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   164
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   165
 * Method:    socket0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   166
 * Signature: (Z)I
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   167
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   168
JNIEXPORT jint JNICALL Java_sun_nio_ch_sctp_SctpNet_socket0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   169
  (JNIEnv *env, jclass klass, jboolean oneToOne) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   170
    int fd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   171
    struct sctp_event_subscribe event;
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 4678
diff changeset
   172
#ifdef AF_INET6
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 4678
diff changeset
   173
    int domain = ipv6_available() ? AF_INET6 : AF_INET;
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 4678
diff changeset
   174
#else
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 4678
diff changeset
   175
    int domain = AF_INET;
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 4678
diff changeset
   176
#endif
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   177
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   178
    /* Try to load the socket API extension functions */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   179
    if (!funcsLoaded && !loadSocketExtensionFuncs(env)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   180
        return 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   181
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   182
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 4678
diff changeset
   183
    fd = socket(domain, (oneToOne ? SOCK_STREAM : SOCK_SEQPACKET), IPPROTO_SCTP);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   184
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   185
    if (fd < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   186
        return handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   187
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   188
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   189
    /* Enable events */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   190
    memset(&event, 0, sizeof(event));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   191
    event.sctp_data_io_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   192
    event.sctp_association_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   193
    event.sctp_address_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   194
    event.sctp_send_failure_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   195
    //event.sctp_peer_error_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   196
    event.sctp_shutdown_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   197
    //event.sctp_partial_delivery_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   198
    //event.sctp_adaptation_layer_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   199
    if (setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(event)) != 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   200
       handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   201
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   202
    return fd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   203
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   204
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   205
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   206
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   207
 * Method:    bindx
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   208
 * Signature: (I[Ljava/net/InetAddress;IIZ)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   209
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   210
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_bindx
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   211
  (JNIEnv *env, jclass klass, jint fd, jobjectArray addrs, jint port,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   212
   jint addrsLength, jboolean add, jboolean preferIPv6) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   213
    SOCKADDR *sap, *tmpSap;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   214
    int i, sa_len = sizeof(SOCKADDR);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   215
    jobject ia;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   216
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   217
    if (addrsLength < 1)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   218
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   219
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   220
    if ((sap = calloc(addrsLength,  sa_len)) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   221
          JNU_ThrowOutOfMemoryError(env, "heap allocation failure");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   222
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   223
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   224
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   225
    tmpSap = sap;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   226
    for (i=0; i<addrsLength; i++) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   227
        ia = (*env)->GetObjectArrayElement(env, addrs, i);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   228
        if (NET_InetAddressToSockaddr(env, ia, port, (struct sockaddr*)tmpSap,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   229
                                      &sa_len, preferIPv6) != 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   230
            free(sap);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   231
            return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   232
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   233
        tmpSap++;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   234
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   235
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   236
    if (nio_sctp_bindx(fd, (void*)sap, addrsLength, add ? SCTP_BINDX_ADD_ADDR :
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   237
                       SCTP_BINDX_REM_ADDR) != 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   238
        handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   239
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   240
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   241
    free(sap);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   242
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   243
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   244
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   245
 * Class:     sun_nio_ch_sctp_SctpNet
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   246
 * Method:    listen0
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   247
 * Signature: (II)V
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   248
 */
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   249
JNIEXPORT void JNICALL
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   250
Java_sun_nio_ch_sctp_SctpNet_listen0
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   251
  (JNIEnv *env, jclass cl, jint fd, jint backlog) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   252
    if (listen(fd, backlog) < 0)
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   253
        handleSocketError(env, errno);
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   254
}
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   255
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   256
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   257
 * Class:     sun_nio_ch_sctp_SctpNet
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   258
 * Method:    connect0
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   259
 * Signature: (ILjava/net/InetAddress;I)I
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   260
 */
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   261
JNIEXPORT jint JNICALL
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   262
Java_sun_nio_ch_sctp_SctpNet_connect0
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   263
  (JNIEnv *env, jclass clazz, int fd, jobject iao, jint port) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   264
    SOCKADDR sa;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   265
    int sa_len = SOCKADDR_LEN;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   266
    int rv;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   267
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   268
    if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *) &sa,
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   269
                                  &sa_len, JNI_TRUE) != 0) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   270
        return IOS_THROWN;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   271
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   272
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   273
    rv = connect(fd, (struct sockaddr *)&sa, sa_len);
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   274
    if (rv != 0) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   275
        if (errno == EINPROGRESS) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   276
            return IOS_UNAVAILABLE;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   277
        } else if (errno == EINTR) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   278
            return IOS_INTERRUPTED;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   279
        }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   280
        return handleSocketError(env, errno);
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   281
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   282
    return 1;
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   283
}
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   284
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   285
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   286
 * Class:     sun_nio_ch_sctp_SctpNet
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   287
 * Method:    close0
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   288
 * Signature: (I)V
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   289
 */
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   290
JNIEXPORT void JNICALL
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   291
Java_sun_nio_ch_sctp_SctpNet_close0
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   292
  (JNIEnv *env, jclass clazz, jint fd) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   293
    if (fd != -1) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   294
        int rv = close(fd);
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   295
        if (rv < 0)
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   296
            JNU_ThrowIOExceptionWithLastError(env, "Close failed");
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   297
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   298
}
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   299
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   300
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   301
 * Class:     sun_nio_ch_sctp_SctpNet
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   302
 * Method:    preClose0
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   303
 * Signature: (I)V
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   304
 */
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   305
JNIEXPORT void JNICALL
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   306
Java_sun_nio_ch_sctp_SctpNet_preClose0
4669
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   307
  (JNIEnv *env, jclass clazz, jint fd) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   308
    if (preCloseFD >= 0) {
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   309
        if (dup2(preCloseFD, fd) < 0)
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   310
            JNU_ThrowIOExceptionWithLastError(env, "dup2 failed");
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   311
    }
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   312
}
11d1dbd3598d 6915313: Reorganize implementation to make it more feasible to port to JDK6
chegar
parents: 3072
diff changeset
   313
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   314
void initializeISA
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   315
  (JNIEnv* env) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   316
    if (isaCls == 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   317
        jclass c = (*env)->FindClass(env, "java/net/InetSocketAddress");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   318
        CHECK_NULL(c);
28680
79674c06a625 8067680: (sctp) Possible race initializing native IDs
robm
parents: 25859
diff changeset
   319
        isaCtrID = (*env)->GetMethodID(env, c, "<init>",
79674c06a625 8067680: (sctp) Possible race initializing native IDs
robm
parents: 25859
diff changeset
   320
                                     "(Ljava/net/InetAddress;I)V");
79674c06a625 8067680: (sctp) Possible race initializing native IDs
robm
parents: 25859
diff changeset
   321
        CHECK_NULL(isaCtrID);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   322
        isaCls = (*env)->NewGlobalRef(env, c);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   323
        CHECK_NULL(isaCls);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   324
        (*env)->DeleteLocalRef(env, c);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   325
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   326
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   327
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   328
jobject SockAddrToInetSocketAddress
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   329
  (JNIEnv *env, struct sockaddr* sap) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   330
    int port = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   331
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   332
    jobject ia = NET_SockaddrToInetAddress(env, sap, &port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   333
    if (ia == NULL)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   334
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   335
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   336
    if (isaCls == 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   337
        initializeISA(env);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   338
        CHECK_NULL_RETURN(isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   339
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   340
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   341
    return (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   342
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   343
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   344
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   345
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   346
 * Method:    getLocalAddresses0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   347
 * Signature: (I)[Ljava/net/SocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   348
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   349
JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_sctp_SctpNet_getLocalAddresses0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   350
  (JNIEnv *env, jclass klass, jint fd) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   351
    void *addr_buf, *laddr;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   352
    struct sockaddr* sap;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   353
    int i, addrCount;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   354
    jobjectArray isaa;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   355
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   356
#ifdef __solaris__
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   357
    if ((addrCount = nio_sctp_getladdrs(fd, 0, (void **)&addr_buf)) == -1) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   358
#else /* __linux__ */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   359
    if ((addrCount = nio_sctp_getladdrs(fd, 0, (struct sockaddr **)&addr_buf)) == -1) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   360
#endif
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   361
        handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   362
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   363
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   364
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   365
    if (addrCount < 1)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   366
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   367
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   368
    if (isaCls == 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   369
        initializeISA(env);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   370
        CHECK_NULL_RETURN(isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   371
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   372
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   373
    isaa = (*env)->NewObjectArray(env, addrCount, isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   374
    if (isaa == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   375
        nio_sctp_freeladdrs(addr_buf);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   376
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   377
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   378
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   379
    laddr = addr_buf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   380
    for (i=0; i<addrCount; i++) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   381
        int port = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   382
        jobject isa = NULL, ia;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   383
        sap = (struct sockaddr*)addr_buf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   384
        ia = NET_SockaddrToInetAddress(env, sap, &port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   385
        if (ia != NULL)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   386
            isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 14342
diff changeset
   387
        if (isa == NULL)
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 14342
diff changeset
   388
            break;
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 14342
diff changeset
   389
        (*env)->SetObjectArrayElement(env, isaa, i, isa);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   390
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   391
        if (sap->sa_family == AF_INET)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   392
            addr_buf = ((struct sockaddr_in*)addr_buf) + 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   393
        else
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   394
            addr_buf = ((struct sockaddr_in6*)addr_buf) + 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   395
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   396
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   397
    nio_sctp_freeladdrs(laddr);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   398
    return isaa;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   399
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   400
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   401
jobjectArray getRemoteAddresses
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   402
  (JNIEnv *env, jint fd, sctp_assoc_t id) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   403
    void *addr_buf, *paddr;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   404
    struct sockaddr* sap;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   405
    int i, addrCount;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   406
    jobjectArray isaa;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   407
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   408
#if __solaris__
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   409
    if ((addrCount = nio_sctp_getpaddrs(fd, id, (void **)&addr_buf)) == -1) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   410
#else /* __linux__ */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   411
    if ((addrCount = nio_sctp_getpaddrs(fd, id, (struct sockaddr**)&addr_buf)) == -1) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   412
#endif
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   413
        handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   414
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   415
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   416
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   417
    if (addrCount < 1)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   418
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   419
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   420
    if (isaCls == 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   421
        initializeISA(env);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   422
        CHECK_NULL_RETURN(isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   423
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   424
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   425
    isaa = (*env)->NewObjectArray(env, addrCount, isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   426
    if (isaa == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   427
        nio_sctp_freepaddrs(addr_buf);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   428
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   429
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   430
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   431
    paddr = addr_buf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   432
    for (i=0; i<addrCount; i++) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   433
        jobject ia, isa = NULL;
29118
8782a8e91d4c 8046901: Check jdk/src/solaris/native/sun/nio for Parfait flagged uninitialized memory
msheppar
parents: 28680
diff changeset
   434
        int port = 0;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   435
        sap = (struct sockaddr*)addr_buf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   436
        ia = NET_SockaddrToInetAddress(env, sap, &port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   437
        if (ia != NULL)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   438
            isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
22631
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 14342
diff changeset
   439
        if (isa == NULL)
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 14342
diff changeset
   440
            break;
ac85b05a53f4 8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
alanb
parents: 14342
diff changeset
   441
        (*env)->SetObjectArrayElement(env, isaa, i, isa);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   442
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   443
        if (sap->sa_family == AF_INET)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   444
            addr_buf = ((struct sockaddr_in*)addr_buf) + 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   445
        else
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   446
            addr_buf = ((struct sockaddr_in6*)addr_buf) + 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   447
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   448
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   449
    nio_sctp_freepaddrs(paddr);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   450
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   451
    return isaa;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   452
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   453
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   454
 /*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   455
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   456
 * Method:    getRemoteAddresses0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   457
 * Signature: (II)[Ljava/net/SocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   458
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   459
JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_sctp_SctpNet_getRemoteAddresses0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   460
  (JNIEnv *env, jclass klass, jint fd, jint assocId) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   461
    return getRemoteAddresses(env, fd, assocId);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   462
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   463
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   464
/* Map the Java level option to the native level */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   465
int mapSocketOption
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   466
  (jint cmd, int *level, int *optname) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   467
    static struct {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   468
        jint cmd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   469
        int level;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   470
        int optname;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   471
    } const opts[] = {
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   472
        { sun_nio_ch_sctp_SctpStdSocketOption_SCTP_DISABLE_FRAGMENTS,   IPPROTO_SCTP, SCTP_DISABLE_FRAGMENTS },
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   473
        { sun_nio_ch_sctp_SctpStdSocketOption_SCTP_EXPLICIT_COMPLETE,   IPPROTO_SCTP, SCTP_EXPLICIT_EOR },
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   474
        { sun_nio_ch_sctp_SctpStdSocketOption_SCTP_FRAGMENT_INTERLEAVE, IPPROTO_SCTP, SCTP_FRAGMENT_INTERLEAVE },
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   475
        { sun_nio_ch_sctp_SctpStdSocketOption_SCTP_NODELAY,             IPPROTO_SCTP, SCTP_NODELAY },
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   476
        { sun_nio_ch_sctp_SctpStdSocketOption_SO_SNDBUF,                SOL_SOCKET,   SO_SNDBUF },
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   477
        { sun_nio_ch_sctp_SctpStdSocketOption_SO_RCVBUF,                SOL_SOCKET,   SO_RCVBUF },
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   478
        { sun_nio_ch_sctp_SctpStdSocketOption_SO_LINGER,                SOL_SOCKET,   SO_LINGER } };
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   479
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   480
    int i;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   481
    for (i=0; i<(int)(sizeof(opts) / sizeof(opts[0])); i++) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   482
        if (cmd == opts[i].cmd) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   483
            *level = opts[i].level;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   484
            *optname = opts[i].optname;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   485
            return 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   486
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   487
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   488
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   489
    /* not found */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   490
    return -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   491
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   492
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   493
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   494
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   495
 * Method:    setIntOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   496
 * Signature: (III)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   497
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   498
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_setIntOption0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   499
  (JNIEnv *env, jclass klass, jint fd, jint opt, int arg) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   500
    int klevel, kopt;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   501
    int result;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   502
    struct linger linger;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   503
    void *parg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   504
    int arglen;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   505
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   506
    if (mapSocketOption(opt, &klevel, &kopt) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   507
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   508
                                     "Unsupported socket option");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   509
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   510
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   511
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   512
    if (opt == sun_nio_ch_sctp_SctpStdSocketOption_SO_LINGER) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   513
        parg = (void *)&linger;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   514
        arglen = sizeof(linger);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   515
        if (arg >= 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   516
            linger.l_onoff = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   517
            linger.l_linger = arg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   518
        } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   519
            linger.l_onoff = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   520
            linger.l_linger = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   521
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   522
    } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   523
        parg = (void *)&arg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   524
        arglen = sizeof(arg);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   525
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   526
4675
68f287672813 6916922: (sctp) SO_RCVBUF & SO_SNDBUF returns twice the value set
chegar
parents: 4669
diff changeset
   527
    if (NET_SetSockOpt(fd, klevel, kopt, parg, arglen) < 0) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   528
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   529
                                     "sun_nio_ch_sctp_SctpNet.setIntOption0");
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   530
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   531
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   532
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   533
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   534
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   535
 * Method:    getIntOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   536
 * Signature: (II)I
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   537
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   538
JNIEXPORT int JNICALL Java_sun_nio_ch_sctp_SctpNet_getIntOption0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   539
  (JNIEnv *env, jclass klass, jint fd, jint opt) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   540
    int klevel, kopt;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   541
    int result;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   542
    struct linger linger;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   543
    void *arg;
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 5506
diff changeset
   544
    int arglen;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   545
29118
8782a8e91d4c 8046901: Check jdk/src/solaris/native/sun/nio for Parfait flagged uninitialized memory
msheppar
parents: 28680
diff changeset
   546
    memset((char *) &linger, 0, sizeof(linger));
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   547
    if (mapSocketOption(opt, &klevel, &kopt) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   548
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   549
                                     "Unsupported socket option");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   550
        return -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   551
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   552
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   553
    if (opt == sun_nio_ch_sctp_SctpStdSocketOption_SO_LINGER) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   554
        arg = (void *)&linger;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   555
        arglen = sizeof(linger);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   556
    } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   557
        arg = (void *)&result;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   558
        arglen = sizeof(result);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   559
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   560
4675
68f287672813 6916922: (sctp) SO_RCVBUF & SO_SNDBUF returns twice the value set
chegar
parents: 4669
diff changeset
   561
    if (NET_GetSockOpt(fd, klevel, kopt, arg, &arglen) < 0) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   562
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   563
                                     "sun.nio.ch.Net.getIntOption");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   564
        return -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   565
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   566
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   567
    if (opt == sun_nio_ch_sctp_SctpStdSocketOption_SO_LINGER)
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   568
        return linger.l_onoff ? linger.l_linger : -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   569
    else
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   570
        return result;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   571
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   572
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   573
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   574
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   575
 * Method:    getPrimAddrOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   576
 * Signature: (II)Ljava/net/SocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   577
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   578
JNIEXPORT jobject JNICALL Java_sun_nio_ch_sctp_SctpNet_getPrimAddrOption0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   579
  (JNIEnv *env, jclass klass, jint fd, jint assocId) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   580
    struct sctp_setprim prim;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   581
    unsigned int prim_len = sizeof(prim);
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   582
    struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   583
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   584
    prim.ssp_assoc_id = assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   585
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   586
    if (getsockopt(fd, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &prim, &prim_len) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   587
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   588
                                     "sun.nio.ch.SctpNet.getPrimAddrOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   589
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   590
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   591
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   592
    return SockAddrToInetSocketAddress(env, sap);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   593
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   594
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   595
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   596
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   597
 * Method:    setPrimAddrOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   598
 * Signature: (IILjava/net/InetAddress;I)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   599
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   600
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_setPrimAddrOption0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   601
  (JNIEnv *env, jclass klass, jint fd, jint assocId, jobject iaObj, jint port) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   602
    struct sctp_setprim prim;
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   603
    struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr;
29118
8782a8e91d4c 8046901: Check jdk/src/solaris/native/sun/nio for Parfait flagged uninitialized memory
msheppar
parents: 28680
diff changeset
   604
    int sap_len = sizeof(sap);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   605
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   606
    if (NET_InetAddressToSockaddr(env, iaObj, port, sap,
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   607
                                  &sap_len, JNI_TRUE) != 0) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   608
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   609
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   610
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   611
    prim.ssp_assoc_id = assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   612
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   613
    if (setsockopt(fd, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &prim, sizeof(prim)) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   614
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   615
                                     "sun.nio.ch.SctpNet.setPrimAddrOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   616
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   617
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   618
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   619
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   620
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   621
 * Method:    setPeerPrimAddrOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   622
 * Signature: (IILjava/net/InetAddress;I)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   623
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   624
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_setPeerPrimAddrOption0
7545
409091945418 7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents: 6850
diff changeset
   625
  (JNIEnv *env, jclass klass, jint fd, jint assocId,
409091945418 7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents: 6850
diff changeset
   626
   jobject iaObj, jint port, jboolean preferIPv6) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   627
    struct sctp_setpeerprim prim;
7545
409091945418 7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents: 6850
diff changeset
   628
    struct sockaddr* sap = (struct sockaddr*)&prim.sspp_addr;
29118
8782a8e91d4c 8046901: Check jdk/src/solaris/native/sun/nio for Parfait flagged uninitialized memory
msheppar
parents: 28680
diff changeset
   629
    int sap_len = sizeof(sap);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   630
7545
409091945418 7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents: 6850
diff changeset
   631
    if (NET_InetAddressToSockaddr(env, iaObj, port, sap,
409091945418 7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
chegar
parents: 6850
diff changeset
   632
                                  &sap_len, preferIPv6) != 0) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   633
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   634
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   635
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   636
    prim.sspp_assoc_id = assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   637
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   638
    if (setsockopt(fd, IPPROTO_SCTP, SCTP_SET_PEER_PRIMARY_ADDR, &prim,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   639
            sizeof(prim)) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   640
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   641
                                     "sun.nio.ch.SctpNet.setPeerPrimAddrOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   642
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   643
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   644
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   645
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   646
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   647
 * Method:    getInitMsgOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   648
 * Signature: (I[I)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   649
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   650
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_getInitMsgOption0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   651
  (JNIEnv *env, jclass klass, jint fd, jintArray retVal) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   652
    struct sctp_initmsg sctp_initmsg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   653
    unsigned int sim_len = sizeof(sctp_initmsg);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   654
    int vals[2];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   655
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   656
    if (getsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &sctp_initmsg,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   657
            &sim_len) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   658
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   659
                                     "sun.nio.ch.SctpNet.getInitMsgOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   660
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   661
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   662
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   663
    vals[0] = sctp_initmsg.sinit_max_instreams;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   664
    vals[1] = sctp_initmsg.sinit_num_ostreams;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   665
    (*env)->SetIntArrayRegion(env, retVal, 0, 2, vals);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   666
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   667
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   668
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   669
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   670
 * Method:    setInitMsgOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   671
 * Signature: (III)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   672
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   673
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_setInitMsgOption0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   674
  (JNIEnv *env, jclass klass, jint fd, jint inArg, jint outArg) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   675
    struct sctp_initmsg sctp_initmsg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   676
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   677
    sctp_initmsg.sinit_max_instreams = (unsigned int)inArg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   678
    sctp_initmsg.sinit_num_ostreams = (unsigned int)outArg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   679
    sctp_initmsg.sinit_max_attempts = 0;  // default
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   680
    sctp_initmsg.sinit_max_init_timeo = 0;  // default
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   681
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   682
    if (setsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &sctp_initmsg,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   683
          sizeof(sctp_initmsg)) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   684
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   685
                                     "sun.nio.ch.SctpNet.setInitMsgOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   686
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   687
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   688
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   689
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   690
 * Class:     sun_nio_ch_sctp_SctpNet
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   691
 * Method:    shutdown0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   692
 * Signature: (II)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   693
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   694
JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_shutdown0
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   695
  (JNIEnv *env, jclass klass, jint fd, jint assocId) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   696
    int rv;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   697
    struct msghdr msg[1];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   698
    struct iovec iov[1];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   699
    int cbuf_size = CMSG_SPACE(sizeof (struct sctp_sndrcvinfo));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   700
    char cbuf[CMSG_SPACE(sizeof (struct sctp_sndrcvinfo))];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   701
    struct cmsghdr* cmsg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   702
    struct sctp_sndrcvinfo *sri;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   703
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   704
    /* SctpSocketChannel */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   705
    if (assocId < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   706
        shutdown(fd, SHUT_WR);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   707
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   708
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   709
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   710
    memset(msg, 0, sizeof (*msg));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   711
    memset(cbuf, 0, cbuf_size);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   712
    msg->msg_name = NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   713
    msg->msg_namelen = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   714
    iov->iov_base = NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   715
    iov->iov_len = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   716
    msg->msg_iov = iov;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   717
    msg->msg_iovlen = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   718
    msg->msg_control = cbuf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   719
    msg->msg_controllen = cbuf_size;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   720
    msg->msg_flags = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   721
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   722
    cmsg = CMSG_FIRSTHDR(msg);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   723
    cmsg->cmsg_level = IPPROTO_SCTP;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   724
    cmsg->cmsg_type = SCTP_SNDRCV;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   725
    cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   726
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   727
    /* Initialize the payload: */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   728
    sri = (struct sctp_sndrcvinfo*) CMSG_DATA(cmsg);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   729
    memset(sri, 0, sizeof (*sri));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   730
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   731
    if (assocId > 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   732
        sri->sinfo_assoc_id = assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   733
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   734
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   735
    sri->sinfo_flags = sri->sinfo_flags | SCTP_EOF;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   736
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   737
    /* Sum of the length of all control messages in the buffer. */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   738
    msg->msg_controllen = cmsg->cmsg_len;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   739
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   740
    if ((rv = sendmsg(fd, msg, 0)) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   741
        handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   742
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   743
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   744
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   745
/*
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   746
 * Class:     sun_nio_ch_sctp_SctpNet
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   747
 * Method:    branch
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   748
 * Signature: (II)I
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   749
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 7668
diff changeset
   750
JNIEXPORT int JNICALL Java_sun_nio_ch_sctp_SctpNet_branch0
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   751
  (JNIEnv *env, jclass klass, jint fd, jint assocId) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   752
    int newfd = 0;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   753
    if ((newfd = nio_sctp_peeloff(fd, assocId)) < 0) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   754
        handleSocketError(env, errno);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   755
    }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   756
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   757
    return newfd;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   758
}