Obtaining the IP address of the machine

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 23, 2008 at 1:04 PM, Nigel Hsiung <nigelcz at hotmail.com> wrote:
>
> This worked for me -
>
> pj_in_addr hostip;
>
> pj_gethostip(&hostip);
> if (pj_gethostip(&hostip) == PJ_SUCCESS){
>      printf("my ip = %s", pj_inet_ntoa(hostip.sin_addr));
> }
>

Yep. Or with the latest version where the function has been modified
to support IPv6:

 #include <pj/addr_resolv.h>

 pj_sockaddr addr;
 int af;

 af = pj_AF_INET();  // or pj_AF_INET6 for IPv6

 if (pj_gethostip(af, &addr) == PJ_SUCCESS) {
    char ipaddr[PJ_INET6_ADDRSTRLEN];

    printf("my ip=%s\n",
            pj_sockaddr_print(&addr, ipaddr, sizeof(ipaddr), 0));
 }

Cheers
 Benny



[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux