jdk/src/solaris/native/sun/nio/ch/SctpNet.c
author chegar
Mon, 29 Jun 2009 14:53:10 +0100
changeset 3072 a801b122142f
parent 2542 d859108aea12
child 4669 11d1dbd3598d
permissions -rw-r--r--
6855335: Several changes in the SCTP implementation. Reviewed-by: michaelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     1
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
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
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    23
 * have any questions.
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"
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    37
#include "sun_nio_ch_SctpNet.h"
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    38
#include "sun_nio_ch_SctpStdSocketOption.h"
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
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    51
/**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    52
 * Loads the native sctp library that contains the socket extension
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    53
 * functions, as well as locating the individual functions.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
 * There will be a pending exception if this method returns false.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    56
jboolean loadSocketExtensionFuncs
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    57
  (JNIEnv* env) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    58
    if (dlopen(nativeSctpLib, RTLD_GLOBAL | RTLD_LAZY) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    59
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    60
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    61
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    62
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    63
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    64
    if ((nio_sctp_getladdrs = (sctp_getladdrs_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    65
            dlsym(RTLD_DEFAULT, "sctp_getladdrs")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    66
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    67
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    68
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    69
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    70
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    71
    if ((nio_sctp_freeladdrs = (sctp_freeladdrs_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    72
            dlsym(RTLD_DEFAULT, "sctp_freeladdrs")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    73
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    74
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    75
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    76
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    77
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    78
    if ((nio_sctp_getpaddrs = (sctp_getpaddrs_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
            dlsym(RTLD_DEFAULT, "sctp_getpaddrs")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    80
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    81
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
    if ((nio_sctp_freepaddrs = (sctp_freepaddrs_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    86
            dlsym(RTLD_DEFAULT, "sctp_freepaddrs")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    89
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    90
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
    if ((nio_sctp_bindx = (sctp_bindx_func*)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
            dlsym(RTLD_DEFAULT, "sctp_bindx")) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    95
              dlerror());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
        return JNI_FALSE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    98
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    99
    if ((nio_sctp_peeloff = (sctp_peeloff_func*)
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   100
            dlsym(RTLD_DEFAULT, "sctp_peeloff")) == NULL) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   101
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   102
              dlerror());
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   103
        return JNI_FALSE;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   104
    }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   105
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   106
    funcsLoaded = JNI_TRUE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   107
    return JNI_TRUE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   108
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   111
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   112
 * Method:    socket0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   113
 * Signature: (Z)I
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   114
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   115
JNIEXPORT jint JNICALL Java_sun_nio_ch_SctpNet_socket0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   116
  (JNIEnv *env, jclass klass, jboolean oneToOne) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   117
    int fd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   118
    struct sctp_event_subscribe event;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   119
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   120
    /* Try to load the socket API extension functions */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   121
    if (!funcsLoaded && !loadSocketExtensionFuncs(env)) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   122
        return 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   123
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   124
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   125
    fd = socket(ipv6_available() ? AF_INET6 : AF_INET,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   126
            (oneToOne ? SOCK_STREAM : SOCK_SEQPACKET), IPPROTO_SCTP);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   127
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   128
    if (fd < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   129
        return handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   130
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   131
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   132
    /* Enable events */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   133
    memset(&event, 0, sizeof(event));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   134
    event.sctp_data_io_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   135
    event.sctp_association_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   136
    event.sctp_address_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   137
    event.sctp_send_failure_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   138
    //event.sctp_peer_error_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   139
    event.sctp_shutdown_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   140
    //event.sctp_partial_delivery_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   141
    //event.sctp_adaptation_layer_event = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   142
    if (setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(event)) != 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   143
       handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   144
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   145
    return fd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   146
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   147
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   148
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   149
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   150
 * Method:    bindx
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   151
 * Signature: (I[Ljava/net/InetAddress;IIZ)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   152
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   153
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_bindx
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   154
  (JNIEnv *env, jclass klass, jint fd, jobjectArray addrs, jint port,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   155
   jint addrsLength, jboolean add, jboolean preferIPv6) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   156
    SOCKADDR *sap, *tmpSap;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   157
    int i, sa_len = sizeof(SOCKADDR);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   158
    jobject ia;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   159
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   160
    if (addrsLength < 1)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   161
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   162
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   163
    if ((sap = calloc(addrsLength,  sa_len)) == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   164
          JNU_ThrowOutOfMemoryError(env, "heap allocation failure");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   165
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   166
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   167
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   168
    tmpSap = sap;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   169
    for (i=0; i<addrsLength; i++) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   170
        ia = (*env)->GetObjectArrayElement(env, addrs, i);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   171
        if (NET_InetAddressToSockaddr(env, ia, port, (struct sockaddr*)tmpSap,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   172
                                      &sa_len, preferIPv6) != 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   173
            free(sap);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   174
            return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   175
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   176
        tmpSap++;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   177
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   178
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   179
    if (nio_sctp_bindx(fd, (void*)sap, addrsLength, add ? SCTP_BINDX_ADD_ADDR :
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   180
                       SCTP_BINDX_REM_ADDR) != 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   181
        handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   182
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   183
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   184
    free(sap);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   185
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   186
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   187
void initializeISA
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   188
  (JNIEnv* env) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   189
    if (isaCls == 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   190
        jclass c = (*env)->FindClass(env, "java/net/InetSocketAddress");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   191
        CHECK_NULL(c);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   192
        isaCls = (*env)->NewGlobalRef(env, c);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   193
        CHECK_NULL(isaCls);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   194
        (*env)->DeleteLocalRef(env, c);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   195
        isaCtrID = (*env)->GetMethodID(env, isaCls, "<init>",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   196
                                     "(Ljava/net/InetAddress;I)V");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   197
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   198
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   199
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   200
jobject SockAddrToInetSocketAddress
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   201
  (JNIEnv *env, struct sockaddr* sap) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   202
    int port = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   203
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   204
    jobject ia = NET_SockaddrToInetAddress(env, sap, &port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   205
    if (ia == NULL)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   206
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   207
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   208
    if (isaCls == 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   209
        initializeISA(env);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   210
        CHECK_NULL_RETURN(isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   211
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   212
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   213
    return (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   214
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   215
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   216
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   217
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   218
 * Method:    getLocalAddresses0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   219
 * Signature: (I)[Ljava/net/SocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   220
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   221
JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_SctpNet_getLocalAddresses0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   222
  (JNIEnv *env, jclass klass, jint fd) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   223
    void *addr_buf, *laddr;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   224
    struct sockaddr* sap;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   225
    int i, addrCount;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   226
    jobjectArray isaa;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   227
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   228
#ifdef __solaris__
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   229
    if ((addrCount = nio_sctp_getladdrs(fd, 0, (void **)&addr_buf)) == -1) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   230
#else /* __linux__ */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   231
    if ((addrCount = nio_sctp_getladdrs(fd, 0, (struct sockaddr **)&addr_buf)) == -1) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   232
#endif
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   233
        handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   234
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   235
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   236
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   237
    if (addrCount < 1)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   238
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   239
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   240
    if (isaCls == 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   241
        initializeISA(env);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   242
        CHECK_NULL_RETURN(isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   243
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   244
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   245
    isaa = (*env)->NewObjectArray(env, addrCount, isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   246
    if (isaa == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   247
        nio_sctp_freeladdrs(addr_buf);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   248
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   249
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   250
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   251
    laddr = addr_buf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   252
    for (i=0; i<addrCount; i++) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   253
        int port = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   254
        jobject isa = NULL, ia;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   255
        sap = (struct sockaddr*)addr_buf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   256
        ia = NET_SockaddrToInetAddress(env, sap, &port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   257
        if (ia != NULL)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   258
            isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   259
        if (isa != NULL)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   260
            (*env)->SetObjectArrayElement(env, isaa, i, isa);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   261
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   262
        if (sap->sa_family == AF_INET)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   263
            addr_buf = ((struct sockaddr_in*)addr_buf) + 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   264
        else
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   265
            addr_buf = ((struct sockaddr_in6*)addr_buf) + 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   266
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   267
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   268
    nio_sctp_freeladdrs(laddr);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   269
    return isaa;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   270
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   271
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   272
jobjectArray getRemoteAddresses
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   273
  (JNIEnv *env, jint fd, sctp_assoc_t id) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   274
    void *addr_buf, *paddr;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   275
    struct sockaddr* sap;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   276
    int i, addrCount;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   277
    jobjectArray isaa;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   278
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   279
#if __solaris__
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   280
    if ((addrCount = nio_sctp_getpaddrs(fd, id, (void **)&addr_buf)) == -1) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   281
#else /* __linux__ */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   282
    if ((addrCount = nio_sctp_getpaddrs(fd, id, (struct sockaddr**)&addr_buf)) == -1) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   283
#endif
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   284
        handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   285
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   286
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   287
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   288
    if (addrCount < 1)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   289
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   290
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   291
    if (isaCls == 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   292
        initializeISA(env);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   293
        CHECK_NULL_RETURN(isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   294
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   295
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   296
    isaa = (*env)->NewObjectArray(env, addrCount, isaCls, NULL);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   297
    if (isaa == NULL) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   298
        nio_sctp_freepaddrs(addr_buf);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   299
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   300
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   301
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   302
    paddr = addr_buf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   303
    for (i=0; i<addrCount; i++) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   304
        jobject ia, isa = NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   305
        int port;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   306
        sap = (struct sockaddr*)addr_buf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   307
        ia = NET_SockaddrToInetAddress(env, sap, &port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   308
        if (ia != NULL)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   309
            isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   310
        if (isa != NULL)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   311
            (*env)->SetObjectArrayElement(env, isaa, i, isa);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   312
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   313
        if (sap->sa_family == AF_INET)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   314
            addr_buf = ((struct sockaddr_in*)addr_buf) + 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   315
        else
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   316
            addr_buf = ((struct sockaddr_in6*)addr_buf) + 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   317
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   318
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   319
    nio_sctp_freepaddrs(paddr);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   320
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   321
    return isaa;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   322
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   323
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   324
 /*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   325
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   326
 * Method:    getRemoteAddresses0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   327
 * Signature: (II)[Ljava/net/SocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   328
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   329
JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_SctpNet_getRemoteAddresses0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   330
  (JNIEnv *env, jclass klass, jint fd, jint assocId) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   331
    return getRemoteAddresses(env, fd, assocId);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   332
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   333
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   334
/* Map the Java level option to the native level */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   335
int mapSocketOption
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   336
  (jint cmd, int *level, int *optname) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   337
    static struct {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   338
        jint cmd;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   339
        int level;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   340
        int optname;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   341
    } const opts[] = {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   342
        { sun_nio_ch_SctpStdSocketOption_SCTP_DISABLE_FRAGMENTS,   IPPROTO_SCTP, SCTP_DISABLE_FRAGMENTS },
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   343
        { sun_nio_ch_SctpStdSocketOption_SCTP_EXPLICIT_COMPLETE,   IPPROTO_SCTP, SCTP_EXPLICIT_EOR },
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   344
        { sun_nio_ch_SctpStdSocketOption_SCTP_FRAGMENT_INTERLEAVE, IPPROTO_SCTP, SCTP_FRAGMENT_INTERLEAVE },
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   345
        { sun_nio_ch_SctpStdSocketOption_SCTP_NODELAY,             IPPROTO_SCTP, SCTP_NODELAY },
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   346
        { sun_nio_ch_SctpStdSocketOption_SO_SNDBUF,                SOL_SOCKET,   SO_SNDBUF },
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   347
        { sun_nio_ch_SctpStdSocketOption_SO_RCVBUF,                SOL_SOCKET,   SO_RCVBUF },
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   348
        { sun_nio_ch_SctpStdSocketOption_SO_LINGER,                SOL_SOCKET,   SO_LINGER } };
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   349
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   350
    int i;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   351
    for (i=0; i<(int)(sizeof(opts) / sizeof(opts[0])); i++) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   352
        if (cmd == opts[i].cmd) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   353
            *level = opts[i].level;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   354
            *optname = opts[i].optname;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   355
            return 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   356
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   357
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   358
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   359
    /* not found */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   360
    return -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   361
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   362
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   363
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   364
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   365
 * Method:    setIntOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   366
 * Signature: (III)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   367
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   368
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setIntOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   369
  (JNIEnv *env, jclass klass, jint fd, jint opt, int arg) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   370
    int klevel, kopt;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   371
    int result;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   372
    struct linger linger;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   373
    void *parg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   374
    int arglen;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   375
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   376
    if (mapSocketOption(opt, &klevel, &kopt) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   377
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   378
                                     "Unsupported socket option");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   379
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   380
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   381
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   382
    if (opt == sun_nio_ch_SctpStdSocketOption_SO_LINGER) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   383
        parg = (void *)&linger;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   384
        arglen = sizeof(linger);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   385
        if (arg >= 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   386
            linger.l_onoff = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   387
            linger.l_linger = arg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   388
        } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   389
            linger.l_onoff = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   390
            linger.l_linger = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   391
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   392
    } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   393
        parg = (void *)&arg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   394
        arglen = sizeof(arg);
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
    if (setsockopt(fd, klevel, kopt, parg, arglen) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   398
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   399
                                     "sun_nio_ch_SctpNet.setIntOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   400
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   401
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   402
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   403
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   404
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   405
 * Method:    getIntOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   406
 * Signature: (II)I
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   407
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   408
JNIEXPORT int JNICALL Java_sun_nio_ch_SctpNet_getIntOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   409
  (JNIEnv *env, jclass klass, jint fd, jint opt) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   410
    int klevel, kopt;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   411
    int result;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   412
    struct linger linger;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   413
    void *arg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   414
    unsigned int arglen;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   415
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   416
    if (mapSocketOption(opt, &klevel, &kopt) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   417
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   418
                                     "Unsupported socket option");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   419
        return -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   420
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   421
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   422
    if (opt == sun_nio_ch_SctpStdSocketOption_SO_LINGER) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   423
        arg = (void *)&linger;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   424
        arglen = sizeof(linger);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   425
    } else {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   426
        arg = (void *)&result;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   427
        arglen = sizeof(result);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   428
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   429
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   430
    if (getsockopt(fd, klevel, kopt, arg, &arglen) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   431
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   432
                                     "sun.nio.ch.Net.getIntOption");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   433
        return -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   434
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   435
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   436
    if (opt == sun_nio_ch_SctpStdSocketOption_SO_LINGER)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   437
        return linger.l_onoff ? linger.l_linger : -1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   438
    else
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   439
        return result;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   440
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   441
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   442
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   443
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   444
 * Method:    getPrimAddrOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   445
 * Signature: (II)Ljava/net/SocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   446
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   447
JNIEXPORT jobject JNICALL Java_sun_nio_ch_SctpNet_getPrimAddrOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   448
  (JNIEnv *env, jclass klass, jint fd, jint assocId) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   449
    struct sctp_setprim prim;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   450
    unsigned int prim_len = sizeof(prim);
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   451
    struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   452
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   453
    prim.ssp_assoc_id = assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   454
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   455
    if (getsockopt(fd, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &prim, &prim_len) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   456
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   457
                                     "sun.nio.ch.SctpNet.getPrimAddrOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   458
        return NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   459
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   460
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   461
    return SockAddrToInetSocketAddress(env, sap);
2542
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
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   465
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   466
 * Method:    setPrimAddrOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   467
 * Signature: (IILjava/net/InetAddress;I)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   468
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   469
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setPrimAddrOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   470
  (JNIEnv *env, jclass klass, jint fd, jint assocId, jobject iaObj, jint port) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   471
    struct sctp_setprim prim;
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   472
    struct sockaddr* sap = (struct sockaddr*)&prim.ssp_addr;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   473
    int sap_len;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   474
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   475
    if (NET_InetAddressToSockaddr(env, iaObj, port, sap,
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   476
                                  &sap_len, JNI_TRUE) != 0) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   477
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   478
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   479
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   480
    prim.ssp_assoc_id = assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   481
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   482
    if (setsockopt(fd, IPPROTO_SCTP, SCTP_PRIMARY_ADDR, &prim, sizeof(prim)) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   483
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   484
                                     "sun.nio.ch.SctpNet.setPrimAddrOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   485
    }
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
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   490
 * Method:    setPeerPrimAddrOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   491
 * Signature: (IILjava/net/InetAddress;I)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   492
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   493
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setPeerPrimAddrOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   494
  (JNIEnv *env, jclass klass, jint fd, jint assocId, jobject iaObj, jint port) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   495
    struct sctp_setpeerprim prim;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   496
    struct sockaddr_storage ss;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   497
    int ss_len = sizeof(ss);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   498
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   499
    if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&ss,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   500
                                  &ss_len, JNI_TRUE) != 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   501
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   502
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   503
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   504
    prim.sspp_assoc_id = assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   505
    prim.sspp_addr = ss;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   506
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   507
    if (setsockopt(fd, IPPROTO_SCTP, SCTP_SET_PEER_PRIMARY_ADDR, &prim,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   508
            sizeof(prim)) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   509
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   510
                                     "sun.nio.ch.SctpNet.setPeerPrimAddrOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   511
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   512
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   513
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   514
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   515
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   516
 * Method:    getInitMsgOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   517
 * Signature: (I[I)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   518
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   519
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_getInitMsgOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   520
  (JNIEnv *env, jclass klass, jint fd, jintArray retVal) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   521
    struct sctp_initmsg sctp_initmsg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   522
    unsigned int sim_len = sizeof(sctp_initmsg);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   523
    int vals[2];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   524
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   525
    if (getsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &sctp_initmsg,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   526
            &sim_len) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   527
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   528
                                     "sun.nio.ch.SctpNet.getInitMsgOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   529
        return;
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
    vals[0] = sctp_initmsg.sinit_max_instreams;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   533
    vals[1] = sctp_initmsg.sinit_num_ostreams;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   534
    (*env)->SetIntArrayRegion(env, retVal, 0, 2, vals);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   535
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   536
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   537
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   538
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   539
 * Method:    setInitMsgOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   540
 * Signature: (III)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   541
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   542
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setInitMsgOption0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   543
  (JNIEnv *env, jclass klass, jint fd, jint inArg, jint outArg) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   544
    struct sctp_initmsg sctp_initmsg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   545
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   546
    sctp_initmsg.sinit_max_instreams = (unsigned int)inArg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   547
    sctp_initmsg.sinit_num_ostreams = (unsigned int)outArg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   548
    sctp_initmsg.sinit_max_attempts = 0;  // default
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   549
    sctp_initmsg.sinit_max_init_timeo = 0;  // default
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   550
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   551
    if (setsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &sctp_initmsg,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   552
          sizeof(sctp_initmsg)) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   553
        JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   554
                                     "sun.nio.ch.SctpNet.setInitMsgOption0");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   555
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   556
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   557
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   558
/*
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   559
 * Class:     sun_nio_ch_SctpNet
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   560
 * Method:    shutdown0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   561
 * Signature: (II)V
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   562
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   563
JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_shutdown0
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   564
  (JNIEnv *env, jclass klass, jint fd, jint assocId) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   565
    int rv;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   566
    struct msghdr msg[1];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   567
    struct iovec iov[1];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   568
    int cbuf_size = CMSG_SPACE(sizeof (struct sctp_sndrcvinfo));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   569
    char cbuf[CMSG_SPACE(sizeof (struct sctp_sndrcvinfo))];
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   570
    struct cmsghdr* cmsg;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   571
    struct sctp_sndrcvinfo *sri;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   572
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   573
    /* SctpSocketChannel */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   574
    if (assocId < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   575
        shutdown(fd, SHUT_WR);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   576
        return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   577
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   578
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   579
    memset(msg, 0, sizeof (*msg));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   580
    memset(cbuf, 0, cbuf_size);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   581
    msg->msg_name = NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   582
    msg->msg_namelen = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   583
    iov->iov_base = NULL;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   584
    iov->iov_len = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   585
    msg->msg_iov = iov;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   586
    msg->msg_iovlen = 1;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   587
    msg->msg_control = cbuf;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   588
    msg->msg_controllen = cbuf_size;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   589
    msg->msg_flags = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   590
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   591
    cmsg = CMSG_FIRSTHDR(msg);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   592
    cmsg->cmsg_level = IPPROTO_SCTP;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   593
    cmsg->cmsg_type = SCTP_SNDRCV;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   594
    cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   595
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   596
    /* Initialize the payload: */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   597
    sri = (struct sctp_sndrcvinfo*) CMSG_DATA(cmsg);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   598
    memset(sri, 0, sizeof (*sri));
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   599
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   600
    if (assocId > 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   601
        sri->sinfo_assoc_id = assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   602
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   603
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   604
    sri->sinfo_flags = sri->sinfo_flags | SCTP_EOF;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   605
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   606
    /* Sum of the length of all control messages in the buffer. */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   607
    msg->msg_controllen = cmsg->cmsg_len;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   608
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   609
    if ((rv = sendmsg(fd, msg, 0)) < 0) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   610
        handleSocketError(env, errno);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   611
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   612
}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   613
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   614
/*
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   615
 * Class:     sun_nio_ch_SctpNet
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   616
 * Method:    branch
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   617
 * Signature: (II)I
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   618
 */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   619
JNIEXPORT int JNICALL Java_sun_nio_ch_SctpNet_branch0
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   620
  (JNIEnv *env, jclass klass, jint fd, jint assocId) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   621
    int newfd = 0;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   622
    if ((newfd = nio_sctp_peeloff(fd, assocId)) < 0) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   623
        handleSocketError(env, errno);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   624
    }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   625
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   626
    return newfd;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   627
}