[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r36425 - gnunet/src/cadet
From: |
gnunet |
Subject: |
[GNUnet-SVN] r36425 - gnunet/src/cadet |
Date: |
Fri, 2 Oct 2015 05:37:51 +0200 |
Author: bartpolot
Date: 2015-10-02 05:37:50 +0200 (Fri, 02 Oct 2015)
New Revision: 36425
Modified:
gnunet/src/cadet/cadet.h
gnunet/src/cadet/cadet_common.c
Log:
- added hexdump-like function to write binary data to log
Modified: gnunet/src/cadet/cadet.h
===================================================================
--- gnunet/src/cadet/cadet.h 2015-10-02 03:37:49 UTC (rev 36424)
+++ gnunet/src/cadet/cadet.h 2015-10-02 03:37:50 UTC (rev 36425)
@@ -328,7 +328,20 @@
const char *
GC_h2s (const struct GNUNET_CADET_Hash *id);
+
/**
+ * Allocate a string with a hexdump of any binary data.
+ *
+ * @param bin Arbitrary binary data.
+ * @param len Length of @a bin in bytes.
+ * @param output Where to write the output (if *output be NULL it's allocated).
+ *
+ * @return The size of the output.
+ */
+size_t
+GC_bin2s (void *bin, unsigned int len, char **output);
+
+/**
* Convert a message type into a string to help debug
* Generated with:
* FIND: "#define ([^ ]+)[ ]*([0-9]+)"
Modified: gnunet/src/cadet/cadet_common.c
===================================================================
--- gnunet/src/cadet/cadet_common.c 2015-10-02 03:37:49 UTC (rev 36424)
+++ gnunet/src/cadet/cadet_common.c 2015-10-02 03:37:50 UTC (rev 36425)
@@ -99,6 +99,38 @@
}
+/**
+ * Allocate a string with a hexdump of any binary data.
+ *
+ * @param bin Arbitrary binary data.
+ * @param len Length of @a bin in bytes.
+ * @param output Where to write the output (if *output be NULL it's allocated).
+ *
+ * @return The size of the output.
+ */
+size_t
+GC_bin2s (void *bin, unsigned int len, char **output)
+{
+ char *data = bin;
+ char *buf;
+ unsigned int s_len;
+ unsigned int i;
+
+ s_len = 2 * len + 1;
+ if (NULL == *output)
+ *output = GNUNET_malloc (s_len);
+ buf = *output;
+
+ for (i = 0; i < len; i++)
+ {
+ SPRINTF (&buf[2 * i], "%2X", data[i]);
+ }
+ buf[s_len - 1] = '\0';
+
+ return s_len;
+}
+
+
#if !defined(GNUNET_CULL_LOGGING)
const char *
GC_m2s (uint16_t m)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r36425 - gnunet/src/cadet,
gnunet <=