diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-07-30 11:40:32 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-07-30 11:40:32 +0200 |
commit | 40481e895453c53d71f2f254b931b77c830c9e0a (patch) | |
tree | 4699953396361534765d34db3cdf37b690fac6b3 /src/utils.c | |
parent | 3eba991b3d005c3ae4aafe2235558a60e06b49f4 (diff) |
move hexdump() from logging.c to utils.c
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index 05381c8b..a6c2d6d2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -75,3 +75,22 @@ int hexparse(const char *str, uint8_t *b, int max_len) return i>>1; } + +static char hexd_buff[4096]; + +char *hexdump(const unsigned char *buf, int len) +{ + int i; + char *cur = hexd_buff; + + hexd_buff[0] = 0; + for (i = 0; i < len; i++) { + int len_remain = sizeof(hexd_buff) - (cur - hexd_buff); + int rc = snprintf(cur, len_remain, "%02x ", buf[i]); + if (rc <= 0) + break; + cur += rc; + } + hexd_buff[sizeof(hexd_buff)-1] = 0; + return hexd_buff; +} |