Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit d8a0582

Browse files
author
Mark Sheppard
committed
8265369: [macos-aarch64] java/net/MulticastSocket/Promiscuous.java failed with "SocketException: Cannot allocate memory"
Reviewed-by: dfuchs, michaelm, chegar
1 parent 21abcc4 commit d8a0582

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1837,6 +1837,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
18371837
jint fd;
18381838
jint family;
18391839
jint ipv6_join_leave;
1840+
int res;
18401841

18411842
if (IS_NULL(fdObj)) {
18421843
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -1993,9 +1994,17 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
19931994
/*
19941995
* Join the multicast group.
19951996
*/
1996-
if (setsockopt(fd, IPPROTO_IP, (join ? IP_ADD_MEMBERSHIP:IP_DROP_MEMBERSHIP),
1997-
(char *) &mname, mname_len) < 0) {
1997+
res = setsockopt(fd, IPPROTO_IP, (join ? IP_ADD_MEMBERSHIP:IP_DROP_MEMBERSHIP),
1998+
(char *) &mname, mname_len);
19981999

2000+
#ifdef __APPLE__
2001+
if (res < 0 && errno == ENOMEM) {
2002+
res = setsockopt(fd, IPPROTO_IP, (join ? IP_ADD_MEMBERSHIP:IP_DROP_MEMBERSHIP),
2003+
(char *) &mname, mname_len);
2004+
}
2005+
#endif
2006+
2007+
if (res < 0) {
19992008
/*
20002009
* If IP_ADD_MEMBERSHIP returns ENOPROTOOPT on Linux and we've got
20012010
* IPv6 enabled then it's possible that the kernel has been fixed
@@ -2096,9 +2105,16 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
20962105
#endif
20972106

20982107
/* Join the multicast group */
2099-
if (setsockopt(fd, IPPROTO_IPV6, (join ? ADD_MEMBERSHIP : DRP_MEMBERSHIP),
2100-
(char *) &mname6, sizeof (mname6)) < 0) {
2108+
res = setsockopt(fd, IPPROTO_IPV6, (join ? ADD_MEMBERSHIP : DRP_MEMBERSHIP),
2109+
(char *) &mname6, sizeof(mname6));
21012110

2111+
#ifdef __APPLE__
2112+
if (res < 0 && errno == ENOMEM) {
2113+
res = setsockopt(fd, IPPROTO_IPV6, (join ? ADD_MEMBERSHIP : DRP_MEMBERSHIP),
2114+
(char *) &mname6, sizeof(mname6));
2115+
}
2116+
#endif
2117+
if (res < 0) {
21022118
if (join) {
21032119
NET_ThrowCurrent(env, "setsockopt " S_ADD_MEMBERSHIP " failed");
21042120
} else {

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ java/net/MulticastSocket/SetGetNetworkInterfaceTest.java 8219083 windows-
606606

607607
java/net/ServerSocket/AcceptInheritHandle.java 8211854 aix-ppc64
608608

609-
java/net/MulticastSocket/Promiscuous.java 8265369 macosx-aarch64
610609

611610
############################################################################
612611

0 commit comments

Comments
 (0)