You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Gerry <ge...@everythingsucks.co.uk> on 2005/11/14 14:59:53 UTC

inet_addr() ?

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 //----


Re: inet_addr() ?

Posted by Jeff Trawick <tr...@gmail.com>.
On 11/14/05, Gerry <ge...@everythingsucks.co.uk> wrote:
> 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().

If your app needs to have detailed IP info (and possibly impose
restrictions), then it can look in the union sa in the apr_sockaddr_t
returned by apr_sockaddr_info_get().