7004439: SCTP_SET_PEER_PRIMARY_ADDR throws SocketException on Linux

IPv4 addrs passed to SCTP_SET_PEER_PRIMARY_ADDR should not be converted to IPv4-mapped addrs

Reviewed-by: michaelm
This commit is contained in:
Chris Hegarty 2010-12-10 10:47:21 +00:00
parent b2516290d4
commit 458596deff
3 changed files with 19 additions and 13 deletions

View File

@ -43,7 +43,7 @@ public class SctpNet {
/* -- 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 @@ public class SctpNet {
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 @@ public class SctpNet {
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 @@ public class SctpNet {
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;

View File

@ -617,18 +617,18 @@ JNIEXPORT void JNICALL Java_sun_nio_ch_SctpNet_setPrimAddrOption0
* 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) {

View File

@ -188,6 +188,7 @@ public class SocketOptionTests {
}
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);