提交 be15e466 编写于 作者: C chegar

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
上级 52500910
......@@ -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;
......
......@@ -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) {
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册