From b227547119f45ca35465bd2cfa460c48bb496b57 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Tue, 1 Aug 2000 21:10:52 +0000 Subject: [PATCH] (doit): loop until we create an error socket of an supported socket family git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8881 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/rsh/rsh.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/appl/rsh/rsh.c b/appl/rsh/rsh.c index 220675e3e..40fb7a7ba 100644 --- a/appl/rsh/rsh.c +++ b/appl/rsh/rsh.c @@ -703,7 +703,7 @@ doit (const char *hostname, continue; } if (do_errsock) { - struct addrinfo *ea; + struct addrinfo *ea, *eai; struct addrinfo hints; memset (&hints, 0, sizeof(hints)); @@ -712,15 +712,23 @@ doit (const char *hostname, hints.ai_family = a->ai_family; hints.ai_flags = AI_PASSIVE; - error = getaddrinfo (NULL, "0", &hints, &ea); + errsock = -1; + + error = getaddrinfo (NULL, "0", &hints, &eai); if (error) errx (1, "getaddrinfo: %s", gai_strerror(error)); - errsock = socket (ea->ai_family, ea->ai_socktype, ea->ai_protocol); + for (ea = eai; ea != NULL; ea = ea->ai_next) { + errsock = socket (ea->ai_family, ea->ai_socktype, + ea->ai_protocol); + if (errsock < 0) + continue; + if (bind (errsock, ea->ai_addr, ea->ai_addrlen) < 0) + err (1, "bind"); + break; + } if (errsock < 0) err (1, "socket"); - if (bind (errsock, ea->ai_addr, ea->ai_addrlen) < 0) - err (1, "bind"); - freeaddrinfo (ea); + freeaddrinfo (eai); } else errsock = -1;