[OK, I'm getting better at this Reply To All stuff...]

> > 1.  Modify connect to take an apr_sockaddr_t instead of a hostname...
This
> > is a simple change so I'll make it sooner rather than later.
>
> yes...

OK, I've done some work on this but am getting an error now
Could not connect: Can't assign requested address (49)

I've got to drive to Suffolk in a short while so I'll post the patch at the
end of this message and let someone else figure out where I've screwed up!
:)

>
> > ??? Do we change apr_gethostbyname to return an apr_sockaddr_t?
>
> yes...
>
> > This would then give
> >     apr_sockaddr_t *sa;
> >     apr_gethostbyname(&sa, "hostname", pool);
> >     apr_connect(sock, sa);
>
> We need to add more arguments: address family for sure and possibly
> flags.  Look at getaddrinfo().  And do we want to add an optional
> service name/port number parameter?  That would build the complete
> sockaddr for us.

OK.  Care to suggest the definition?

>
> > 2. Are we agreed on Jeff's suggestions of
> > Add apr_pool_t * to apr_sockaddr_t.
> > apr_status_t apr_get_address(char **hostname, apr_interface_e which,
> > apr_socket_t *sock);
> > apr_status_t apr_get_nas(char **addr, apr_sockaddr_t *sa);
> > These are new additions sos houldn't interfere with any existing
> > code.
>
> I am.

Good.

>
> In addition to the changes you mentioned, I see apr_create_socket() as
> extremely important in the short run and I think we should think about
> apr_bind() working like apr_connect() (in other words, taking an
> apr_sockaddr_t).  That makes sense when the user has told us the local
> interface address and we have to resolve it anyway.  We have to keep
> it from being painful when we just have the port number.

OK, so again care to suggest the API definitions?

>
> > 3. Before we can take this further, I guess we need to add the following
> > though...
>
> I'll let others comment on this stuff.  I'm much more concerned about
> getting enough IPv6 enabled in APR so we can test it properly.  Apache
> needs can come a little later (for me, at least).

Agreed in principal...  However, we are about to beta Apache 2.0 (I did wanr
that this change would screw things up a while back) so I'm not sure if the
timing is good for stopping apache building.  then again if we break it
they'll have to fix it... :)

david

Index: include/apr_network_io.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_network_io.h,v
retrieving revision 1.70
diff -u -r1.70 apr_network_io.h
--- include/apr_network_io.h    2000/11/16 01:51:33     1.70
+++ include/apr_network_io.h    2000/11/16 13:40:54
@@ -255,7 +255,7 @@
  *                 APR assumes that the sockaddr_in in the apr_socket is
  *                 completely filled out.
  */
-apr_status_t apr_connect(apr_socket_t *sock, const char *hostname);
+apr_status_t apr_connect(apr_socket_t *sock, apr_sockaddr_t *sa);

 /**
  * Get name of a machine we are currently connected to.


+apr_status_t apr_gethostbyname(apr_sockaddr_t **sa, const char *hostname,
apr_pool_t *p);

Modify apr_connect...

apr_status_t apr_connect(apr_socket_t *sock, apr_sockaddr_t *sa)
{
    if ((sock->socketdes < 0) || (!sock->remote_addr)) {
        return APR_ENOTSOCK;
    }

    if ((connect(sock->socketdes,
                 (const struct sockaddr *)&sa->sa.sin,
                 sa->sa_len) < 0) &&
        (errno != EINPROGRESS)) {
        return errno;
    }
    else {
        sock->remote_addr = sa;
        /* XXX IPv6 */
        if (sock->local_addr->sa.sin.sin_port == 0) {
            /* connect() got us an ephemeral port */
            sock->local_port_unknown = 1;
        }
        /* XXX IPv6 */
        if (sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
            /* not bound to specific local interface; connect() had to
assign
             * one for the socket
             */
            sock->local_interface_unknown = 1;
        }
#ifndef HAVE_POLL
        sock->connected=1;
#endif
        return APR_SUCCESS;
    }
}

This into sa_common.c

apr_status_t apr_gethostbyname(apr_sockaddr_t **sa, const char *hostname,
apr_pool_t *p)
{
    struct hostent *hp;

    (*sa) = (apr_sockaddr_t *)apr_pcalloc(p, sizeof(apr_sockaddr_t));
    if ((*sa) == NULL)
        return APR_ENOMEM;
    (*sa)->pool = p;
    (*sa)->sa.sin.sin_family = AF_INET; /* we don't yet support IPv6 */

    if (hostname != NULL) {
#ifndef GETHOSTBYNAME_HANDLES_NAS
        if (*hostname >= '0' && *hostname <= '9' &&
            strspn(hostname, "0123456789.") == strlen(hostname)) {
            (*sa)->sa.sin.sin_addr.s_addr = inet_addr(hostname);
            (*sa)->sa_len = sizeof(struct sockaddr_in);
        }
        else {
#endif
        hp = gethostbyname(hostname);

        if (!hp)  {
            return (h_errno + APR_OS_START_SYSERR);
        }

        /* XXX IPv6: move name resolution out of this function */
        memcpy((char *)&(*sa)->sa.sin.sin_addr, hp->h_addr_list[0],
               hp->h_length);
        (*sa)->sa_len = sizeof(struct sockaddr_in);
        (*sa)->ipaddr_len = hp->h_length;

#ifndef GETHOSTBYNAME_HANDLES_NAS
        }
#endif
    }
   (*sa)->hostname = apr_pstrdup(p, hostname);
    return APR_SUCCESS;
}



Index: test/client.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/test/client.c,v
retrieving revision 1.17
diff -u -r1.17 client.c
--- test/client.c       2000/11/09 15:01:35     1.17
+++ test/client.c       2000/11/16 13:36:45
@@ -73,6 +73,7 @@
     char *dest = "127.0.0.1";
     apr_port_t local_port, remote_port;
     apr_interval_time_t read_timeout = -1;
+    apr_sockaddr_t *destsa;

     setbuf(stdout, NULL);
     if (argc > 1) {
@@ -123,9 +124,18 @@
     }
     fprintf(stdout, "OK\n");

+    fprintf(stdout,"\tClient:  Making socket address...............");
+    if (apr_gethostbyname(&destsa, dest, context) != APR_SUCCESS){
+        apr_close_socket(sock);
+        fprintf(stdout, "Failed!\n");
+        fprintf(stdout, "Couldn't create a socket address structure for
%s\n", dest);
+        exit(-1);
+    }
+    fprintf(stdout,"OK\n");
+
     fprintf(stdout, "\tClient:  Connecting to socket.......");

-    stat = apr_connect(sock, dest);
+    stat = apr_connect(sock, destsa);

     if (stat != APR_SUCCESS) {
         apr_close_socket(sock);



Reply via email to