[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://myzitong.com/article/jcppcc.html