No se porq no se muestra los includes.
#define
#define
#define
#define
#define MAXSOCK 20
int main(int argc, char **argv)
{
int error=0;
struct addrinfo hints, *res, *res0;
memset(&hints, 0, sizeof(hints));
hints.ai_socktype= 0;//SOCK_STREAM;
if(argc!=2)
fprintf(stderr,"modo de uso: dns_resolve fqdn\n");
else
{
error = getaddrinfo(argv[1],NULL,&hints,&res0);
if(error)//si es diferente de cero
{
fprintf(stderr,"dns_resolve %s: %s\n",argv[1],gai_strerror(error));
}
else
{
for(res=res0; res ; res=res->ai_next)
{
int error;
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
switch (res->ai_family) {
case AF_INET:
printf("Interfaz IPv4 %d\n", res->ai_family);
break;
case AF_INET6:
printf("Interfaz IPv6 %d\n", res->ai_family);
break;
default:
printf("interfaz desconocida \n");
return 1;
break;
}
error = getnameinfo(res->ai_addr, res->ai_addrlen, hbuf,
sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
if(error)//si es diferente de cero
{
fprintf(stderr,"error dns_resolve: %s\n",gai_strerror(error));
}
printf("addr: %s port: %s\n",hbuf,sbuf);
}
}
}
return 1;
}
No hay comentarios.:
Publicar un comentario