We are only interested in SOCK_STREAM and protocol IPPROTO_TCP
as that is the way we communicate. When we don't specify that
in the hints for getaddrinfo we also get SOCK_DGRAM/IPPROTO_UDP
and on Linux SOCK_RAW. And possibly more on other platforms.
So lets me more specific. The older fix to suppress duplicates
is also useable as a user might specify two or more names
that resolve to the same address and we want to suppress duplicates
also.
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = family;
- hints.ai_socktype = 0;
- hints.ai_protocol = 0;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = 0;
res = getaddrinfo(host, NULL, &hints, &ai);