// author: frenchwhale (http://frenchwhales_site.tripod.com) // for the WinSock tutorial // // file name: resolver.c // // description: An application that queries the current // DNS server with a host name and prints // the results to the console. // Copyright 2002 frenchwhale #include #include #include #include int main(int argc, int **argv) { WSADATA wsda; // Structure to store info // returned from WSAStartup struct hostent *host; // Used to store information // retreived about the server char szAddress[64]; int i; // Check arguments if(argc != 2 || (argc==2 && strcmp((char *) &argv[1][0], "/?")==0)) { printf("resolver domain\n"); printf(" domain: the domain name that you want to resolve\n"); exit(1); } // Copy the IP address strcpy(szAddress, (char *) &argv[1][0]); // Load version 1.1 of Winsock WSAStartup(MAKEWORD(1,1), &wsda); host = NULL; printf("Resolving host..."); host = gethostbyname(szAddress); // Get the IP address of the server // and store it in host if(host == NULL) { printf("Error\nUnknown host: %s\n", szAddress); exit(1); } printf("OK\n"); printf("host->h_name = %s\n", host->h_name); i = 0; while(host->h_aliases[i] != NULL) { printf("host->h_aliases[%d] = %s\n", i, host->h_aliases[i]); i++; } printf("host->h_addrtype = %d\n", host->h_addrtype); printf("host->h_length = %d\n", host->h_length); i = 0; while(host->h_addr_list[i] != NULL) { printf("host->h_addr_list[%d] = 0x%X (%s)\n", i, (long) host->h_addr_list[i], inet_ntoa(*(struct in_addr *) host->h_addr_list[i])); i++; } WSACleanup(); return 0; }