#include<stdlib.h>
#include<stdio.h>
#include<errno.h>
#include<netinet/in.h>
#include<netdb.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>
int main(int argc, char const *argv[]){
struct hostent *h;
if(argc != 2){
fprintf(stderr, "USa: %s<nombre_dominio>\n", argv[0]);
exit(1);
}
if((h = gethostbyname(argv[1]))==NULL){
herror("gethostbyname");
exit(1);
}
else
printf("gethostbyname() is OK.\n");
printf("El nombre del host es: %s\n", h->h_name);
printf("La dirección IP es: es: %s\n", inet_ntoa(*((struct in_addr*)h->h_addr)));
printf("Sniffeando otros nombres... sniff... sniff... snif...\n");
int j = 0;
do
{
printf("Alias #%d es: %s\n",j,h->h_aliases[j]);
j++;
} while (h->h_aliases[j]!=NULL);
printf("Sniffeando oras IPs...sniff...sniff...sniff\n");
int i = 0;
do
{
printf("Direccion #%i es: %s\n",i, inet_ntoa(*((struct in_addr*)(h->h_addr_list[i]))));
i++;
} while (h->h_addr_list[i]!=NULL);
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.