diff options
Diffstat (limited to 'src/cadet/cadet_common.c')
-rw-r--r-- | src/cadet/cadet_common.c | 32 |
1 files changed, 32 insertions, 0 deletions
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 | */ | ||
111 | size_t | ||
112 | GC_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) |
103 | const char * | 135 | const char * |
104 | GC_m2s (uint16_t m) | 136 | GC_m2s (uint16_t m) |