- s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
- if (s < 0) {
- rprintf(FERROR, RSYNC_NAME ": open socket in failed: %s\n",
- strerror(errno));
- freeaddrinfo(res);
- return -1;
+ resp = res;
+ while (1) {
+ s = socket(resp->ai_family, resp->ai_socktype, resp->ai_protocol);
+
+ if (s >= 0) {
+ break; /* got a socket */
+ } else if ((resp = resp->ai_next)) {
+ switch (errno) {
+ case EPROTONOSUPPORT:
+ case EAFNOSUPPORT:
+ case EPFNOSUPPORT:
+ /* See if there's another address that will work... */
+ continue;
+ }
+ }
+
+ rprintf(FERROR, RSYNC_NAME ": open inbound socket"
+ "(dom=%d, type=%d, proto=%d) failed: %s\n",
+ resp->ai_family, resp->ai_socktype, resp->ai_protocol,
+ strerror(errno));
+ goto fail;