Added silc_hexdump.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 17 Jul 2007 17:26:09 +0000 (17:26 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 17 Jul 2007 17:26:09 +0000 (17:26 +0000)
CHANGES.RUNTIME
lib/silcutil/silclog.c
lib/silcutil/silcutil.c
lib/silcutil/silcutil.h

index 39b65e5ea30a75899db9946d435e274d925cb854..f43bd6ee0474286483f34e60fc53806f7cb4b280 100644 (file)
@@ -1,3 +1,7 @@
+Tue Jul 17 20:10:41 EEST 2007 Pekka Riikonen <priikone@silcnet.org>
+
+       * Added silc_hexdump to lib/silcutil/silcutil.[ch].
+
 Fri Jul 13 23:01:45 EEST 2007  Pekka Riikonen <priikone@silcnet.org>
 
        * Added SILC_GET32_X_MSB macro to lib/silcutil/silctypes.h.
index 824efb701389912d11b260450b86ea63e6ac12fe..56f5532c5dc9b534ce5ee36642dfbe3fe8db7bd7 100644 (file)
@@ -529,10 +529,6 @@ void silc_log_output_hexdump(char *file, const char *function,
                             int line, void *data_in,
                             SilcUInt32 len, char *string)
 {
-  int i, k;
-  int off, pos, count;
-  unsigned char *data = (unsigned char *)data_in;
-
 #ifndef SILC_SYMBIAN
   if (!silclog.debug_hexdump)
     goto end;
@@ -550,60 +546,7 @@ void silc_log_output_hexdump(char *file, const char *function,
 
   fprintf(stderr, "%s:%d: %s\n", function, line, string);
 
-  k = 0;
-  pos = 0;
-  count = 16;
-  off = len % 16;
-  while (1) {
-    if (off) {
-      if ((len - pos) < 16 && (len - pos <= len - off))
-       count = off;
-    } else {
-      if (pos == len)
-       count = 0;
-    }
-    if (off == len)
-      count = len;
-
-    if (count)
-      fprintf(stderr, "%08X  ", k++ * 16);
-
-    for (i = 0; i < count; i++) {
-      fprintf(stderr, "%02X ", data[pos + i]);
-
-      if ((i + 1) % 4 == 0)
-       fprintf(stderr, " ");
-    }
-
-    if (count && count < 16) {
-      int j;
-
-      for (j = 0; j < 16 - count; j++) {
-       fprintf(stderr, "   ");
-
-       if ((j + count + 1) % 4 == 0)
-         fprintf(stderr, " ");
-      }
-    }
-
-    for (i = 0; i < count; i++) {
-      char ch;
-
-      if (data[pos] < 32 || data[pos] >= 127)
-       ch = '.';
-      else
-       ch = data[pos];
-
-      fprintf(stderr, "%c", ch);
-      pos++;
-    }
-
-    if (count)
-      fprintf(stderr, "\n");
-
-    if (count < 16)
-      break;
-  }
+  silc_hexdump(data_in, len, stderr);
 
  end:
   silc_free(string);
index 12315f7f96255c303cd263d13cc071b51b26e90e..5cd09db067d6b3ea2495925848ae9a4395d59290 100644 (file)
@@ -565,3 +565,68 @@ char *silc_get_input(const char *prompt, SilcBool echo_off)
   return NULL;
 #endif /* SILC_UNIX */
 }
+
+/* Hexdump */
+
+void silc_hexdump(const unsigned char *data, SilcUInt32 data_len,
+                 FILE *output)
+{
+  int i, k;
+  int off, pos, count;
+  int len = data_len;
+
+  k = 0;
+  pos = 0;
+  count = 16;
+  off = len % 16;
+  while (1) {
+    if (off) {
+      if ((len - pos) < 16 && (len - pos <= len - off))
+       count = off;
+    } else {
+      if (pos == len)
+       count = 0;
+    }
+    if (off == len)
+      count = len;
+
+    if (count)
+      fprintf(output, "%08X  ", k++ * 16);
+
+    for (i = 0; i < count; i++) {
+      fprintf(output, "%02X ", data[pos + i]);
+
+      if ((i + 1) % 4 == 0)
+       fprintf(output, " ");
+    }
+
+    if (count && count < 16) {
+      int j;
+
+      for (j = 0; j < 16 - count; j++) {
+       fprintf(output, "   ");
+
+       if ((j + count + 1) % 4 == 0)
+         fprintf(output, " ");
+      }
+    }
+
+    for (i = 0; i < count; i++) {
+      char ch;
+
+      if (data[pos] < 32 || data[pos] >= 127)
+       ch = '.';
+      else
+       ch = data[pos];
+
+      fprintf(output, "%c", ch);
+      pos++;
+    }
+
+    if (count)
+      fprintf(output, "\n");
+
+    if (count < 16)
+      break;
+  }
+}
index f645569f2163fcb0f4ecba46eff72d18f3907a7b..c6b0d43f1938fb34d6bbba40f6d494cb222aa3f5 100644 (file)
@@ -433,4 +433,20 @@ char *silc_get_real_name();
 #define silc_va_copy(dest, src) dest = src;
 #endif
 
+/****f* silcutil/SilcUtilAPI/silc_hexdump
+ *
+ * SYNOPSIS
+ *
+ *    void silc_hexdump(const unsigned char *data, SilcUInt32 data_len,
+ *                      FILE *output);
+ *
+ * DESCRIPTION
+ *
+ *    Dumps the `data' of length of `data_len' bytes as HEX.  The `output'
+ *    file specifies the destination.
+ *
+ ***/
+void silc_hexdump(const unsigned char *data, SilcUInt32 data_len,
+                 FILE *output);
+
 #endif /* !SILCUTIL_H */