[Linux网络编程]域名转换函数族--使用gethostbyname函数1-成都快上网建站

[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
URL链接:http://kswjz.com/article/jcppcc.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流