From: Kern Sibbald Date: Thu, 15 Oct 2015 03:59:50 +0000 (-0700) Subject: Fix bug #2083 -- Fix sockaddr_to_ascii for FreeBSD X-Git-Tag: Release-7.4.0~214 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=dfe932d873073d10eb3a9f3856a23a844b5557ea;p=bacula%2Fbacula Fix bug #2083 -- Fix sockaddr_to_ascii for FreeBSD --- diff --git a/bacula/src/lib/address_conf.c b/bacula/src/lib/address_conf.c index 59dbd0f31c..66a49d2aec 100644 --- a/bacula/src/lib/address_conf.c +++ b/bacula/src/lib/address_conf.c @@ -613,10 +613,19 @@ char *sockaddr_to_ascii(const struct sockaddr *sa, int socklen, char *buf, int b /* This is the more modern way of doing it */ char clienthost[NI_MAXHOST]; char clientservice[NI_MAXSERV]; - int status; - status = getnameinfo(sa, socklen, clienthost, sizeof(clienthost), - clientservice, sizeof(clientservice), - NI_NUMERICHOST | NI_NUMERICSERV); + int status = 1; + if (sa->sa_family == AF_INET) { + status = getnameinfo(sa, socklen, clienthost, sizeof(clienthost), + clientservice, sizeof(clientservice), + NI_NUMERICHOST | NI_NUMERICSERV); + } +#ifdef HAVE_IPV6 + else { + status = getnameinfo(sa, sizeof(sockaddr_in6), clienthost, sizeof(clienthost), + clientservice, sizeof(clientservice), + NI_NUMERICHOST | NI_NUMERICSERV); + } +#endif if (status == 0) { /* Enclose IPv6 in [] */ if (strchr(clienthost, ':') != NULL) {