apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject Re: svn commit: r602176 - /apr/apr/trunk/network_io/unix/sockaddr.c
Date Tue, 11 Dec 2007 15:55:57 GMT
On Tue, Dec 11, 2007 at 05:21:03AM -0600, William Rowe wrote:
> Joe Orton wrote:
>> I'd rather just see a new flag added alongside the existing 
>> APR_IPV4_ADDR_* flags to make it explicit that this is a new and very 
>> different interface guarantee, APR_IPV6_ADDR_V4MAPPED maybe.
>
> Perhaps, but the flag existed and had no definition, so this really
> strikes me as a rational solution.  My 2c.

It's pretty horrid IMO: the existing APR_IPV?_ADDR_OK flags specify 
different *ordering* for the searches.  This overloads a different 
combination of input parameters to have an unrelated side-effect - 
forcing use of v4-mapped IPv6 addresses.

> Either the existing flag or a new flag, it doesn't seem like this can
> be resolved before 1.3.0.  Does anyone see a way to make the reciprocal
> sa-from-ip-and-inet6-family actually work before then?

No.  But given that new interfaces are needed can we just give up on 
hacking the resolver and fix the actual issue, i.e. allow duplication of 
the sockaddr object?  Something like this?

Index: network_io/unix/sockaddr.c
===================================================================
--- network_io/unix/sockaddr.c	(revision 603185)
+++ network_io/unix/sockaddr.c	(working copy)
@@ -588,6 +588,27 @@
     return find_addresses(sa, hostname, family, port, flags, p);
 }
 
+APR_DECLARE(apr_sockaddr_t *) apr_sockaddr_clone(const apr_sockaddr_t *old,
+                                                 apr_port_t port,
+                                                 apr_pool_t *p)
+{
+    apr_sockaddr_t *sa = apr_pmemdup(p, old, sizeof *sa);
+
+    sa->pool = p;
+    sa->next = NULL;
+    
+    if (sa->hostname) {
+        sa->hostname = apr_pstrdup(p, sa->hostname);
+    }
+    if (sa->servname) {
+        sa->servname = apr_pstrdup(p, sa->servname);
+    }
+
+    apr_sockaddr_vars_set(sa, old->family, port);
+
+    return sa;    
+}
+
 APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
                                           apr_sockaddr_t *sockaddr,
                                           apr_int32_t flags)
Index: include/apr_network_io.h
===================================================================
--- include/apr_network_io.h	(revision 603185)
+++ include/apr_network_io.h	(working copy)
@@ -696,6 +696,18 @@
 APR_DECLARE(int) apr_sockaddr_equal(const apr_sockaddr_t *addr1,
                                     const apr_sockaddr_t *addr2);
 
+/** Create a duplicate of a socket address structure.
+ * @param old Old socket address structure
+ * @param port Port to use in returned structure
+ * @return Duplicate socket address structure which varies only
+ * by the port specified.
+ * @note Available only in APR version 1.3.0 onwards.
+ */
+APR_DECLARE(apr_sockaddr_t *) apr_sockaddr_clone(const apr_sockaddr_t *old,
+                                                 apr_port_t port,
+                                                 apr_pool_t *p);
+
+
 /**
 * Return the type of the socket.
 * @param sock The socket to query.

Mime
View raw message