摘要: getaddrinfo()函数详解1. 概述IPv4中使用gethostbyname()函数完成主机名到地址解析,这个函数仅仅支持IPv4,且不允许调用者指定所需地址类型的任何信息,返回的结构只包含了用于存储IPv4地址的空间。IPv6中引入了getaddrinfo()的新API,它是协议无关的,既可用于IPv4也可用于IPv6。getaddrinfo函数能够处理名字到地址以及服务到端口这两种转换... 阅读全文
posted @ 2010-11-19 12:41 hapus 阅读(98319) 评论(1) 推荐(5) 编辑
摘要: typedef struct addrinfo { int ai_flags; //AI_PASSIVE,AI_CANONNAME,AI_NUMERICHOST int ai_family; //AF_INET,AF_INET6 int ai_socktype; //SOCK_STREAM,SOCK_DGRAM int ai_protocol; //IPPROTO_IP, IPPROTO_IP... 阅读全文
posted @ 2010-11-19 11:47 hapus 阅读(9065) 评论(0) 推荐(0) 编辑
摘要: gethostbyname()函数说明——用域名或主机名获取IP地址 包含头文件 #include <netdb.h> #include <sys/socket.h> 函数原型 struct hostent *gethostbyname(const char *name); 这个函数的传入值是域名或者主机名,例如"www.google.cn"等等。传... 阅读全文
posted @ 2010-11-19 11:10 hapus 阅读(76368) 评论(1) 推荐(5) 编辑