diff options
Diffstat (limited to 'epan/to_str.c')
-rw-r--r-- | epan/to_str.c | 28 |
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 |