src/solaris/native/sun/nio/ch/Net.c
Print this page
rev 8725 : 8024854: Basic changes and files to build the class library on AIX
Contributed-by: luchsh@linux.vnet.ibm.com, spoole@linux.vnet.ibm.com, thomas.stuefe@sap.com
Reviewed-by: alanb, prr, sla, chegar, michaelm, mullan
*** 1,7 ****
/*
! * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 38,47 ****
--- 38,50 ----
#include "net_util_md.h"
#include "nio_util.h"
#include "nio.h"
#include "sun_nio_ch_PollArrayWrapper.h"
+ #ifdef _AIX
+ #include <sys/utsname.h>
+ #endif
/**
* IP_MULTICAST_ALL supported since 2.6.31 but may not be available at
* build time.
*/
*** 49,76 ****
#ifndef IP_MULTICAST_ALL
#define IP_MULTICAST_ALL 49
#endif
#endif
! #ifdef _ALLBSD_SOURCE
#ifndef IP_BLOCK_SOURCE
#define IP_ADD_SOURCE_MEMBERSHIP 70 /* join a source-specific group */
#define IP_DROP_SOURCE_MEMBERSHIP 71 /* drop a single source */
#define IP_BLOCK_SOURCE 72 /* block a source */
#define IP_UNBLOCK_SOURCE 73 /* unblock a source */
#endif /* IP_BLOCK_SOURCE */
#ifndef MCAST_BLOCK_SOURCE
#define MCAST_JOIN_SOURCE_GROUP 82 /* join a source-specific group */
#define MCAST_LEAVE_SOURCE_GROUP 83 /* leave a single source */
#define MCAST_BLOCK_SOURCE 84 /* block a source */
#define MCAST_UNBLOCK_SOURCE 85 /* unblock a source */
#endif /* MCAST_BLOCK_SOURCE */
#ifndef IPV6_ADD_MEMBERSHIP
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
--- 52,101 ----
#ifndef IP_MULTICAST_ALL
#define IP_MULTICAST_ALL 49
#endif
#endif
! #if defined(_ALLBSD_SOURCE) || defined(_AIX)
#ifndef IP_BLOCK_SOURCE
+ #if defined(_AIX)
+
+ #define IP_BLOCK_SOURCE 58 /* Block data from a given source to a given group */
+ #define IP_UNBLOCK_SOURCE 59 /* Unblock data from a given source to a given group */
+ #define IP_ADD_SOURCE_MEMBERSHIP 60 /* Join a source-specific group */
+ #define IP_DROP_SOURCE_MEMBERSHIP 61 /* Leave a source-specific group */
+
+ #else
+
#define IP_ADD_SOURCE_MEMBERSHIP 70 /* join a source-specific group */
#define IP_DROP_SOURCE_MEMBERSHIP 71 /* drop a single source */
#define IP_BLOCK_SOURCE 72 /* block a source */
#define IP_UNBLOCK_SOURCE 73 /* unblock a source */
+ #endif /* _AIX */
+
#endif /* IP_BLOCK_SOURCE */
#ifndef MCAST_BLOCK_SOURCE
+ #if defined(_AIX)
+
+ #define MCAST_BLOCK_SOURCE 64
+ #define MCAST_UNBLOCK_SOURCE 65
+ #define MCAST_JOIN_SOURCE_GROUP 66
+ #define MCAST_LEAVE_SOURCE_GROUP 67
+
+ #else
+
#define MCAST_JOIN_SOURCE_GROUP 82 /* join a source-specific group */
#define MCAST_LEAVE_SOURCE_GROUP 83 /* leave a single source */
#define MCAST_BLOCK_SOURCE 84 /* block a source */
#define MCAST_UNBLOCK_SOURCE 85 /* unblock a source */
+ #endif /* _AIX */
+
#endif /* MCAST_BLOCK_SOURCE */
#ifndef IPV6_ADD_MEMBERSHIP
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
*** 121,130 ****
--- 146,185 ----
sin6->sin6_family = AF_INET6;
COPY_INET6_ADDRESS(env, source, (jbyte*)&(sin6->sin6_addr));
}
#endif
+ #ifdef _AIX
+
+ /*
+ * Checks whether or not "socket extensions for multicast source filters" is supported.
+ * Returns JNI_TRUE if it is supported, JNI_FALSE otherwise
+ */
+ static jboolean isSourceFilterSupported(){
+ static jboolean alreadyChecked = JNI_FALSE;
+ static jboolean result = JNI_TRUE;
+ if (alreadyChecked != JNI_TRUE){
+ struct utsname uts;
+ memset(&uts, 0, sizeof(uts));
+ strcpy(uts.sysname, "?");
+ const int utsRes = uname(&uts);
+ int major = -1;
+ int minor = -1;
+ major = atoi(uts.version);
+ minor = atoi(uts.release);
+ if (strcmp(uts.sysname, "AIX") == 0) {
+ if (major < 6 || (major == 6 && minor < 1)) {// unsupported on aix < 6.1
+ result = JNI_FALSE;
+ }
+ }
+ alreadyChecked = JNI_TRUE;
+ }
+ return result;
+ }
+
+ #endif /* _AIX */
+
JNIEXPORT void JNICALL
Java_sun_nio_ch_Net_initIDs(JNIEnv *env, jclass clazz)
{
/* Here because Windows native code does need to init IDs */
}
*** 473,482 ****
--- 528,545 ----
} else {
#ifdef MACOSX
/* no IPv4 include-mode filtering for now */
return IOS_UNAVAILABLE;
#else
+
+ #ifdef _AIX
+ /* check AIX for support of source filtering */
+ if (isSourceFilterSupported() != JNI_TRUE){
+ return IOS_UNAVAILABLE;
+ }
+ #endif
+
mreq_source.imr_multiaddr.s_addr = htonl(group);
mreq_source.imr_sourceaddr.s_addr = htonl(source);
mreq_source.imr_interface.s_addr = htonl(interf);
opt = (join) ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP;
optval = (void*)&mreq_source;
*** 484,494 ****
#endif
}
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, optval, optlen);
if (n < 0) {
! if (join && (errno == ENOPROTOOPT))
return IOS_UNAVAILABLE;
handleSocketError(env, errno);
}
return 0;
}
--- 547,557 ----
#endif
}
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, optval, optlen);
if (n < 0) {
! if (join && (errno == ENOPROTOOPT || errno == EOPNOTSUPP))
return IOS_UNAVAILABLE;
handleSocketError(env, errno);
}
return 0;
}
*** 503,520 ****
#else
struct my_ip_mreq_source mreq_source;
int n;
int opt = (block) ? IP_BLOCK_SOURCE : IP_UNBLOCK_SOURCE;
mreq_source.imr_multiaddr.s_addr = htonl(group);
mreq_source.imr_sourceaddr.s_addr = htonl(source);
mreq_source.imr_interface.s_addr = htonl(interf);
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt,
(void*)&mreq_source, sizeof(mreq_source));
if (n < 0) {
! if (block && (errno == ENOPROTOOPT))
return IOS_UNAVAILABLE;
handleSocketError(env, errno);
}
return 0;
#endif
--- 566,590 ----
#else
struct my_ip_mreq_source mreq_source;
int n;
int opt = (block) ? IP_BLOCK_SOURCE : IP_UNBLOCK_SOURCE;
+ #ifdef _AIX
+ /* check AIX for support of source filtering */
+ if (isSourceFilterSupported() != JNI_TRUE){
+ return IOS_UNAVAILABLE;
+ }
+ #endif
+
mreq_source.imr_multiaddr.s_addr = htonl(group);
mreq_source.imr_sourceaddr.s_addr = htonl(source);
mreq_source.imr_interface.s_addr = htonl(interf);
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt,
(void*)&mreq_source, sizeof(mreq_source));
if (n < 0) {
! if (block && (errno == ENOPROTOOPT || errno == EOPNOTSUPP))
return IOS_UNAVAILABLE;
handleSocketError(env, errno);
}
return 0;
#endif
*** 548,558 ****
#endif
}
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, optval, optlen);
if (n < 0) {
! if (join && (errno == ENOPROTOOPT))
return IOS_UNAVAILABLE;
handleSocketError(env, errno);
}
return 0;
#else
--- 618,628 ----
#endif
}
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, optval, optlen);
if (n < 0) {
! if (join && (errno == ENOPROTOOPT || errno == EOPNOTSUPP))
return IOS_UNAVAILABLE;
handleSocketError(env, errno);
}
return 0;
#else
*** 577,587 ****
initGroupSourceReq(env, group, index, source, &req);
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt,
(void*)&req, sizeof(req));
if (n < 0) {
! if (block && (errno == ENOPROTOOPT))
return IOS_UNAVAILABLE;
handleSocketError(env, errno);
}
return 0;
#endif
--- 647,657 ----
initGroupSourceReq(env, group, index, source, &req);
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt,
(void*)&req, sizeof(req));
if (n < 0) {
! if (block && (errno == ENOPROTOOPT || errno == EOPNOTSUPP))
return IOS_UNAVAILABLE;
handleSocketError(env, errno);
}
return 0;
#endif