diff --git a/lib/libutil/sockaddr_snprintf.c b/lib/libutil/sockaddr_snprintf.c index 0dcd0eba9d16a..2ea270830bc49 100644 --- a/lib/libutil/sockaddr_snprintf.c +++ b/lib/libutil/sockaddr_snprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: sockaddr_snprintf.c,v 1.11 2013/12/31 12:58:02 mlelstv Exp $ */ +/* $NetBSD: sockaddr_snprintf.c,v 1.12 2016/04/06 18:08:16 christos Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.11 2013/12/31 12:58:02 mlelstv Exp $"); +__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.12 2016/04/06 18:08:16 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -159,10 +159,17 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt, break; case AF_LINK: sdl = ((const struct sockaddr_dl *)(const void *)sa); - (void)strlcpy(addr = abuf, link_ntoa(sdl), sizeof(abuf)); - if ((w = strchr(addr, ':')) != 0) { - *w++ = '\0'; - addr = w; + addr = abuf; + if (sdl->sdl_slen == 0 && sdl->sdl_nlen == 0 + && sdl->sdl_alen == 0) { + (void)snprintf(abuf, sizeof(abuf), "link#%hu", + sdl->sdl_index); + } else { + (void)strlcpy(abuf, link_ntoa(sdl), sizeof(abuf)); + if ((w = strchr(addr, ':')) != 0) { + *w++ = '\0'; + addr = w; + } } break; default: diff --git a/sys/net/dl_print.c b/sys/net/dl_print.c index 1d06fd17f3eae..9644cc8286e32 100644 --- a/sys/net/dl_print.c +++ b/sys/net/dl_print.c @@ -1,4 +1,4 @@ -/* $NetBSD: dl_print.c,v 1.2 2014/12/02 19:34:33 christos Exp $ */ +/* $NetBSD: dl_print.c,v 1.3 2016/04/06 18:04:58 christos Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -29,10 +29,10 @@ #include #ifdef _KERNEL -__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.2 2014/12/02 19:34:33 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.3 2016/04/06 18:04:58 christos Exp $"); #include #else -__RCSID("$NetBSD: dl_print.c,v 1.2 2014/12/02 19:34:33 christos Exp $"); +__RCSID("$NetBSD: dl_print.c,v 1.3 2016/04/06 18:04:58 christos Exp $"); #include static const uint8_t hexdigits[] = "0123456789abcdef"; #endif @@ -83,6 +83,9 @@ sdl_print(char *buf, size_t len, const void *v) const struct sockaddr_dl *sdl = v; char abuf[LINK_ADDRSTRLEN]; + if (sdl->sdl_slen == 0 && sdl->sdl_nlen == 0 && sdl->sdl_alen == 0) + return snprintf(buf, len, "link#%hu", sdl->sdl_index); + dl_print(abuf, sizeof(abuf), &sdl->sdl_addr); return snprintf(buf, len, "[%s]:%hu", abuf, sdl->sdl_index); }