Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src pretty-print link addresses.
details: https://anonhg.NetBSD.org/src/rev/3891ff168ce3
branches: trunk
changeset: 344605:3891ff168ce3
user: christos <christos%NetBSD.org@localhost>
date: Wed Apr 06 18:04:58 2016 +0000
description:
pretty-print link addresses.
diffstat:
lib/libutil/sockaddr_snprintf.c | 19 +++++++++++++------
sys/net/dl_print.c | 9 ++++++---
2 files changed, 19 insertions(+), 9 deletions(-)
diffs (72 lines):
diff -r f3fc370c0b95 -r 3891ff168ce3 lib/libutil/sockaddr_snprintf.c
--- a/lib/libutil/sockaddr_snprintf.c Wed Apr 06 17:34:33 2016 +0000
+++ b/lib/libutil/sockaddr_snprintf.c Wed Apr 06 18:04:58 2016 +0000
@@ -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 <sys/cdefs.h>
#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 <sys/types.h>
@@ -159,10 +159,17 @@
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 -r f3fc370c0b95 -r 3891ff168ce3 sys/net/dl_print.c
--- a/sys/net/dl_print.c Wed Apr 06 17:34:33 2016 +0000
+++ b/sys/net/dl_print.c Wed Apr 06 18:04:58 2016 +0000
@@ -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 <sys/types.h>
#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 <sys/systm.h>
#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 <stdio.h>
static const uint8_t hexdigits[] = "0123456789abcdef";
#endif
@@ -83,6 +83,9 @@
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);
}
Home |
Main Index |
Thread Index |
Old Index