一.域名解析
DNS域名解析,实现了主机域名地址到IP地址转换的过程。
二.Linux中编程应用
1.gethostbyname()//利用这个函数完成域名到IP地址的转换。
成功时返回hostent结构体,失败返回NULL
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses */
}
#include <netdb.h>
#include <arpa/inet.h>
#include <stdio.h>
void main()
{
struct hostent * host;
gethostbyname("www.baidu.com") ;
if(host != NULL)
{
printf("解析出ip:%s\n",inet_ntoa(*(struct in_addr *)host->h_addr));
}
}