/* What follows is code that ran before I added somecomments and should run * after....This is student code and I am posting it because my code is * somewhere in the disk cloud of my stuff. I will more fully comment later. */ /* These are the libraries that numerous 'man' commands will show as necessary * for Sockets */ #include #include #include #include #include #include int main(int argc, char *argv[]){ /*create place to deposit responses for getaddrinfo*/ struct addrinfo* output; int err = getaddrinfo(argv[1], NULL, NULL, &output); if(err != 0){/*if we did not get an error here*/ printf("Error, terminating\n"); exit(EXIT_FAILURE); } /*two for loops going through the same elements are for formatting, arrays were being difficult*/ printf("IP Addresses:\n"); struct addrinfo* out; for(out = output; out != NULL; out = out -> ai_next){ /*getaddrinfo returns duplicates, so we look at every other entry*/ if(out != NULL){ out = out -> ai_next; } char name[NI_MAXHOST]; /*NI_NUMERICHOST gives an IP address in either IPv4 or IPv6*/ if(out != NULL){ getnameinfo(out->ai_addr, out->ai_addrlen, name, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); } else{ break; } printf("%s\n", name); } printf("\nNames:\n"); for(out = output; out != NULL; out = out -> ai_next){ if(out != NULL){ out = out -> ai_next; } char name[NI_MAXHOST]; /*with 0 instead of NI_NUMERICHOST we get the name*/ if(out != NULL){ getnameinfo(out->ai_addr, out->ai_addrlen, name, NI_MAXHOST, NULL, 0, 0); } else{ break; } printf("%s\n", name); } printf("\n"); } /*char* getIPv4(char *hostname){ struct addrinfo* output; int err = getaddrinfo(hostname, NULL, NULL, &output); if(err != 0){//if we did not get an error here printf("Error, terminating\n"); exit(EXIT_FAILURE); } //two for loops going through the same elements are for formatting, arrays were being difficult for(struct addrinfo* out = output; out != NULL; out = out -> ai_next -> ai_next){ //getaddrinfo returns duplicates, so we look at every other entry if(out->ai_addr.sin_family == AF_INET){ char name[NI_MAXHOST]; //NI_NUMERICHOST gives an IP address in either IPv4 or IPv6 getnameinfo(out->ai_addr, out->ai_addrlen, name, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); return name; } } }*/