diff options
| -rw-r--r-- | usr.sbin/switchd/switchd.h | 3 | ||||
| -rw-r--r-- | usr.sbin/switchd/util.c | 23 |
2 files changed, 24 insertions, 2 deletions
diff --git a/usr.sbin/switchd/switchd.h b/usr.sbin/switchd/switchd.h index 463cea46ee8..ae03d05e401 100644 --- a/usr.sbin/switchd/switchd.h +++ b/usr.sbin/switchd/switchd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: switchd.h,v 1.9 2016/09/29 18:25:54 reyk Exp $ */ +/* $OpenBSD: switchd.h,v 1.10 2016/09/29 20:46:06 reyk Exp $ */ /* * Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org> @@ -173,6 +173,7 @@ void print_verbose(const char *emsg, ...) __attribute__((__format__ (printf, 1, 2))); void print_debug(const char *emsg, ...) __attribute__((__format__ (printf, 1, 2))); +void print_hex(uint8_t *, off_t, size_t); void getmonotime(struct timeval *); int parsehostport(const char *, struct sockaddr *, socklen_t); diff --git a/usr.sbin/switchd/util.c b/usr.sbin/switchd/util.c index 620c650b3c7..716423c7460 100644 --- a/usr.sbin/switchd/util.c +++ b/usr.sbin/switchd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.2 2016/09/29 18:13:50 reyk Exp $ */ +/* $OpenBSD: util.c,v 1.3 2016/09/29 20:46:06 reyk Exp $ */ /* * Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org> @@ -293,6 +293,27 @@ print_verbose(const char *emsg, ...) } } +void +print_hex(uint8_t *buf, off_t offset, size_t length) +{ + unsigned int i; + extern int verbose; + + if (verbose < 3 || !length) + return; + + for (i = 0; i < length; i++) { + if (i && (i % 4) == 0) { + if ((i % 32) == 0) + print_debug("\n"); + else + print_debug(" "); + } + print_debug("%02x", buf[offset + i]); + } + print_debug("\n"); +} + int parsehostport(const char *str, struct sockaddr *sa, socklen_t salen) { |
