|
1 | 1 | /*
|
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * 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,
|
1837 | 1837 | jint fd;
|
1838 | 1838 | jint family;
|
1839 | 1839 | jint ipv6_join_leave;
|
| 1840 | + int res; |
1840 | 1841 |
|
1841 | 1842 | if (IS_NULL(fdObj)) {
|
1842 | 1843 | JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
@@ -1993,9 +1994,17 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
|
1993 | 1994 | /*
|
1994 | 1995 | * Join the multicast group.
|
1995 | 1996 | */
|
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); |
1998 | 1999 |
|
| 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) { |
1999 | 2008 | /*
|
2000 | 2009 | * If IP_ADD_MEMBERSHIP returns ENOPROTOOPT on Linux and we've got
|
2001 | 2010 | * 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,
|
2096 | 2105 | #endif
|
2097 | 2106 |
|
2098 | 2107 | /* 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)); |
2101 | 2110 |
|
| 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) { |
2102 | 2118 | if (join) {
|
2103 | 2119 | NET_ThrowCurrent(env, "setsockopt " S_ADD_MEMBERSHIP " failed");
|
2104 | 2120 | } else {
|
|
0 commit comments