From: Dave Hart Date: Sun, 12 Dec 2010 07:23:59 +0000 (+0000) Subject: include non-zero scope in IPv6 stoa() output X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bcd83a3dbafff822beaa2a75e9979fed2a99c739;p=thirdparty%2Fntp.git include non-zero scope in IPv6 stoa() output bk: 4d04788fnOvE-t2guGdrsFVEsSaGoA --- diff --git a/libntp/socktoa.c b/libntp/socktoa.c index 7c4fc394e1..0b374096b7 100644 --- a/libntp/socktoa.c +++ b/libntp/socktoa.c @@ -35,33 +35,43 @@ socktoa( const sockaddr_u *sock ) { - register char *buffer; + char * res; + char * addr; + u_long scope; - LIB_GETBUF(buffer); + LIB_GETBUF(res); if (NULL == sock) - strncpy(buffer, "(null)", LIB_BUFLENGTH); + strncpy(res, "(null)", LIB_BUFLENGTH); else { switch(AF(sock)) { case AF_INET: case AF_UNSPEC: - inet_ntop(AF_INET, PSOCK_ADDR4(sock), buffer, + inet_ntop(AF_INET, PSOCK_ADDR4(sock), res, LIB_BUFLENGTH); break; case AF_INET6: - inet_ntop(AF_INET6, PSOCK_ADDR6(sock), buffer, + inet_ntop(AF_INET6, PSOCK_ADDR6(sock), res, LIB_BUFLENGTH); + scope = SCOPE_VAR(sock); + if (0 != scope && !strchr(res, '%')) { + addr = res; + LIB_GETBUF(res); + snprintf(res, LIB_BUFLENGTH, "%s%%%lu", + addr, scope); + res[LIB_BUFLENGTH - 1] = '\0'; + } break; default: - snprintf(buffer, LIB_BUFLENGTH, + snprintf(res, LIB_BUFLENGTH, "(socktoa unknown family %d)", AF(sock)); } } - return buffer; + return res; } @@ -70,15 +80,16 @@ sockporttoa( const sockaddr_u *sock ) { - const char *atext; - char *buf; + const char * atext; + char * buf; atext = socktoa(sock); LIB_GETBUF(buf); - if (IS_IPV4(sock)) - snprintf(buf, LIB_BUFLENGTH, "%s:%hu", atext, SRCPORT(sock)); - else - snprintf(buf, LIB_BUFLENGTH, "[%s]:%hu", atext, SRCPORT(sock)); + snprintf(buf, LIB_BUFLENGTH, + (IS_IPV6(sock)) + ? "[%s]:%hu" + : "%s:%hu", + atext, SRCPORT(sock)); return buf; }