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.
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;
}