分类: C/C++
2007-08-23 15:48:35
#include
int main ()
{
char ac[80];
struct hostent *phe;
struct in_addr addr;
int i;
if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR) {
printf("ERROR when getting local host name.\r\n");
return -1;
}
phe = gethostbyname(ac);
if (phe == 0) {
printf("ERROR Bad host lookup.\r\n");
return -1 ;
}
for (i=0; phe->h_addr_list[i] != 0, i++) {
memcpy(&addr, phe->h_addr_list[0], sizeof(struct in_addr));
printf("Address:%s", inet_ntoa(addr));
}
return 0;
}