diff options
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-icmpv6.c | 15 | ||||
-rw-r--r-- | epan/libethereal.def | 1 | ||||
-rw-r--r-- | epan/to_str.c | 21 | ||||
-rw-r--r-- | epan/to_str.h | 1 |
4 files changed, 16 insertions, 22 deletions
diff --git a/epan/dissectors/packet-icmpv6.c b/epan/dissectors/packet-icmpv6.c index f179350168..2dc9601120 100644 --- a/epan/dissectors/packet-icmpv6.c +++ b/epan/dissectors/packet-icmpv6.c @@ -215,22 +215,13 @@ again: case ND_OPT_SOURCE_LINKADDR: case ND_OPT_TARGET_LINKADDR: { - int len, i, p; - const guint8 *a; - char *t; + int len, p; p = offset + sizeof(*opt); len = (opt->nd_opt_len << 3) - sizeof(*opt); - a = tvb_get_ptr(tvb, p, len); - t = ep_alloc(len * 3); - memset(t, 0, len * 3); - for (i = 0; i < len; i++) { - if (i) - t[i * 3 - 1] = ':'; - g_snprintf(t+i*3, 2, "%02x", a[i]); - } proto_tree_add_text(icmp6opt_tree, tvb, - offset + sizeof(*opt), len, "Link-layer address: %s", t); + offset + sizeof(*opt), len, "Link-layer address: %s", + bytestring_to_str(tvb_get_ptr(tvb, p, len), len, ':')); break; } case ND_OPT_PREFIX_INFORMATION: diff --git a/epan/libethereal.def b/epan/libethereal.def index 7e8db18328..71d1c1ad4c 100644 --- a/epan/libethereal.def +++ b/epan/libethereal.def @@ -38,6 +38,7 @@ BandRejectReason_vals DATA build_follow_filter bytes_to_str_punct bytes_to_str +bytestring_to_str call_dissector capture_ap1394 capture_arcnet diff --git a/epan/to_str.c b/epan/to_str.c index 0431f66233..1c4ff2baa0 100644 --- a/epan/to_str.c +++ b/epan/to_str.c @@ -65,22 +65,20 @@ #include <time.h> #include "emem.h" -#define MAX_BYTESTRING_LEN 6 - /* Routine to convert a sequence of bytes to a hex string, one byte/two hex * digits at at a time, with a specified punctuation character between - * the bytes. The sequence of bytes must be no longer than - * MAX_BYTESTRING_LEN. + * the bytes. * * If punct is '\0', no punctuation is applied (and thus * the resulting string is (len-1) bytes shorter) */ -static gchar * +gchar * bytestring_to_str(const guint8 *ad, guint32 len, char punct) { gchar *buf; gchar *p; int i; guint32 octet; + size_t buflen; /* At least one version of Apple's C compiler/linker is buggy, causing a complaint from the linker about the "literal C string section" not ending with '\0' if we initialize a 16-element "char" array with @@ -91,13 +89,16 @@ bytestring_to_str(const guint8 *ad, guint32 len, char punct) { { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - g_assert(len > 0 && len <= MAX_BYTESTRING_LEN); - len--; + g_assert(len > 0); - buf=ep_alloc(MAX_BYTESTRING_LEN*3+1); - p = &buf[MAX_BYTESTRING_LEN*3]; + if (punct) + buflen=len*3; + else + buflen=len*2 + 1; + buf=ep_alloc(buflen); + p = &buf[buflen - 1]; *p = '\0'; - i = len; + i = len - 1; for (;;) { octet = ad[i]; *--p = hex_digits[octet&0xF]; diff --git a/epan/to_str.h b/epan/to_str.h index 55449f490d..e9997d62f3 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -54,6 +54,7 @@ struct e_in6_addr; extern gchar* address_to_str(const address *); extern void address_to_str_buf(const address *addr, gchar *buf, int buf_len); +extern gchar* bytestring_to_str(const guint8 *, guint32, char); extern gchar* ether_to_str(const guint8 *); extern gchar* ip_to_str(const guint8 *); extern void ip_to_str_buf(const guint8 *, gchar *); |