- int sock
- /* initialize hint */
- memset(&hint, 0, sizeof(hint));
- hint.ai_family = PF_UNSPEC;
- hint.ai_protocol = prot;
- hint.ai_socktype = type;
- res = getaddrinfo(host, serv, &hint, &addr);
- if (res != 0) {
- printf("sockconn cannot resolve host %s, service %s,
- protocol %d: %s\n", host, serv, prot, gai_strerror(res));
- errno = 0;
+ int sock;
+ /* initialize hint structure */
+ memset(&hint, 0, sizeof(struct addrinfo));
+ hint.ai_family = PF_UNSPEC; /* generic address (IPv4 or IPv6) */
+ hint.ai_protocol = prot; /* protocol */
+ hint.ai_socktype = type; /* socket type */
+ res = getaddrinfo(host, serv, &hint, &addr); /* calling getaddrinfo */
+ if (res != 0) { /* on error exit */
+ printf("sockconn cannot resolve host %s, service %s, ", host, serv);
+ printf("protocol %d: %s\n", prot, gai_strerror(res));