#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <netdb.h> #include <sys/socket.h> #include <string.h> #include <arpa/inet.h> 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:https://www.cdcxhl.com/article22/jcppcc.html
成都网站建设公司_创新互联,为您提供自适应网站、关键词优化、软件开发、用户体验、静态网站、电子商务
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联