int get_ip_of_host()

in sample_app/onvif_camera_mock/artifacts/wsdd/src/net_utils.c [87:120]


int get_ip_of_host(const char *host_name, int af, char *IP)
{
    struct hostent *host;
    int addrstr_len;


    if( !host_name || !IP )
    {
        errno = EINVAL;
        return -1;
    }


    if( af == AF_INET6)
        addrstr_len = INET6_ADDRSTRLEN;
    else
        addrstr_len = INET_ADDRSTRLEN;


    host = gethostbyname2(host_name, af);
    if( !host )
      return -1;                        //possible DNS is not configured


    if( !host->h_addr_list[0] )
      return -1;                        //host is found, but no associated IP.


    if(inet_ntop(af, (void *)host->h_addr_list[0], IP, addrstr_len) == NULL)
      return -1;


    return 0; //good job
}