【发布时间】:2012-09-02 05:03:48
【问题描述】:
#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main () {
in_addr ip;
ip.s_addr = inet_addr("173.194.71.94"); // www.google.fr IP
hostent* hostnames = gethostbyaddr(&ip, sizeof(ip), AF_INET);
if (hostnames != NULL && hostnames[0].h_name != NULL) {
printf("%s\n", hostnames[0].h_name);
return 0;
} else {
herror("gethostbyaddr");
return 1;
}
}
它返回“gethostbyaddr:未知主机”。我尝试使用不同的 IP。怎么了?
有人可以帮助我吗? 谢谢
【问题讨论】:
标签: c++ c sockets networking gethostbyaddr