From: Kern Sibbald Date: Mon, 31 Mar 2014 18:07:48 +0000 (+0200) Subject: Make IPv6 handling more robust X-Git-Tag: Release-7.0.1~3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fd781ad869729cb7b4b78dea88d5332bfc60cf32;p=bacula%2Fbacula Make IPv6 handling more robust --- diff --git a/bacula/src/lib/address_conf.c b/bacula/src/lib/address_conf.c index c5ef4cac1e..0d5fb07830 100644 --- a/bacula/src/lib/address_conf.c +++ b/bacula/src/lib/address_conf.c @@ -65,7 +65,7 @@ IPADDR::IPADDR(int af) : type(R_EMPTY) saddr4->sin_port = 0xffff; } #ifdef HAVE_IPV6 - else { + else if (af == AF_INET6) { saddr6->sin6_port = 0xffff; } #endif @@ -96,11 +96,11 @@ unsigned short IPADDR::get_port_net_order() const port = saddr4->sin_port; } #ifdef HAVE_IPV6 - else { + else if (saddr->sa_family == AF_INET6) { port = saddr6->sin6_port; } #endif - return port; + return port; } void IPADDR::set_port_net(unsigned short port) @@ -109,7 +109,7 @@ void IPADDR::set_port_net(unsigned short port) saddr4->sin_port = port; } #ifdef HAVE_IPV6 - else { + else if (saddr->sa_family == AF_INET6) { saddr6->sin6_port = port; } #endif @@ -201,10 +201,11 @@ const char *IPADDR::get_address(char *outputbuf, int outlen) const char *IPADDR::build_address_str(char *buf, int blen) { char tmp[1024]; + *buf = 0; if (get_family() == AF_INET) { bsnprintf(buf, blen, "%s:%hu ", get_address(tmp, sizeof(tmp) - 1), get_port_host_order()); - } else { + } else if (get_family() == AF_INET6) { bsnprintf(buf, blen, "[%s]:%hu ", get_address(tmp, sizeof(tmp) - 1), get_port_host_order()); } @@ -574,7 +575,7 @@ int sockaddr_get_port_net_order(const struct sockaddr *client_addr) return ((struct sockaddr_in *)client_addr)->sin_port; } #ifdef HAVE_IPV6 - else { + else if (client_addr->sa_family == AF_INET6) { return ((struct sockaddr_in6 *)client_addr)->sin6_port; } #endif @@ -587,7 +588,7 @@ int sockaddr_get_port(const struct sockaddr *client_addr) return ntohs(((struct sockaddr_in *)client_addr)->sin_port); } #ifdef HAVE_IPV6 - else { + else if (client_addr->sa_family == AF_INET6) { return ntohs(((struct sockaddr_in6 *)client_addr)->sin6_port); } #endif diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index 91fd397096..f61929f4ea 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -439,14 +439,15 @@ static const char *resolv_host(int family, const char *host, dlist * addr_list) IPADDR *addr = New(IPADDR(hp->h_addrtype)); addr->set_type(IPADDR::R_MULTIPLE); if (addr->get_family() == AF_INET) { - addr->set_addr4((struct in_addr*)*p); + addr->set_addr4((struct in_addr*)*p); + addr_list->append(addr); } #ifdef HAVE_IPV6 - else { - addr->set_addr6((struct in6_addr*)*p); + else if (addr->get_family() == AF_INET6) { + addr->set_addr6((struct in6_addr*)*p); + addr_list->append(addr); } #endif - addr_list->append(addr); } V(ip_mutex); }