//*****************RESUELVE UN DOMINIO, O IP*********************
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Realizado en plataforma LINUX Ubuntu 20.04.4 LTS.
//Bajo el standard ANSI C.-C-11
//Usado el IDE Sublime Text.
//compilar con gcc en consola Linux.
//++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++--LENGUAJE C --TRABAJO CON LA ESTRUCTURA hostent- ++++++++
//****Programado por HILARIO IGLESIAS MARTÍNEZ****
//Laminador jubilado deL Tren de Alambrón de
//Arcelor Mittal en Gijón -ASTURIAS-
// https://es.wikipedia.org/wiki/Tren_de_alambron
//*******************************************
//Programa que bajo la estructura hostent
//y gethostbyname resolviendo un dominio o una
//dirección IP.
//Cuestiones o dudas a: idusdruida51@gmail.com
//************************************************
//++++++++++++++++++++++++++++++++++++++++++++++
#include <arpa/inet.h>
#include <stdio.h>
#include <netdb.h>
int main()
{
char **doblePuntero;
char EntradaDatos[80];
char espacioIP[32];
printf("Introduce dominio tipo: www.yomismo.com, o una IP\n");
scanf(" %s",EntradaDatos);
struct hostent *punteroHosten;
punteroHosten=gethostbyname(EntradaDatos);
printf("**********HOST************\n");
printf("DIRECCIÓN: %s\n",punteroHosten->h_name );
printf("**********ALIAS*****************\n");
for(doblePuntero = punteroHosten->h_aliases; *doblePuntero != NULL; doblePuntero++) {
printf("Alias del HOST: %s\n",*doblePuntero);
}
printf("******TIPO DE DIRECCIÓN************\n");
printf("TIPO: %i\n",punteroHosten->h_addrtype);
printf("******BYTES DE LONGITUD DIRECCIÓN************\n");
printf("LONGITUD: %i\n",punteroHosten->h_length);
printf("******LISTA DE DIRECCIONES************\n");
doblePuntero = punteroHosten->h_addr_list;
/* Imprime todos los alias llamando a la función ,inet_ntop()
de #include <arpa/inet.h> */
for(; *doblePuntero!=NULL; doblePuntero++) {
inet_ntop(punteroHosten->h_addrtype, *doblePuntero, espacioIP, sizeof(espacioIP));
printf(" DIRECCIONES: %s\n", espacioIP);
} //inet_ntop() convierte IP versión IPv4 y IPv6 de binario a texto
printf("ESPACIO OCUPADO POR CADA IP: BYTES %li\n", sizeof(espacioIP));
return 0;
}
Comentarios sobre la versión: 1.0 (0)
No hay comentarios