httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <trawi...@bellsouth.net>
Subject Re: [PATCH] apr_sockaddr_t & friends
Date Tue, 14 Nov 2000 14:55:24 GMT
"David Reid" <dreid@jetnet.co.uk> writes:

> /**
>  * Get the character network address of the IP address contained in the
> apr_sockaddr_t.
>  * @param addr The pointer to the returned string.
>  * @param sa The apr_sockaddr_t structure to use...
>  * @param p The apr_pool_t to use for memory allocations.
>  */
> apr_status_t apr_get_nas(char **addr, apr_sockaddr_t *sa, apr_pool_t *p);

We may or may not want a pool parameter here, depending on how it
should work.  If we want it to cache the numeric address string so
that apps don't need a separate field, the function would be something
like this:

  if (!sa->addr_str) {     /* gotta add this field to apr_sockaddr_t */
      sa->addr_str = apr_palloc(sa->pool, sa->addr_str_len);
      apr_inet_ntop(sa->sin.sin_family, sa->ipaddr_ptr,
                    sa->addr_str, sa->addr_str_len);
  }
  *addr = sa->addr_str;

> > I'm not sure what you mean...
> 
> I think that makes two of us.  Can you outline more of your API in detail?

for UDP?  something like this:

  apr_sendto(apr_socket_t *sock, apr_sockaddr_t *sa, apr_size_t *nbytes)
  {
      if (!sa) {
          sa = sock->remote_addr;
      }

      do {
          rc = sendto(sock->fd, &sa->sin, sa->sa_len);
      } while (rc == -1 && errno == EINTR);

      /* handle rc, nbytes, timeout here */
  }

  apr_recvfrom(apr_socket_t *sock, apr_sockaddr_t **newsa, apr_size_t *nbytes)
  {
      apr_sockaddr_t *sa;

      if (!**newsa) {
          use sock->remote_addr;
      }
      else {
          *newsa = apr_palloc(sock->pool, sock->sa_len);
          use new sa;
      }

      do {
          rc = recvfrom(sock->fd, &sa->sin, &sa->sa_len);
      } while (rc == -1 && errno == EINTR);

      /* handle rc, nbytes, timeout here */
  }

more comments on the set of routines in your current patch:

  apr_get_socket_inaddr(), apr_get_v4_address(), apr_inaddr_compare():

    replace these three routines with

      apr_get_ipaddr(apr_sockaddr_t *sa, char **ipaddr, apr_size_t *len,
                     apr_int32_t *family);

      This returns the address of the IP address within the
      sockaddr_in[6] and tells the caller the length and the family.

    I'm not sure we need the apr_in_addr_t data type at this point.

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Mime
View raw message