Skip to content

Instantly share code, notes, and snippets.

@Xhendos
Created July 18, 2017 16:59
Show Gist options
  • Save Xhendos/9e75c598ff0d3330b931104aed1ee29c to your computer and use it in GitHub Desktop.
Save Xhendos/9e75c598ff0d3330b931104aed1ee29c to your computer and use it in GitHub Desktop.
#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