apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r1541078 - in /apr/apr/branches/1.5.x: ./ CHANGES include/apr_network_io.h network_io/unix/sockaddr.c test/testsock.c
Date Tue, 12 Nov 2013 14:26:23 GMT
Author: trawick
Date: Tue Nov 12 14:26:22 2013
New Revision: 1541078

URL: http://svn.apache.org/r1541078
Log:
Merge r1541061 from trunk:

add apr_sockaddr_is_wildcard() API

Modified:
    apr/apr/branches/1.5.x/   (props changed)
    apr/apr/branches/1.5.x/CHANGES
    apr/apr/branches/1.5.x/include/apr_network_io.h
    apr/apr/branches/1.5.x/network_io/unix/sockaddr.c
    apr/apr/branches/1.5.x/test/testsock.c

Propchange: apr/apr/branches/1.5.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r1541061

Modified: apr/apr/branches/1.5.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/CHANGES?rev=1541078&r1=1541077&r2=1541078&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.5.x/CHANGES [utf-8] Tue Nov 12 14:26:22 2013
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 1.5.0
 
+  *) Add apr_sockaddr_is_wildcard() to check if a socket address
+     refers to the wildcard address for the protocol family (e.g.,
+     0.0.0.0/INADDR_ANY for IPv4).  [Jeff Trawick]
+
   *) apr_file_dup2() on Windows: Fix debug RTL assertion in when 
      attempting to _commit(stdout) or _commit(stderr).  [Mike Rumph
      <mike.rumph oracle.com>]

Modified: apr/apr/branches/1.5.x/include/apr_network_io.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/include/apr_network_io.h?rev=1541078&r1=1541077&r2=1541078&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/include/apr_network_io.h (original)
+++ apr/apr/branches/1.5.x/include/apr_network_io.h Tue Nov 12 14:26:22 2013
@@ -721,6 +721,16 @@ APR_DECLARE(int) apr_sockaddr_equal(cons
                                     const apr_sockaddr_t *addr2);
 
 /**
+ * See if the IP address in an APR socket address refers to the wildcard
+ * address for the protocol family (e.g., INADDR_ANY for IPv4).
+ *
+ * @param addr The APR socket address to examine.
+ * @remark The return value will be non-zero if the address is
+ * initialized and is the wildcard address.
+ */
+APR_DECLARE(int) apr_sockaddr_is_wildcard(const apr_sockaddr_t *addr);
+
+/**
 * Return the type of the socket.
 * @param sock The socket to query.
 * @param type The returned type (e.g., SOCK_STREAM).

Modified: apr/apr/branches/1.5.x/network_io/unix/sockaddr.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/network_io/unix/sockaddr.c?rev=1541078&r1=1541077&r2=1541078&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/network_io/unix/sockaddr.c (original)
+++ apr/apr/branches/1.5.x/network_io/unix/sockaddr.c Tue Nov 12 14:26:22 2013
@@ -839,6 +839,35 @@ APR_DECLARE(int) apr_sockaddr_equal(cons
     return 0; /* not equal */
 }
 
+APR_DECLARE(int) apr_sockaddr_is_wildcard(const apr_sockaddr_t *addr)
+{
+    static const char inaddr_any[
+#if APR_HAVE_IPV6
+        sizeof(struct in6_addr)
+#else
+        sizeof(struct in_addr)
+#endif
+    ] = {0};
+
+    if (addr->ipaddr_ptr /* IP address initialized */
+        && addr->ipaddr_len <= sizeof inaddr_any) { /* else bug elsewhere?
*/
+        if (!memcmp(inaddr_any, addr->ipaddr_ptr, addr->ipaddr_len)) {
+            return 1;
+        }
+#if APR_HAVE_IPV6
+    if (addr->family == AF_INET6
+        && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)addr->ipaddr_ptr)) {
+        struct in_addr *v4 = (struct in_addr *)&((apr_uint32_t *)addr->ipaddr_ptr)[3];
+
+        if (!memcmp(inaddr_any, v4, sizeof *v4)) {
+            return 1;
+        }
+    }
+#endif
+    }
+    return 0;
+}
+
 static apr_status_t parse_network(apr_ipsubnet_t *ipsub, const char *network)
 {
     /* legacy syntax for ip addrs: a.b.c. ==> a.b.c.0/24 for example */

Modified: apr/apr/branches/1.5.x/test/testsock.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/test/testsock.c?rev=1541078&r1=1541077&r2=1541078&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/test/testsock.c (original)
+++ apr/apr/branches/1.5.x/test/testsock.c Tue Nov 12 14:26:22 2013
@@ -67,14 +67,21 @@ static void test_addr_info(abts_case *tc
 {
     apr_status_t rv;
     apr_sockaddr_t *sa;
+    int rc;
 
     rv = apr_sockaddr_info_get(&sa, NULL, APR_UNSPEC, 80, 0, p);
     APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv);
 
+    rc = apr_sockaddr_is_wildcard(sa);
+    ABTS_INT_NEQUAL(tc, 0, rc);
+
     rv = apr_sockaddr_info_get(&sa, "127.0.0.1", APR_UNSPEC, 80, 0, p);
     APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv);
     ABTS_STR_EQUAL(tc, "127.0.0.1", sa->hostname);
 
+    rc = apr_sockaddr_is_wildcard(sa);
+    ABTS_INT_EQUAL(tc, 0, rc);
+
     rv = apr_sockaddr_info_get(&sa, "127.0.0.1", APR_UNSPEC, 0, 0, p);
     APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv);
     ABTS_STR_EQUAL(tc, "127.0.0.1", sa->hostname);
@@ -318,6 +325,10 @@ static void test_print_addr(abts_case *t
     if (rv == APR_SUCCESS && sa) {
         /* sa should now be a v4-mapped IPv6 address. */
         char buf[128];
+        int rc;
+
+        rc = apr_sockaddr_is_wildcard(sa);
+        ABTS_INT_NEQUAL(tc, 0, rc);
 
         memset(buf, 'z', sizeof buf);
         



Mime
View raw message