RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
[Linux网络编程]域名转换函数族--使用gethostbyname函数1
#include 
#include 
#include 
#include 
#include 
#include 
#include 
int main(int argc,char *argv[])
{
  struct hostent *hptr;
  struct in_addr hpaddr;   //定义一个地址结构体  
  if((hptr = gethostbyname(argv[1])) == NULL)
  {
    printf("请输入域名.\n");
    return 1;
  }
  else
  {
    memcpy(&hpaddr,&hptr->h_addr,4);  //拷贝ip地址   
    printf("IP地址为%s.\n",inet_ntoa(hpaddr));
  }
  return 0;
}

标题名称:[Linux网络编程]域名转换函数族--使用gethostbyname函数1
地址分享:http://scyingshan.cn/article/jcppcc.html