Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 728A92291 for ; Sat, 7 May 2011 06:31:33 +0000 (UTC) Received: (qmail 35779 invoked by uid 500); 7 May 2011 06:31:33 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 35515 invoked by uid 500); 7 May 2011 06:31:32 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 35507 invoked by uid 99); 7 May 2011 06:31:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 May 2011 06:31:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 May 2011 06:31:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2EB4A23889EC; Sat, 7 May 2011 06:31:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Sat, 07 May 2011 06:31:06 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110507063106.2EB4A23889EC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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);