Created
July 18, 2017 16:59
-
-
Save Xhendos/9e75c598ff0d3330b931104aed1ee29c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <netdb.h> | |
#include <sys/socket.h> | |
#include <arpa/inet.h> | |
#include <netinet/in.h> | |
int main(int argc, char* argv[]) | |
{ | |
struct hostent *host_descriptor; | |
char *address = argv[1]; | |
host_descriptor = gethostbyname(address); | |
if(host_descriptor == NULL) | |
{ | |
perror("[ADR] host_descriptor is NULL\n"); | |
return -1; | |
} | |
printf("[ADR] succesfully received information from %s\n", address); | |
printf("[ADR] official name of the host is %s (%s)\n", host_descriptor->h_name, inet_ntoa(*(struct in_addr *)host_descriptor->h_addr)); | |
for(int i = 0; host_descriptor->h_aliases[i] != NULL; i++) | |
{ | |
printf(" + alternative hostname is %s (%s)\n", host_descriptor->h_aliases[i], inet_ntoa(* (struct in_addr *)host_descriptor->h_addr_list[i])); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment