summaryrefslogtreecommitdiff
path: root/epan/strutil.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-11-13 07:19:37 +0000
committerGuy Harris <guy@alum.mit.edu>2000-11-13 07:19:37 +0000
commit99c98f9e74d8d812e0e87c960970116bf149434b (patch)
treed3b2949261e9970321c2a8fac4be3d2baaeb63c1 /epan/strutil.c
parent796997a538eede8129af9fbb938b3b1cc8bc719d (diff)
downloadwireshark-99c98f9e74d8d812e0e87c960970116bf149434b.tar.gz
Move "bytes_to_str()" to "strutil.c" from "packet.c" - it's just a
string formatter, like "format_text()", and, as "tvbuff.c" now calls it (*vide infra*), we don't want to have to make "tvbuff.c" drag "packet.h" in just to declare "bytes_to_str()". It's now declared in "strutil.h", so include it in modules that use "bytes_to_str()" and weren't already including it. Add a "tvb_bytes_to_str()" wrapper that calls "tvb_get_ptr()" to get a pointer to a chunk of N bytes at a given offset in a tvbuff and then hands that chunk to "bytes_to_str()". Convert the code that was doing that to use "tvb_bytes_to_str()" instead (which caught what I suspect is a bug in the Q.2931 dissector, where it was handing an offset of 0 to "tvb_get_ptr()" - a cut-and-pasteo, I think). Tvbuffify the ARP dissector. svn path=/trunk/; revision=2634
Diffstat (limited to 'epan/strutil.c')
-rw-r--r--epan/strutil.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/epan/strutil.c b/epan/strutil.c
index a01c3453ae..8c73202dd9 100644
--- a/epan/strutil.c
+++ b/epan/strutil.c
@@ -1,7 +1,7 @@
/* strutil.c
* String utility routines
*
- * $Id: strutil.c,v 1.5 2000/11/10 06:50:37 guy Exp $
+ * $Id: strutil.c,v 1.6 2000/11/13 07:19:32 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -238,3 +238,41 @@ format_text(const u_char *string, int len)
fmtbuf[column] = '\0';
return fmtbuf;
}
+
+/* Max string length for displaying byte string. */
+#define MAX_BYTE_STR_LEN 32
+
+/* Turn an array of bytes into a string showing the bytes in hex. */
+#define N_BYTES_TO_STR_STRINGS 6
+gchar *
+bytes_to_str(const guint8 *bd, int bd_len) {
+ static gchar str[N_BYTES_TO_STR_STRINGS][MAX_BYTE_STR_LEN+3+1];
+ static int cur_idx;
+ gchar *cur;
+ gchar *p;
+ int len;
+ static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+ cur_idx++;
+ if (cur_idx >= N_BYTES_TO_STR_STRINGS)
+ cur_idx = 0;
+ cur = &str[cur_idx][0];
+ p = cur;
+ len = MAX_BYTE_STR_LEN;
+ while (bd_len > 0 && len > 0) {
+ *p++ = hex[(*bd) >> 4];
+ *p++ = hex[(*bd) & 0xF];
+ len -= 2;
+ bd++;
+ bd_len--;
+ }
+ if (bd_len != 0) {
+ /* Note that we're not showing the full string. */
+ *p++ = '.';
+ *p++ = '.';
+ *p++ = '.';
+ }
+ *p = '\0';
+ return cur;
+}