host entry的问题
时间:10-02
整理:3721RD
点击:
void main()
{
struct in_addr addr;
struct hostent *ent;
char host[128];
char *ip;
gethostname(host, 128);
printf("get host: %s\n", host);
ent = gethostbyname(host);
if(ent == NULL)
{
printf("fuck error\n");
return;
}
memcpy((char *)&addr, (char*)ent->h_addr_list[1], (size_t)ent->h_length);
ip = inet_ntoa(addr);
printf("get ip: %s\n", ip);
printf("what we get: %s\n", ent->h_name);
}
得到的ip address和ifconfig得到的不一样!
xxx@xxx ~/test $ hostname -i
202.102.110.203
xxx@xxx~/test $ ./test
get host: HUS2
get ip: 202.102.110.203
what we get: HUS2
ifconfig:
inet 172.28.30.9 netmask 255.255.255.0 broadcast 172.28.30.255
{
struct in_addr addr;
struct hostent *ent;
char host[128];
char *ip;
gethostname(host, 128);
printf("get host: %s\n", host);
ent = gethostbyname(host);
if(ent == NULL)
{
printf("fuck error\n");
return;
}
memcpy((char *)&addr, (char*)ent->h_addr_list[1], (size_t)ent->h_length);
ip = inet_ntoa(addr);
printf("get ip: %s\n", ip);
printf("what we get: %s\n", ent->h_name);
}
得到的ip address和ifconfig得到的不一样!
xxx@xxx ~/test $ hostname -i
202.102.110.203
xxx@xxx~/test $ ./test
get host: HUS2
get ip: 202.102.110.203
what we get: HUS2
ifconfig:
inet 172.28.30.9 netmask 255.255.255.0 broadcast 172.28.30.255
。