Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libutil Add a debugging format that prints all the field...
details: https://anonhg.NetBSD.org/src/rev/01b30f367366
branches: trunk
changeset: 787231:01b30f367366
user: christos <christos%NetBSD.org@localhost>
date: Fri Jun 07 17:23:26 2013 +0000
description:
Add a debugging format that prints all the fields with names.
diffstat:
lib/libutil/sockaddr_snprintf.3 | 8 ++-
lib/libutil/sockaddr_snprintf.c | 88 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 92 insertions(+), 4 deletions(-)
diffs (148 lines):
diff -r f07d70be4600 -r 01b30f367366 lib/libutil/sockaddr_snprintf.3
--- a/lib/libutil/sockaddr_snprintf.3 Fri Jun 07 17:18:33 2013 +0000
+++ b/lib/libutil/sockaddr_snprintf.3 Fri Jun 07 17:23:26 2013 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: sockaddr_snprintf.3,v 1.7 2009/04/11 16:13:49 joerg Exp $
+.\" $NetBSD: sockaddr_snprintf.3,v 1.8 2013/06/07 17:23:26 christos Exp $
.\"
.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd April 9, 2005
+.Dd June 7, 2013
.Dt SOCKADDR_SNPRINTF 3
.Os
.Sh NAME
@@ -109,6 +109,10 @@
For all other address families, it is the same as the
.Dq a
format.
+.It D
+Debugging output:
+For all addresses, print all their fields as
+.Dq field_name=value .
.It f
The numeric value of the family of the address is printed.
.It l
diff -r f07d70be4600 -r 01b30f367366 lib/libutil/sockaddr_snprintf.c
--- a/lib/libutil/sockaddr_snprintf.c Fri Jun 07 17:18:33 2013 +0000
+++ b/lib/libutil/sockaddr_snprintf.c Fri Jun 07 17:23:26 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sockaddr_snprintf.c,v 1.9 2008/04/28 20:23:03 martin Exp $ */
+/* $NetBSD: sockaddr_snprintf.c,v 1.10 2013/06/07 17:23:26 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.9 2008/04/28 20:23:03 martin Exp $");
+__RCSID("$NetBSD: sockaddr_snprintf.c,v 1.10 2013/06/07 17:23:26 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -44,9 +44,71 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <stdlib.h>
#include <util.h>
#include <netdb.h>
+static int
+debug_at(char *str, size_t len, const struct sockaddr_at *sat)
+{
+ return snprintf(str, len, "sat_len=%u, sat_family=%u, sat_port=%u, "
+ "sat_addr.s_net=%u, sat_addr.s_node=%u, "
+ "sat_range.r_netrange.nr_phase=%u, "
+ "sat_range.r_netrange.nr_firstnet=%u, "
+ "sat_range.r_netrange.nr_lastnet=%u",
+ sat->sat_len, sat->sat_family, sat->sat_port,
+ sat->sat_addr.s_net, sat->sat_addr.s_node,
+ sat->sat_range.r_netrange.nr_phase,
+ sat->sat_range.r_netrange.nr_firstnet,
+ sat->sat_range.r_netrange.nr_lastnet);
+}
+
+static int
+debug_in(char *str, size_t len, const struct sockaddr_in *sin)
+{
+ return snprintf(str, len, "sin_len=%u, sin_family=%u, sin_port=%u, "
+ "sin_addr.s_addr=%08x",
+ sin->sin_len, sin->sin_family, sin->sin_port,
+ sin->sin_addr.s_addr);
+}
+
+static int
+debug_in6(char *str, size_t len, const struct sockaddr_in6 *sin6)
+{
+ const uint8_t *s = sin6->sin6_addr.s6_addr;
+
+ return snprintf(str, len, "sin6_len=%u, sin6_family=%u, sin6_port=%u, "
+ "sin6_flowinfo=%u, "
+ "sin6_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:"
+ "%02x:%02x:%02x:%02x:%02x:%02x, sin6_scope_id=%u",
+ sin6->sin6_len, sin6->sin6_family, sin6->sin6_port,
+ sin6->sin6_flowinfo, s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5],
+ s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb], s[0xc], s[0xd],
+ s[0xe], s[0xf], sin6->sin6_scope_id);
+}
+
+static int
+debug_un(char *str, size_t len, const struct sockaddr_un *sun)
+{
+ return snprintf(str, len, "sun_len=%u, sun_family=%u, sun_path=%*s",
+ sun->sun_len, sun->sun_family, (int)sizeof(sun->sun_path),
+ sun->sun_path);
+}
+
+static int
+debug_dl(char *str, size_t len, const struct sockaddr_dl *sdl)
+{
+ const uint8_t *s = (const void *)sdl->sdl_data;
+
+ return snprintf(str, len, "sdl_len=%u, sdl_family=%u, sdl_index=%u, "
+ "sdl_type=%u, sdl_nlen=%u, sdl_alen=%u, sdl_slen=%u, sdl_data="
+ "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
+ sdl->sdl_len, sdl->sdl_family, sdl->sdl_index,
+ sdl->sdl_type, sdl->sdl_nlen, sdl->sdl_alen, sdl->sdl_slen,
+ s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5],
+ s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb]);
+}
+
int
sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt,
const struct sockaddr * const sa)
@@ -207,6 +269,28 @@
ADDNA();
}
break;
+ case 'D':
+ switch (sa->sa_family) {
+ case AF_APPLETALK:
+ debug_at(nbuf, sizeof(nbuf), sat);
+ break;
+ case AF_LOCAL:
+ debug_un(nbuf, sizeof(nbuf), sun);
+ break;
+ case AF_INET:
+ debug_in(nbuf, sizeof(nbuf), sin4);
+ break;
+ case AF_INET6:
+ debug_in6(nbuf, sizeof(nbuf), sin6);
+ break;
+ case AF_LINK:
+ debug_dl(nbuf, sizeof(nbuf), sdl);
+ break;
+ default:
+ abort();
+ }
+ ADDS(nbuf);
+ break;
default:
ADDC('%');
if (na == 0)
Home |
Main Index |
Thread Index |
Old Index