apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gerry <ge...@everythingsucks.co.uk>
Subject inet_addr() ?
Date Mon, 14 Nov 2005 13:59:53 GMT
Guys,

Doing an apache2 module for Set Top Box socket proxying over HTTP.

I'm trying to stick to APR calls instead of posix calls, but there doesn't
appear to be an equivelant of inet_addr().

So I'm finding myself going through the motions of using a bunch of
APR calls to do the equivelant of gethostbyname() giving me out the IP address
in a char* but can't get get a uint32 without resorting to inet_addr().

I've grepped the apache2 code it seems to me like there's never an int IP
exposed, everything is apr_sockaddr_t's.

Thoughts ?

----// SNIP //----

static uint _service_getInetAddress( Service* service )
{
  uint           addr;

  addr = service->ipaddress;

  if ( addr == INETADDR_NEEDED ) {
    apr_status_t    rv;
    apr_pool_t     *p         = NULL;
    apr_sockaddr_t *myaddr    = NULL;
    char           *ip        = NULL;

    rv = apr_pool_create( &p, manager.pool );
    if ( !APR_STATUS_IS_SUCCESS( rv ) ) {
      logError( "Cannot allocate subpool to lookup hostname %s", service->host
);
    }

    if ( APR_STATUS_IS_SUCCESS( rv ) &&
        !APR_STATUS_IS_SUCCESS( rv = apr_sockaddr_info_get(&myaddr,
service->host, APR_UNSPEC, 0, 0, p) ) ) {
      logDebug( "Cannot resolve host name %s --- ignoring!", service->host );
    }

    if ( APR_STATUS_IS_SUCCESS( rv ) &&
        !APR_STATUS_IS_SUCCESS (rv = apr_sockaddr_ip_get( &ip, myaddr ) ) ) {
      logDebug( "Cannot get IP from sockaddr_t structure from %s --- ignoring!",
service->host );
    }

    if ( !APR_STATUS_IS_SUCCESS( rv ) ) {
      if ( p ) apr_pool_destroy( p );
      return INETADDR_INVALID;
    }

    addr = inet_addr( ip );
    if ( addr == 0 ) addr = INETADDR_INVALID;
    ip = NULL;

    service->ipaddress = addr;

    apr_pool_destroy( p );
  }

  return addr;
}

----// SNIP //----


Mime
View raw message