There are similar questions for that but I can't find the answer for which I'm looking.
#include <netdb.h>
int getaddrinfo (const char *hostname,
const char *service,
const struct addrinfo *hints,
struct addrinfo **result) ;
Returns: 0 if OK, nonzero on error
What I wonder is that why we do need the iteration over the linked-list pointed to by result
even if we define hints
instead of it being NULL
. We already know the IP
(hostname) and the PORT
(service). Don't we?
If the iteration is needed, could you exemplify simply by considering a guy not having full-filled network knowledge?
For example, I define hints
as following.
struct addrinfo hints;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; /* IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM; /* TCP */
hints.ai_flags = 0;
hints.ai_protocol = 0;