开启WIFI热点,一客户机连接到热点上,获得Ip192.168.1.109,以下是我想获取客户机主机名的代码: #include <stdio.h>
#include <sys/types.h> 
#include <sys/socket.h> 
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h> 
int main(int argc, char** argv) 
{
 struct hostent *ip;
 unsigned long hostname; 
 if (argc != 2) 
 { 
  printf("Need to specify an IP address.\n"); 
  exit(1); 
 }
 if ((hostname = inet_addr(argv[1])) == -1) 
 { 
  printf("Could not find %s\n", argv[1]);
  exit(1); 
 }
 if ((ip = gethostbyaddr((char *)&hostname, sizeof(long), AF_INET)) != NULL) 
 {
  printf("%s is %s\n", argv[1], ip->h_name); 
 }
 else
 {
  printf("Could not resolve %s\n", argv[1]);
 }
 return 0; 
}  编译为test .
运行test 192.168.1.109 
输出: Could not resolve 192.168.1.109哪位大侠做过这方面的啊,纠结几天了。
先谢谢各位了~~