Why are there multiple results from getaddrinfo?
问题 I am trying to create a simple program that gets the ip address given a certain hostname: My code snipped is attached below: #include<stdio.h> #include<stdlib.h> #include<stdio.h> #include<netdb.h> #include<sys/socket.h> #include<errno.h> #include<arpa/inet.h> #include<string.h> #include<unistd.h> int main(int argc, char *argv[]) { if(argc<2){ printf("Please provide a hostname.\n"); exit(1); } char *hostname = argv[1]; char ip[100]; get_ip(hostname,ip); printf("%s resolved to %s\n",hostname