aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonnie Sahlberg <ronnie_sahlberg@ozemail.com.au>2005-07-28 08:55:11 +0000
committerRonnie Sahlberg <ronnie_sahlberg@ozemail.com.au>2005-07-28 08:55:11 +0000
commit93c4543207129c4723d35a200c5ca6f9faa61551 (patch)
treea091d603d99dedb4a242903b60b871ce30223223
parent34c10c4c7e5097be2dea416cc9e86db4d275481c (diff)
downloadwireshark-93c4543207129c4723d35a200c5ca6f9faa61551.tar.gz
wireshark-93c4543207129c4723d35a200c5ca6f9faa61551.tar.bz2
wireshark-93c4543207129c4723d35a200c5ca6f9faa61551.zip
add an ep version of tvb_fake_unicode()
svn path=/trunk/; revision=15128
-rw-r--r--epan/tvbuff.c38
-rw-r--r--epan/tvbuff.h6
2 files changed, 44 insertions, 0 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index ab6bd7896f..2c67d564db 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -1683,6 +1683,44 @@ tvb_fake_unicode(tvbuff_t *tvb, int offset, int len, gboolean little_endian)
return buffer;
}
+/* Convert a string from Unicode to ASCII. At the moment we fake it by
+ * replacing all non-ASCII characters with a '.' )-: The caller must
+ * free the result returned. The len parameter is the number of guint16's
+ * to convert from Unicode.
+ *
+ * This function allocates memory from a buffer with packet lifetime.
+ * You do not have to free this buffer, it will be automatically freed
+ * when ethereal starts decoding the next packet.
+ * Do not use this function if you want the allocated memory to be persistent
+ * after the current packet has been dissected.
+ */
+char *
+ep_tvb_fake_unicode(tvbuff_t *tvb, int offset, int len, gboolean little_endian)
+{
+ char *buffer;
+ int i;
+ guint16 character;
+
+ /* Make sure we have enough data before allocating the buffer,
+ so we don't blow up if the length is huge. */
+ tvb_ensure_bytes_exist(tvb, offset, 2*len);
+
+ /* We know we won't throw an exception, so we don't have to worry
+ about leaking this buffer. */
+ buffer = ep_alloc(len + 1);
+
+ for (i = 0; i < len; i++) {
+ character = little_endian ? tvb_get_letohs(tvb, offset)
+ : tvb_get_ntohs(tvb, offset);
+ buffer[i] = character < 256 ? character : '.';
+ offset += 2;
+ }
+
+ buffer[len] = 0;
+
+ return buffer;
+}
+
/*
* Format the data in the tvb from offset for length ...
*/
diff --git a/epan/tvbuff.h b/epan/tvbuff.h
index 064391d191..ca367978fb 100644
--- a/epan/tvbuff.h
+++ b/epan/tvbuff.h
@@ -395,6 +395,12 @@ extern gint tvb_strnlen(tvbuff_t*, gint offset, guint maxlength);
* convert from Unicode. */
extern char *tvb_fake_unicode(tvbuff_t *tvb, int offset, int len,
gboolean little_endian);
+/* Same as above but the buffer returned from this function does not have to
+ * be freed. It will be automatically freed after the packet is dissected.
+ * Buffers allocated by this function are NOT persistent.
+ */
+extern char *ep_tvb_fake_unicode(tvbuff_t *tvb, int offset, int len,
+ gboolean little_endian);
/**
* Format the data in the tvb from offset for size ...