从域名中解析出ip地址

//p_Url = my-staging.busch-jaeger.de

static int WebSocket_Get_ServerIp(char *p_Url, char *p_Ip)

{
    assert(p_Url);
    assert(p_Ip);

    struct hostent *objHostInfo;    
    objHostInfo = gethostbyname(p_Url);
    if(objHostInfo == NULL)
    {
        printf("Get Ip By Host Failed !!! \n");
        return SN_ERROR;
        
    }
    sprintf(p_Ip,"%s", inet_ntoa(*((struct in_addr *)objHostInfo->h_addr)));
    printf("==========HostName :%s , IP Address :%s\n",objHostInfo->h_name, p_Ip);
    
    return SN_SUCCESS;
}

你可能感兴趣的:(技术,c)