Hi, I have been working on this since a few hours, and I am stuck. If gethostbyaddr fails it should try gethostbyname, but neither of them is working.
Can anyone point me to the problem?
Code:const char *host = "localhost"; int main(void) { char buf[128]; LPHOSTENT hostent = NULL; IN_ADDR iaddr; DWORD addr = inet_addr(host); if (addr != INADDR_NONE) { hostent = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET); if (hostent != NULL) { sprintf(buf, ".»». -> %s.", hostent->h_name); puts(buf); } } else { hostent = gethostbyname(host); if (hostent != NULL) { iaddr = *((LPIN_ADDR)*hostent->h_addr_list); sprintf(buf, ".»». -> %s.", inet_ntoa(iaddr)); puts(buf); } } if (hostent == NULL) { sprintf(buf,".»». Couldn't resolve hostname."); puts(buf); } return 0; }



LinkBack URL
About LinkBacks


