这是一个从here,但无法在编译时:运行此代码段需要哪些头文件?
int main(int argc, char **argv)
{
struct hostent {
char *h_name; // main name
char **h_aliases; // alternative names (aliases)
int h_addrtype; // address type (usually AF_INET)
int h_length; // length of address (in octets)
char **h_addr_list; // alternate addresses (in Network Byte Order)
};
#define h_addr h_addr_list[0] // First address of h_addr_list.
struct hostent *info_stackoverflow;
int i = 0;
info_stackoverflow = gethostbyname("www.stackoverflow.com");
printf("The IP address of %s is %s",
info_stackoverflow->h_name,
inet_ntoa(* ((struct in_addr *)info_stackoverflow->h_addr)));
/* aliases */
while(*(pc_ip->h_aliases + i) != NULL)
{
printf("\n\tAlias: %s", *(pc_ip->h_aliases + i));
i++;
}
}
你能弄清楚'pc_ip'是如何定义的吗? – httpinterpret 2010-05-30 06:26:23
哦,在用info_stackoverflow替换pc_ip后,我在链接时出错:'error LNK2019:无法解析的外部符号_inet_ntoa @ 4参考' – httpinterpret 2010-05-30 06:32:46
现在编译好了,但是在此行获得访问冲突'inet_ntoa(*((struct in_addr *)info_stackoverflow-> h_addr)));' – httpinterpret 2010-05-30 06:44:12