From 503e404ac07cd4adc050672b8abc1bdd073487a2 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Tue, 26 Jun 2012 21:43:19 +0200 Subject: [PATCH] Fix inet_pton call. inet_pton returns 1 when it succeeds so the test was wrong. When it fails its either returns 0 if not a correct ipv6 address or -1 when the protocol family is not known. Checked the man page for both Linux and Solaris and this seems like an oversight as the definition is the same on these OSes and probably on all others as these functions tend to be rather portable. Also did some small rewrite of the code so its easier to read and the braces are easier to interpret. --- bacula/src/lib/bnet.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index a2b18370b3..b6775230e0 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -576,16 +576,14 @@ dlist *bnet_host2ipaddrs(const char *host, int family, const char **errstr) addr->set_type(IPADDR::R_MULTIPLE); addr->set_addr4(&inaddr); addr_list->append(addr); - } else #ifdef HAVE_IPV6 - if (inet_pton(AF_INET6, host, &inaddr6) > 1) { + } else if (inet_pton(AF_INET6, host, &inaddr6) == 1) { addr = New(IPADDR(AF_INET6)); addr->set_type(IPADDR::R_MULTIPLE); addr->set_addr6(&inaddr6); addr_list->append(addr); - } else #endif - { + } else { if (family != 0) { errmsg = resolv_host(family, host, addr_list); if (errmsg) { -- 2.39.5