From f9ec43d2a84e162eebaca9cde5a90c31ddef60c8 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Wed, 30 May 2012 16:15:36 +0200 Subject: [PATCH] Tweak connect error. On lookup of a hostname we could get back both IPv4 and IPV6 addresses for a given host. But we may only support IPV4 on the local host and as such trying to create an IPV6 socket will fail. If we check the return code of the socket call for EAFNOSUPPORT we catch such an error and can continue trying to create a socket type that is supported. --- bacula/src/lib/bsock.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bacula/src/lib/bsock.c b/bacula/src/lib/bsock.c index 845e63ecff..891b10f3e4 100644 --- a/bacula/src/lib/bsock.c +++ b/bacula/src/lib/bsock.c @@ -218,9 +218,21 @@ bool BSOCK::open(JCR *jcr, const char *name, char *host, char *service, if ((sockfd = socket(ipaddr->get_family(), SOCK_STREAM, 0)) < 0) { berrno be; save_errno = errno; - *fatal = 1; - Pmsg3(000, _("Socket open error. proto=%d port=%d. ERR=%s\n"), - ipaddr->get_family(), ipaddr->get_port_host_order(), be.bstrerror()); + switch (errno) { +#ifdef EAFNOSUPPORT + case EAFNOSUPPORT: + /* + * The name lookup of the host returned an address in a protocol family + * we don't support. Suppress the error and try the next address. + */ + break; +#endif + default: + *fatal = 1; + Pmsg3(000, _("Socket open error. proto=%d port=%d. ERR=%s\n"), + ipaddr->get_family(), ipaddr->get_port_host_order(), be.bstrerror()); + break; + } continue; } -- 2.39.5