diff options
author | Evan Huus <eapache@gmail.com> | 2013-12-19 20:53:44 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2013-12-19 20:53:44 +0000 |
commit | 6be37815a19a8b34713831d131c1843d1f20ed7e (patch) | |
tree | d6b217db73573a3e05b1e269a93cc7e1dec94e87 | |
parent | 1ed5971a72e53ed182d6ac90ac0c313b6bcdc234 (diff) | |
download | wireshark-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
-rw-r--r-- | asn1/snmp/snmp.cnf | 2 | ||||
-rw-r--r-- | epan/addr_resolv.c | 3 | ||||
-rw-r--r-- | epan/dissectors/packet-data.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-frame.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-snmp.c | 2 | ||||
-rw-r--r-- | epan/to_str.c | 28 | ||||
-rw-r--r-- | epan/to_str.h | 3 | ||||
-rw-r--r-- | plugins/wimaxasncp/packet-wimaxasncp.c | 8 |
8 files changed, 41 insertions, 9 deletions
diff --git a/asn1/snmp/snmp.cnf b/asn1/snmp/snmp.cnf index 09a83dbe60..be6eb81562 100644 --- a/asn1/snmp/snmp.cnf +++ b/asn1/snmp/snmp.cnf @@ -201,7 +201,7 @@ gint pdu_type=-1; if (usm_p.authOK) { expert = &ei_snmp_authentication_ok; } else { - const gchar* calc_auth_str = bytestring_to_str(calc_auth,calc_auth_len,' '); + const gchar* calc_auth_str = bytestring_to_str(wmem_packet_scope(), calc_auth,calc_auth_len,' '); proto_item_append_text(authen_item, " calculated = %s", calc_auth_str); expert = &ei_snmp_authentication_error; } diff --git a/epan/addr_resolv.c b/epan/addr_resolv.c index 3e594cb259..0815e22802 100644 --- a/epan/addr_resolv.c +++ b/epan/addr_resolv.c @@ -129,6 +129,7 @@ #include <wsutil/pint.h> #include <epan/strutil.h> +#include <epan/to_str-int.h> #include <epan/prefs.h> #include <epan/emem.h> @@ -1700,7 +1701,7 @@ eth_hash_new_entry(const guint8 *addr, const gboolean resolve) tp = g_new(hashether_t, 1); memcpy(tp->addr, addr, sizeof(tp->addr)); tp->status = HASHETHER_STATUS_UNRESOLVED; - g_strlcpy(tp->hexaddr, bytestring_to_ep_str(addr, sizeof(tp->addr), ':'), sizeof(tp->hexaddr)); + bytes_to_hexstr_punct(tp->hexaddr, addr, sizeof(tp->addr), ':'); tp->resolved_name[0] = '\0'; if (resolve) diff --git a/epan/dissectors/packet-data.c b/epan/dissectors/packet-data.c index e6f77db027..7d31975210 100644 --- a/epan/dissectors/packet-data.c +++ b/epan/dissectors/packet-data.c @@ -105,7 +105,7 @@ dissect_data(tvbuff_t *tvb, packet_info *pinfo _U_ , proto_tree *tree) md5_append(&md_ctx, cp, bytes); md5_finish(&md_ctx, digest); - digest_string = bytestring_to_ep_str(digest, 16, '\0'); + digest_string = bytestring_to_str(wmem_packet_scope(), digest, 16, '\0'); ti = proto_tree_add_string(data_tree, &hfi_data_md5_hash, tvb, 0, 0, digest_string); PROTO_ITEM_SET_GENERATED(ti); } diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index 9666be4562..c46202d5db 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -397,7 +397,7 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) md5_append(&md_ctx, cp, cap_len); md5_finish(&md_ctx, digest); - digest_string = bytestring_to_ep_str(digest, 16, '\0'); + digest_string = bytestring_to_str(wmem_packet_scope(), digest, 16, '\0'); ti = proto_tree_add_string(fh_tree, hf_frame_md5_hash, tvb, 0, 0, digest_string); PROTO_ITEM_SET_GENERATED(ti); } diff --git a/epan/dissectors/packet-snmp.c b/epan/dissectors/packet-snmp.c index 72c95098ea..e0606e882e 100644 --- a/epan/dissectors/packet-snmp.c +++ b/epan/dissectors/packet-snmp.c @@ -2695,7 +2695,7 @@ dissect_snmp_SNMPv3Message(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int off if (usm_p.authOK) { expert = &ei_snmp_authentication_ok; } else { - const gchar* calc_auth_str = bytestring_to_ep_str(calc_auth,calc_auth_len,' '); + const gchar* calc_auth_str = bytestring_to_str(wmem_packet_scope(), calc_auth,calc_auth_len,' '); proto_item_append_text(authen_item, " calculated = %s", calc_auth_str); expert = &ei_snmp_authentication_error; } 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 diff --git a/epan/to_str.h b/epan/to_str.h index cf081c763f..beb63eab8b 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -125,8 +125,11 @@ WS_DLL_PUBLIC gchar *bytes_to_ep_str(const guint8 *bd, int bd_len); */ WS_DLL_PUBLIC gchar *bytes_to_ep_str_punct(const guint8 *bd, int bd_len, gchar punct); +/* Deprecated, use bytestring_to_str instead */ WS_DLL_PUBLIC const gchar *bytestring_to_ep_str(const guint8 *, const guint32, const char punct); +WS_DLL_PUBLIC const gchar *bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/plugins/wimaxasncp/packet-wimaxasncp.c b/plugins/wimaxasncp/packet-wimaxasncp.c index 6662b5bac5..9f70311e85 100644 --- a/plugins/wimaxasncp/packet-wimaxasncp.c +++ b/plugins/wimaxasncp/packet-wimaxasncp.c @@ -1070,7 +1070,7 @@ static void wimaxasncp_dissect_tlv_value( const gchar *format1; const gchar *format2; const guint8 *p = tvb_get_ptr(tvb, offset, length); - const gchar *s = bytestring_to_ep_str(p, MIN(length, max_show_bytes), 0); + const gchar *s = bytestring_to_str(wmem_packet_scope(), p, MIN(length, max_show_bytes), 0); if (length <= max_show_bytes) { @@ -1250,7 +1250,7 @@ static void wimaxasncp_dissect_tlv_value( { const gchar *format; const guint8 *p = tvb_get_ptr(tvb, offset, length); - const gchar *s = bytestring_to_ep_str(p, MIN(length, max_show_bytes), 0); + const gchar *s = bytestring_to_str(wmem_packet_scope(), p, MIN(length, max_show_bytes), 0); if (length <= max_show_bytes) { @@ -1770,7 +1770,7 @@ static void wimaxasncp_dissect_tlv_value( const gchar *format2; const guint8 *p = tvb_get_ptr(tvb, offset, length); const gchar *s = - bytestring_to_ep_str(p, MIN(length, max_show_bytes), 0); + bytestring_to_str(wmem_packet_scope(), p, MIN(length, max_show_bytes), 0); if (length <= max_show_bytes) { @@ -1810,7 +1810,7 @@ static void wimaxasncp_dissect_tlv_value( { const gchar *format; const guint8 *p = tvb_get_ptr(tvb, offset, length); - const gchar *s = bytestring_to_ep_str(p, MIN(length, max_show_bytes), 0); + const gchar *s = bytestring_to_str(wmem_packet_scope(), p, MIN(length, max_show_bytes), 0); if (length <= max_show_bytes) { |