I'm trying to build a simple webserver which is IP version agnostic.
This is my sample code snippet
hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
hints.ai_flags = AI_PASSIVE; // fill in my IP for me
hints.ai_socktype = SOCK_STREAM;
if ((status = getaddrinfo(NULL, "8000", &hints, &res)) != 0){
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
exit(0);
}
After populating status, I go through each element of the linked list "res" till I find a valid entry, and then I initialize a socket with that structure.
My question is, in the linked list "res" returned by getaddrinfo(), do I get separate structures for the IPv4 and IPv6 loopback addresses? And in that case, do I need to create two sockets to listen and serve the IPv4 and IPv6 loopback addresses seperately? Or is there a single structure in the "res" linked list which can be used to create a socket which "magically" listens on both the IPv4/v6 loopback addresses?
Thank you