7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux
authorchegar
Fri, 10 Dec 2010 10:47:21 +0000
changeset 7545 409091945418
parent 7544 85a0e84bb9a0
child 7546 c1915029b924
7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux Summary: IPv4 addrs passed to SCTP_SET_PEER_PRIMARY_ADDR should not be converted to IPv4-mapped addrs Reviewed-by: michaelm
jdk/src/solaris/classes/sun/nio/ch/SctpNet.java
jdk/src/solaris/native/sun/nio/ch/SctpNet.c
jdk/test/com/sun/nio/sctp/SctpChannel/SocketOptionTests.java
--- a/jdk/src/solaris/classes/sun/nio/ch/SctpNet.java	Thu Dec 09 13:01:14 2010 -0500
+++ b/jdk/src/solaris/classes/sun/nio/ch/SctpNet.java	Fri Dec 10 10:47:21 2010 +0000
@@ -43,7 +43,7 @@
 
     /* -- Miscellaneous SCTP utilities -- */
 
-    static boolean bindxIPv4MappedAddresses() {
+    private static boolean IPv4MappedAddresses() {
         if ("SunOS".equals(osName)) {
             /* Solaris supports IPv4Mapped Addresses with bindx */
             return true;
@@ -87,7 +87,7 @@
     static void bindx(int fd, InetAddress[] addrs, int port, boolean add)
             throws IOException {
         bindx(fd, addrs, port, addrs.length, add,
-                bindxIPv4MappedAddresses());
+                IPv4MappedAddresses());
     }
 
     static Set<SocketAddress> getLocalAddresses(int fd)
@@ -145,11 +145,16 @@
             InetSocketAddress netAddr = (InetSocketAddress)addr;
 
             if (name.equals(SCTP_PRIMARY_ADDR)) {
-                setPrimAddrOption0(fd, assocId,
-                        netAddr.getAddress(), netAddr.getPort());
+                setPrimAddrOption0(fd,
+                                   assocId,
+                                   netAddr.getAddress(),
+                                   netAddr.getPort());
             } else {
-                setPeerPrimAddrOption0(fd, assocId,
-                        netAddr.getAddress(), netAddr.getPort());
+                setPeerPrimAddrOption0(fd,
+                                       assocId,
+                                       netAddr.getAddress(),
+                                       netAddr.getPort(),
+                                       IPv4MappedAddresses());
             }
         } else if (name.equals(SCTP_DISABLE_FRAGMENTS) ||
             name.equals(SCTP_EXPLICIT_COMPLETE) ||
@@ -290,7 +295,7 @@
             int port) throws IOException;
 
     static native void setPeerPrimAddrOption0(int fd, int assocId,
-            InetAddress ia, int port) throws IOException;
+            InetAddress ia, int port, boolean preferIPv6) throws IOException;
 
     static native SocketAddress getPrimAddrOption0(int fd, int assocId)
             throws IOException;
--- a/jdk/src/solaris/native/sun/nio/ch/SctpNet.c	Thu Dec 09 13:01:14 2010 -0500
+++ b/jdk/src/solaris/native/sun/nio/ch/SctpNet.c	Fri Dec 10 10:47:21 2010 +0000
@@ -617,18 +617,18 @@
  * Signature: (IILjava/net/InetAddress;I)V
  */
 JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setPeerPrimAddrOption0
-  (JNIEnv *env, jclass klass, jint fd, jint assocId, jobject iaObj, jint port) {
+  (JNIEnv *env, jclass klass, jint fd, jint assocId,
+   jobject iaObj, jint port, jboolean preferIPv6) {
     struct sctp_setpeerprim prim;
-    struct sockaddr_storage ss;
-    int ss_len = sizeof(ss);
+    struct sockaddr* sap = (struct sockaddr*)&prim.sspp_addr;
+    int sap_len;
 
-    if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&ss,
-                                  &ss_len, JNI_TRUE) != 0) {
+    if (NET_InetAddressToSockaddr(env, iaObj, port, sap,
+                                  &sap_len, preferIPv6) != 0) {
         return;
     }
 
     prim.sspp_assoc_id = assocId;
-    prim.sspp_addr = ss;
 
     if (setsockopt(fd, IPPROTO_SCTP, SCTP_SET_PEER_PRIMARY_ADDR, &prim,
             sizeof(prim)) < 0) {
--- a/jdk/test/com/sun/nio/sctp/SctpChannel/SocketOptionTests.java	Thu Dec 09 13:01:14 2010 -0500
+++ b/jdk/test/com/sun/nio/sctp/SctpChannel/SocketOptionTests.java	Fri Dec 10 10:47:21 2010 +0000
@@ -188,6 +188,7 @@
             }
             check(found, "SCTP_PRIMARY_ADDR returned bogus address!");
 
+            System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet);
             sc.setOption(SCTP_PRIMARY_ADDR, addrToSet);
             System.out.println("SCTP_PRIMARY_ADDR set to: " + addrToSet);
             primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);