diff options
author | Guy Harris <guy@alum.mit.edu> | 2005-08-28 06:44:06 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2005-08-28 06:44:06 +0000 |
commit | 374c3d0b7581648039cae9a16318619ad5340e29 (patch) | |
tree | aef7dab7ca1133ccd8dc5d37a6b2612d2016e1bd /epan/to_str.c | |
parent | d7f391d333c8e81515d64be3c0dc995c0eb91dce (diff) |
Export "bytestring_to_str()", and use it when adding the link-layer
address for the ND_OPT_TARGET_LINKADDR ICMPv6 packet type.
svn path=/trunk/; revision=15591
Diffstat (limited to 'epan/to_str.c')
-rw-r--r-- | epan/to_str.c | 21 |
1 files changed, 11 insertions, 10 deletions
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]; |