New oid_to_str() and oid_to_str_buf() functions
authorkukosa <kukosa@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 28 Apr 2005 09:51:55 +0000 (09:51 +0000)
committerkukosa <kukosa@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 28 Apr 2005 09:51:55 +0000 (09:51 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@14216 f5534014-38df-0310-8fa8-9805f1628bb7

epan/to_str.c
epan/to_str.h

index 17d820768191b9c39c2ae26c9c9ab6b4fc6a7add..969e5c07b191a281ad4969a07461c5ce9303abeb 100644 (file)
@@ -892,3 +892,41 @@ address_to_str_buf(const address *addr, gchar *buf)
     g_assert_not_reached();
   }
 }
+
+gchar* oid_to_str(guint8 *oid, gint oid_len) {
+  /* static buffer */
+  static int cnt = 0;
+  static gchar strbuf[8][MAX_OID_STR_LEN];
+
+  cnt = (cnt + 1) % 8;
+  return oid_to_str_buf(oid, oid_len, strbuf[cnt]);
+}
+
+gchar* oid_to_str_buf(guint8 *oid, gint oid_len, gchar *buf) {
+  gint i;
+  guint8 byte;
+  guint32 value;
+  gchar *bufp;
+
+  bufp = buf; value=0;
+  for (i=0; i<oid_len; i++){
+    byte = oid[i];
+    if ((bufp - buf) > (MAX_OID_STR_LEN - 12)) {
+      bufp += sprintf(bufp, ".>>>");
+      break;
+    }
+    if (i == 0) {
+      bufp += sprintf(bufp, "%d.%d", byte/40, byte%40);
+      continue;
+    }
+    value = (value << 7) | (byte & 0x7F);
+    if (byte & 0x80) {
+      continue;
+    }
+    bufp += sprintf(bufp, ".%d", value);
+    value = 0;
+  }
+  *bufp = '\0';
+
+  return buf;
+}
index e2db7f4d8c17b5413c2847c3bdfe598e0c03e950..1f030bd36d9a550ee8f369ca0485c695f391a5b6 100644 (file)
@@ -30,6 +30,8 @@
 #include "nstime.h"
 #include "epan/packet_info.h"
 
+#define MAX_OID_STR_LEN 256
+
 /*
  * Resolution of a time stamp.
  */
@@ -67,6 +69,8 @@ extern gchar* abs_time_secs_to_str(time_t);
 extern void    display_signed_time(gchar *, int, gint32, gint32, time_res_t);
 extern gchar*  rel_time_to_str(nstime_t*);
 extern gchar*  rel_time_to_secs_str(nstime_t*);
+extern gchar*  oid_to_str(guint8*, gint);
+extern gchar*  oid_to_str_buf(guint8*, gint, gchar*);
 
 
 extern char    *other_decode_bitfield_value(char *buf, guint32 val, guint32 mask,