aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2011-07-03 17:08:25 +0000
committerGuy Harris <guy@alum.mit.edu>2011-07-03 17:08:25 +0000
commit338af96b2e28196d8dc800a6ca844108bc8f3041 (patch)
treec14e85b721dcab2bb7cadd9787bffc7a551cb2e2 /epan/tvbuff.c
parent8b303cc61a85c3efdb37171d21702ac112681e26 (diff)
Add a tvb_get_ephemeral_string_enc() routine that's like
tvb_get_ephemeral_string() but takes an ENC_ value for the character encoding. Use it in the MQ dissector to fetch strings to put, for example, into the Info column, so we properly handle EBCDIC strings there. svn path=/trunk/; revision=37876
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r--epan/tvbuff.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index cec87ce17e..7bbcc7a2bc 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -50,6 +50,7 @@
#include "tvbuff-int.h"
#include "strutil.h"
#include "emem.h"
+#include "charsets.h"
#include "proto.h" /* XXX - only used for DISSECTOR_ASSERT, probably a new header file? */
static const guint8*
@@ -2448,10 +2449,11 @@ tvb_get_unicode_string(tvbuff_t *tvb, const gint offset, gint length, const guin
}
/*
- * Given a tvbuff, an offset, and a length, allocate a buffer big enough
- * to hold a non-null-terminated string of that length at that offset,
- * plus a trailing '\0', copy the string into it, and return a pointer
- * to the string.
+ * Given a tvbuff, an offset, a length, and an encoding, allocate a
+ * buffer big enough to hold a non-null-terminated string of that length
+ * at that offset, plus a trailing '\0', copy the string into it, and
+ * return a pointer to the string; if the encoding is EBCDIC, map
+ * the string from EBCDIC to ASCII.
*
* Throws an exception if the tvbuff ends before the string does.
*
@@ -2462,7 +2464,8 @@ tvb_get_unicode_string(tvbuff_t *tvb, const gint offset, gint length, const guin
* after the current packet has been dissected.
*/
guint8 *
-tvb_get_ephemeral_string(tvbuff_t *tvb, const gint offset, const gint length)
+tvb_get_ephemeral_string_enc(tvbuff_t *tvb, const gint offset,
+ const gint length, const gint encoding)
{
const guint8 *ptr;
guint8 *strbuf = NULL;
@@ -2474,10 +2477,19 @@ tvb_get_ephemeral_string(tvbuff_t *tvb, const gint offset, const gint length)
if (length != 0) {
memcpy(strbuf, ptr, length);
}
+ if ((encoding & ENC_CHARENCODING_MASK) == ENC_EBCDIC)
+ EBCDIC_to_ASCII(strbuf, length);
strbuf[length] = '\0';
return strbuf;
}
+guint8 *
+tvb_get_ephemeral_string(tvbuff_t *tvb, const gint offset,
+ const gint length)
+{
+ return tvb_get_ephemeral_string_enc(tvb, offset, length, ENC_UTF_8|ENC_NA);
+}
+
/*
* Unicode (UTF-16) version of tvb_get_ephemeral_string()
*