/* Convert an IP address into its fully qualified domain name. */ #include #include #include int main(int argc, char **argv) { in_addr_t ip = inet_addr("131.211.17.1"); struct hostent *entry; if ((int)ip == -1) { fprintf(stderr, "%s: bad argument to inet_addr\n", argv[0]); return EXIT_FAILURE; } entry = gethostbyaddr((char *)&ip, sizeof ip, AF_INET); if (entry == NULL) { fprintf(stderr, "%s: h_errno == %d\n", argv[0], h_errno); return EXIT_FAILURE; } printf("%s\n", entry->h_name); return EXIT_SUCCESS; }