summaryrefslogtreecommitdiff
path: root/epan/to_str.c
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-12-19 20:53:44 +0000
committerEvan Huus <eapache@gmail.com>2013-12-19 20:53:44 +0000
commit6be37815a19a8b34713831d131c1843d1f20ed7e (patch)
treed6b217db73573a3e05b1e269a93cc7e1dec94e87 /epan/to_str.c
parent1ed5971a72e53ed182d6ac90ac0c313b6bcdc234 (diff)
downloadwireshark-6be37815a19a8b34713831d131c1843d1f20ed7e.tar.gz
Add bytestring_to_str() which takes a wmem scope and is otherwise identical to
bytestring_to_ep_str (now deprecated). Use the new one in a few obvious places. Also just print directly to the buffer when loading ethernet addresses for resolution. The straight-to-buffer bytes_to_hexstr seems useful, maybe it shouldn't be in a private header... svn path=/trunk/; revision=54270
Diffstat (limited to 'epan/to_str.c')
-rw-r--r--epan/to_str.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/epan/to_str.c b/epan/to_str.c
index 885d9fb124..5315020a90 100644
--- a/epan/to_str.c
+++ b/epan/to_str.c
@@ -30,6 +30,7 @@
#include <glib.h>
#include "emem.h"
+#include "wmem/wmem.h"
#include "proto.h"
#include "to_str.h"
#include "to_str-int.h"
@@ -187,6 +188,33 @@ bytestring_to_ep_str(const guint8 *ad, const guint32 len, const char punct) {
return buf;
}
+const gchar *
+bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct) {
+ gchar *buf;
+ size_t buflen;
+
+ if (!ad)
+ REPORT_DISSECTOR_BUG("Null pointer passed to bytestring_to_str()");
+
+ if (len == 0)
+ return wmem_strdup(scope, "");
+
+ if (punct)
+ buflen=len*3;
+ else
+ buflen=len*2 + 1;
+
+ buf=(gchar *)wmem_alloc(scope, buflen);
+
+ if (punct)
+ bytes_to_hexstr_punct(buf, ad, len, punct);
+ else
+ bytes_to_hexstr(buf, ad, len);
+
+ buf[buflen-1] = '\0';
+ return buf;
+}
+
/* Max string length for displaying byte string. */
#define MAX_BYTE_STR_LEN 48