You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by David Reid <dr...@jetnet.co.uk> on 2000/11/10 19:48:36 UTC

APR'ize code...

This code needs to be changed to use apr functions.  It's quite apache
specific so I'm not sure it belongs in APR, but I don't think we have the
functions in APR to let us apr'ize it at the moment...

Basically I'm looking at removing the sockaddr's from the conn_rec as they
shouldn't be there in a multi-protocol system and they are duplicates of
what is in the socket structure anyway.  This function will be one of the
stumbling blocks...

Any ideas?

david

/* Code from Harald Hanche-Olsen <ha...@imf.unit.no> */
static apr_inline void do_double_reverse (conn_rec *conn)
{
    struct hostent *hptr;

    if (conn->double_reverse) {
	/* already done */
	return;
    }
    if (conn->remote_host == NULL || conn->remote_host[0] == '\0') {
	/* single reverse failed, so don't bother */
	conn->double_reverse = -1;
	return;
    }
    hptr = gethostbyname(conn->remote_host);
    if (hptr)

	char **haddr;

	for (haddr = hptr->h_addr_list; *haddr; haddr++) {
	    if (((struct in_addr *)(*haddr))->s_addr
		== conn->remote_addr.sin_addr.s_addr) {
		conn->double_reverse = 1;
		return;
	    }
	}
    }
    conn->double_reverse = -1;
}



Re: APR'ize code...

Posted by Jeff Trawick <tr...@bellsouth.net>.
"David Reid" <dr...@jetnet.co.uk> writes:

> This code needs to be changed to use apr functions.  It's quite apache
> specific so I'm not sure it belongs in APR, but I don't think we have the
> functions in APR to let us apr'ize it at the moment...

You could have something like

  apr_check_reverse_lookup(apr_socket_t *sock)

It could first do reverse lookup to find the name from the remote IP
address (unless already performed, in which case it would be cached
inside the apr_sockaddr_t of the peer), then do normal lookup on the
resulting hostname and ensure that the original IP address matches one
of the IP addresses returned from the normal lookup...

(I'm not sure that you intended to use apr_sockaddr_t inside
apr_socket_t, but doing so give us a place to cache a reverse
lookup which in turn eliminates the need to cache the reverse lookup
in conn_rec->remote_host.)
-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Re: APR'ize code...

Posted by rb...@covalent.net.
Let's look at what we would need in APR to support this function, and make
those functions.  :-)

>     hptr = gethostbyname(conn->remote_host);

We should definately have a gethostbyname-like function.  This also solves
the thread-safeness issues surrounding this function.

> 	for (haddr = hptr->h_addr_list; *haddr; haddr++) {
> 	    if (((struct in_addr *)(*haddr))->s_addr
> 		== conn->remote_addr.sin_addr.s_addr) {
> 		conn->double_reverse = 1;
> 		return;

This is a simple comparison that we could create a simple function for,
but that seems like a bit of overkill.

Why not just create a simple APR function, apr_do_double_reverse?  A
double reverse lookup is a relatively standard function for any daemon
program.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------