我想问2个问题,在提问前,我先进行下说明。
在Linux下编译(gcc -o hostinfo hostinfo.c)下面的代码后
#include
#include
#include
#include
int main(int argc, char **argv)
{
if(argc != 2){
fprintf(stderr, "usage: %s \n", argv[0]);
return 0;
}
char **pp;
struct in_addr addr;
struct hostent *hostp;
if(inet_aton(argv[1], &addr) != 0){
hostp = gethostbyaddr((const char *)&addr, sizeof(addr), AF_INET);
}else{
hostp = gethostbyname(argv[1]);
}
printf("official hostname: %s\n", hostp->h_name);
for(pp = hostp->h_aliases; *pp != NULL; pp++){
printf("alias: %s\n", *pp);
}
for(pp = hostp->h_addr_list; *pp != NULL; pp++){
addr.s_addr = ((struct in_addr *) *pp)->s_addr;
printf("address: %s\n", inet_ntoa(addr));
}
return 0;
}
运行命令:
>./hostinfo www.17173.com
>./hostinfo www.17173.com
得到结果如下:
official hostname: poolct.17173.com
alias: www.17173.com
alias: pooldist.17173.com
address: 117.27.230.84
address: 117.27.230.82
address: 117.27.230.83
address: 117.27.230.98
address: 117.27.230.75
address: 117.27.230.86
address: 117.27.230.85
address: 117.27.230.80
address: 117.27.230.99
official hostname: poolct.17173.com
alias: www.17173.com
alias: pooldist.17173.com
address: 117.27.230.83
address: 117.27.230.82
address: 117.27.230.84
address: 117.27.230.96
address: 117.27.230.75
address: 117.27.230.88
address: 117.27.230.85
address: 117.27.230.80
address: 117.27.230.99
现在我想请问2个问题:
A.为什么每次返回的 ip 地址的顺序不一样?
B.这种顺序有何作用?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
小伙看你根骨奇佳,潜力无限,来学PHP伐。