summaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2011-02-08 16:55:03 +0100
committerHarald Welte <laforge@gnumonks.org>2011-02-08 16:55:03 +0100
commit3d0ac5e446314c08f3e590bb4dd976b551bff618 (patch)
tree237c37a59547bc9e308c24750f156823cdd2a487 /src/utils.c
parente7509083673381f5be0e66bf6d9d76195b5fad82 (diff)
[utils] add 'bitdump' function for bitfields
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 405039f6..52007931 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -95,6 +95,36 @@ static char *_hexdump(const unsigned char *buf, int len, char *delim)
return hexd_buff;
}
+char *bitdump(const uint8_t *bits, unsigned int len)
+{
+ int i;
+
+ if (len > sizeof(hexd_buff)-1)
+ len = sizeof(hexd_buff)-1;
+ memset(hexd_buff, 0, sizeof(hexd_buff));
+
+ for (i = 0; i < len; i++) {
+ char outch;
+ switch (bits[i]) {
+ case 0:
+ outch = '0';
+ break;
+ case 0xff:
+ outch = '?';
+ break;
+ case 1:
+ outch = '1';
+ break;
+ default:
+ outch = 'E';
+ break;
+ }
+ hexd_buff[i] = outch;
+ }
+ hexd_buff[sizeof(hexd_buff)-1] = 0;
+ return hexd_buff;
+}
+
char *hexdump(const unsigned char *buf, int len)
{
return _hexdump(buf, len, " ");