summaryrefslogtreecommitdiffstats
path: root/lib/util
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/util.c17
-rw-r--r--lib/util/util.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index a18926c..36d45b8 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -19,6 +19,7 @@
#include <assert.h>
#include <util/util.h>
+#include <talloc/talloc.h>
static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f', };
@@ -47,3 +48,19 @@ void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen)
return;
}
+
+char *format_buffer(void *ctx, const uint8_t *buf, unsigned int len)
+{
+ char *str;
+ unsigned int i;
+
+ if (len == 0)
+ return "";
+
+ str = talloc_asprintf(ctx, "0x%02x%s", buf[0], len > 1 ? " " : "");
+ for (i = 1; i < len; i++)
+ str = talloc_asprintf_append(str, "0x%02x%s", buf[i],
+ ((i + 1) % 8 == 0 && i != len - 1) ? "\n" : " ");
+
+ return str;
+}
diff --git a/lib/util/util.h b/lib/util/util.h
index 39966d0..a579221 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -50,6 +50,7 @@
do { (void)sizeof(char[(x)?1:-1]); } while (0)
void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen);
+char *format_buffer(void *ctx, const uint8_t *buf, unsigned int len);
#endif /* UTIL_H */
OpenPOWER on IntegriCloud