aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-10-02 03:37:50 +0000
committerBart Polot <bart@net.in.tum.de>2015-10-02 03:37:50 +0000
commitcef0009520797f29eefb74e68a0020e4cdb3d5a8 (patch)
treebefdcca569ada96083d5f1bf97586db88c42ce99 /src/cadet
parentea4df299159c854db3e04244455c7628d94a66a2 (diff)
downloadgnunet-cef0009520797f29eefb74e68a0020e4cdb3d5a8.tar.gz
gnunet-cef0009520797f29eefb74e68a0020e4cdb3d5a8.zip
- added hexdump-like function to write binary data to log
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet.h13
-rw-r--r--src/cadet/cadet_common.c32
2 files changed, 45 insertions, 0 deletions
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h
index 83b91ab5a..3c729e22c 100644
--- a/src/cadet/cadet.h
+++ b/src/cadet/cadet.h
@@ -328,6 +328,19 @@ GC_h2hc (const struct GNUNET_CADET_Hash *id);
328const char * 328const char *
329GC_h2s (const struct GNUNET_CADET_Hash *id); 329GC_h2s (const struct GNUNET_CADET_Hash *id);
330 330
331
332/**
333 * Allocate a string with a hexdump of any binary data.
334 *
335 * @param bin Arbitrary binary data.
336 * @param len Length of @a bin in bytes.
337 * @param output Where to write the output (if *output be NULL it's allocated).
338 *
339 * @return The size of the output.
340 */
341size_t
342GC_bin2s (void *bin, unsigned int len, char **output);
343
331/** 344/**
332 * Convert a message type into a string to help debug 345 * Convert a message type into a string to help debug
333 * Generated with: 346 * Generated with:
diff --git a/src/cadet/cadet_common.c b/src/cadet/cadet_common.c
index dbb62d392..360fbcee6 100644
--- a/src/cadet/cadet_common.c
+++ b/src/cadet/cadet_common.c
@@ -99,6 +99,38 @@ GC_h2s (const struct GNUNET_CADET_Hash *id)
99} 99}
100 100
101 101
102/**
103 * Allocate a string with a hexdump of any binary data.
104 *
105 * @param bin Arbitrary binary data.
106 * @param len Length of @a bin in bytes.
107 * @param output Where to write the output (if *output be NULL it's allocated).
108 *
109 * @return The size of the output.
110 */
111size_t
112GC_bin2s (void *bin, unsigned int len, char **output)
113{
114 char *data = bin;
115 char *buf;
116 unsigned int s_len;
117 unsigned int i;
118
119 s_len = 2 * len + 1;
120 if (NULL == *output)
121 *output = GNUNET_malloc (s_len);
122 buf = *output;
123
124 for (i = 0; i < len; i++)
125 {
126 SPRINTF (&buf[2 * i], "%2X", data[i]);
127 }
128 buf[s_len - 1] = '\0';
129
130 return s_len;
131}
132
133
102#if !defined(GNUNET_CULL_LOGGING) 134#if !defined(GNUNET_CULL_LOGGING)
103const char * 135const char *
104GC_m2s (uint16_t m) 136GC_m2s (uint16_t m)