You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Learning apr <le...@hotmail.co.uk> on 2008/04/02 13:44:50 UTC

How can I get the local host IP address

Hello,

I hope to get the local host IP address, but I can not find the appropriated functions.

Please help me.

Thanks!

_________________________________________________________________
Connect to the next generation of MSN Messenger 
http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline

Could not get IP address with the function apr_sockaddr_ip_get

Posted by Learning apr <le...@hotmail.co.uk>.
   Hello,

    I hope to get the local host address by following codes. But I could not get it in the variable "ipAdd".

    Please help me.
    Thanks!

    char hostName[APRMAXHOSTLEN + 1];
    apr_sockaddr_t *sa;
    apr_pool_t *pool;
    char ipAdd[20];

    apr_pool_create(&pool, 0);
    apr_gethostname(hostName, APRMAXHOSTLEN + 1, NULL);
    apr_sockaddr_info_get(&sa, hostName,APR_INET, 0, 0, pool);
    memset(ipAdd, 0, 20);
    apr_sockaddr_ip_get(&ipAdd, sa);
    apr_pool_destroy(pool);

_________________________________________________________________
Explore the seven wonders of the world
http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE