From dfe932d873073d10eb3a9f3856a23a844b5557ea Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 14 Oct 2015 20:59:50 -0700 Subject: [PATCH] Fix bug #2083 -- Fix sockaddr_to_ascii for FreeBSD --- bacula/src/lib/address_conf.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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) { -- 2.39.5