0
#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。怎麼了 ?gethostbyaddr錯誤未知主機
任何人都可以幫助我嗎? 謝謝
此代碼來自不需要「結構」關鍵字的C++代碼。我在Mac OS X 10.6上,它不起作用(一個懶惰的等待,然後錯誤) –
「* ... looooong等... *」:這聽起來像一個DNS超時。 @FélixFaisant – alk
是的,這是一個超時。我在Fedora 17下的另一臺計算機上測試了這個編程,它的工作原理。所以代碼是好的... –