diff options
author | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2018-11-12 12:01:05 +1100 |
---|---|---|
committer | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2018-11-16 13:55:29 +1100 |
commit | cf30fdd3100a425f2f01214ca726f0641f844eec (patch) | |
tree | 579c4082794e909d71ea172a1948ed553ed19b17 /lib/util/util.c | |
parent | 2bc0df4aa35a89c5af7e54f459e2bbde20ca6a7e (diff) | |
download | talos-petitboot-cf30fdd3100a425f2f01214ca726f0641f844eec.tar.gz talos-petitboot-cf30fdd3100a425f2f01214ca726f0641f844eec.zip |
discover: Nicely format IPMI response buffersv1.9.2
A few places where we print out the response buffer from an IPMI command
weren't updated when log timestamps were added, resulting in very hard
to read output. Add a little helper to format buffers and use it to
print these with only one timestamp.
Example:
[04:59:01] ipmi_get_bmc_versions: BMC version resp [0][16]:
0x00 0x20 0x01 0x02 0x13 0x02 0xbf 0x00
0x00 0x00 0xbb 0xaa 0x58 0x98 0x01 0x00
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'lib/util/util.c')
-rw-r--r-- | lib/util/util.c | 17 |
1 files changed, 17 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; +} |