You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/05/07 08:31:06 UTC
svn commit: r1100461 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/net/SocketAddress.java
native/include/acr/netapi.h native/shared/netaddr.c
Author: mturk
Date: Sat May 7 06:31:05 2011
New Revision: 1100461
URL: http://svn.apache.org/viewvc?rev=1100461&view=rev
Log:
Move param checks to java code
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h
commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java?rev=1100461&r1=1100460&r2=1100461&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java Sat May 7 06:31:05 2011
@@ -80,6 +80,11 @@ public abstract class SocketAddress exte
NetworkException
{
super(family);
+ if (family == AddressFamily.LOCAL)
+ throw new InvalidArgumentException();
+ int masked = flags & (IPV4_ADDR_OK | IPV6_ADDR_OK);
+ if (host == null || family != AddressFamily.UNSPEC || masked == (IPV4_ADDR_OK | IPV6_ADDR_OK))
+ throw new InvalidArgumentException();
super.sa = sockaddr0(host, family.valueOf(), port, flags);
}
@@ -88,6 +93,8 @@ public abstract class SocketAddress exte
NetworkException
{
super(family);
+ if (family == AddressFamily.LOCAL)
+ throw new InvalidArgumentException();
super.sa = sockaddr0(host, family.valueOf(), 0, 0);
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h?rev=1100461&r1=1100460&r2=1100461&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h Sat May 7 06:31:05 2011
@@ -23,6 +23,22 @@
typedef struct acr_sockaddr_t acr_sockaddr_t;
struct acr_sockaddr_t {
+ /** Union of either IPv4 or IPv6 sockaddr. */
+ union {
+ /** IPv4 sockaddr structure */
+ struct sockaddr_in sin;
+ /** IPv6 sockaddr structure */
+ struct sockaddr_in6 sin6;
+#if HAVE_SOCKADDR_STORAGE
+ /** Placeholder to ensure that the size of this union is not
+ * dependent on whether APR_HAVE_IPV6 is defined. */
+ struct sockaddr_storage sas;
+#endif
+#if HAVE_SYS_UN_H
+ /** Unix domain socket sockaddr structure */
+ struct sockaddr_un unx;
+#endif
+ } sa;
/** The hostname */
char hostname[NI_MAXHOST];
/** Either a string of the port number or the service name for the port */
@@ -40,28 +56,12 @@ struct acr_sockaddr_t {
int addrlen;
/**
* If multiple addresses were found by AcrGetSockaddrInfo(),
- * this points to a number of the next address.
+ * this points to a number of the address.
*/
int addrcnt;
/** This points to the IP address structure within the appropriate
* sockaddr structure. */
void *ipaddr;
- /** Union of either IPv4 or IPv6 sockaddr. */
- union {
- /** IPv4 sockaddr structure */
- struct sockaddr_in sin;
- /** IPv6 sockaddr structure */
- struct sockaddr_in6 sin6;
-#if HAVE_SOCKADDR_STORAGE
- /** Placeholder to ensure that the size of this union is not
- * dependent on whether APR_HAVE_IPV6 is defined. */
- struct sockaddr_storage sas;
-#endif
-#if HAVE_SYS_UN_H
- /** Unix domain socket sockaddr structure */
- struct sockaddr_un unx;
-#endif
- } sa;
};
#ifdef __cplusplus
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c?rev=1100461&r1=1100460&r2=1100461&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Sat May 7 06:31:05 2011
@@ -547,7 +547,7 @@ call_resolver(acr_sockaddr_t **sa, const
*/
return ACR_ENOENT;
}
- new_sa = calloc(1, ai_len * ai_cnt);
+ new_sa = calloc(ai_len, ai_cnt);
if (sa == 0)
return ACR_ENOMEM;
ai = ai_list;
@@ -824,7 +824,7 @@ ACR_NET_EXPORT(jbyteArray, LocalEndpoint
jbyteArray ba;
acr_sockaddr_t sa;
char *np;
- int rc = ACR_EINVAL;
+ int rc = ACR_ENOTIMPL;
memset(&sa, 0, sizeof(acr_sockaddr_t));
WITH_CSTR(hostname) {
@@ -863,8 +863,6 @@ ACR_NET_EXPORT(jbyteArray, LocalEndpoint
sa.ipaddr = &(sa.hostname);
sa.iplen = sa.addrlen;
rc = 0;
-#else
- rc = ACR_ENOTIMPL;
#endif
} DONE_WITH_STR(hostname);
@@ -967,9 +965,8 @@ ACR_NET_EXPORT(jbyteArray, SocketAddress
jint family, jint port, jint flags)
{
acr_sockaddr_t *sa = 0;
- int ffamily = AF_UNSPEC;
+ int ffamily;
int rc = 0;
- int masked;
switch (family) {
case 1:
@@ -978,21 +975,10 @@ ACR_NET_EXPORT(jbyteArray, SocketAddress
case 2:
ffamily = AF_INET6;
break;
- case 3:
- rc = ACR_EINVAL;
+ default:
+ ffamily = AF_UNSPEC;
break;
}
- /* TODO: Move the param checks to java code
- */
- if ((masked = flags & (ACR_IPV4_ADDR_OK | ACR_IPV6_ADDR_OK))) {
- if (hostname == 0 || family != AF_UNSPEC ||
- masked == (ACR_IPV4_ADDR_OK | ACR_IPV6_ADDR_OK))
- rc = ACR_EINVAL;
- }
- if (rc != 0) {
- ACR_THROW_NET_ERROR(rc);
- return 0;
- }
WITH_CSTR(hostname) {
rc = AcrFindAddresses(&sa, J2S(hostname), ffamily, port, flags);
} DONE_WITH_STR(hostname);