struct hostent *fHost;
char fMyIpAddr[64];
{
char buffer[1024];
if (gethostname(buffer, sizeof(buffer)) == SOCKET_ERROR) {
printf("%s gethostname error !!!\r\n", __FUNCTION__);
return;
}
fHost = gethostbyname(buffer);
if (fHost == NULL) {
printf("%s gethostbyname error !!!\r\n", __FUNCTION__);
return;
}
sprintf(fMyIpAddr, "%d.%d.%d.%d",
((struct in_addr *)(fHost->h_addr))->S_un.S_un_b.s_b1,
((struct in_addr *)(fHost->h_addr))->S_un.S_un_b.s_b2,
((struct in_addr *)(fHost->h_addr))->S_un.S_un_b.s_b3,
((struct in_addr *)(fHost->h_addr))->S_un.S_un_b.s_b4
);
}
댓글 없음:
댓글 쓰기