代码如下:
#include
#include
#include
#include
#include
char host_name[200];
int main(void)
{
gethostname(host_name, 200);
host_name = gethostbyname(host_name);
printf("=========================================================================\n");
printf("The local host: Address : %s\n", inet_ntoa(*(struct in_addr*)host_name->h_addr));
printf(" Name : %s\n", host_name->h_name);
printf(" Port : %d\n", port);
printf("=========================================================================\n");
}
但是运行的结果却是:
=========================================================================
The local host: Address : 127.0.0.1
Name : localhost.localdomain
Port : 8001
=========================================================================
我本机的ip是192.168.0.19。
有?知道是哪里出现问题了?
谢谢了。
Duanjin_Chen 于 2008-04-29 20:26:38发表:
host_name不是char数组吗?怎么host_name->h_addr?