/* ########################################################################## # This script makes a DNS query and prints the results obtained. # It's been used to test the Destination Address Selection procedure. # # This script needs to be linked with the KAME's lib "inet6", as follows: # # gcc -o test_das test_das.c -L/usr/local/lib/ -linet6 # # NOTE: This program is hardly based on the "man getaddrinfo" of FreeBSD. # #(There is no copyright but the copyright of the "man" page, if any :) ########################################################################## */ #include #include #include #include #include int main(int argc, char *argv[]) { struct addrinfo hints, *res, *res0; int error; int s; const char *cause = NULL; char aux[INET6_ADDRSTRLEN]; /* checks the arguments and help if wrong */ if( argc != 2 ) { fprintf(stderr,"test_das: You must specify a name to resolve.\n"); fprintf(stderr,"test_das: syntax: test_das \n\n"); exit(-1); } memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; error = getaddrinfo(argv[1], NULL, &hints, &res0); if (error) { errx(1, "%s", gai_strerror(error)); /*NOTREACHED*/ } s = -1; for (res = res0; res; res = res->ai_next) { bzero(aux, INET6_ADDRSTRLEN); if( res->ai_family == AF_INET) { inet_ntop( AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr), aux, INET6_ADDRSTRLEN ); } else { inet_ntop( AF_INET6, &(((struct sockaddr_in6 *)res->ai_addr)->sin6_addr), aux, INET6_ADDRSTRLEN ); } printf("addr: %s\n", aux); } freeaddrinfo(res0); return 0; }