aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-02-24 01:22:30 +0000
committerGuy Harris <guy@alum.mit.edu>2003-02-24 01:22:30 +0000
commite345e5640e4d675c2de7b95077fa9ae3f8d07c9b (patch)
tree11e4f9c2e4d2fb3d24678348719e70d22ad98f97 /epan/tvbuff.c
parent1c159b152bf565048ea086621023612624b2901e (diff)
Rename "fake_unicode()" to "tvb_fake_unicode()" as it works on a tvbuff,
give it a byte-order argument, and move it to "epan/tvbuff.c". Use it to handle UCS-2 strings in version 1 of the Service Location Protocol. In SRVLOC V1, use registered fields that are already there for SRVLOC V2, and add some as needed. Fix some field names. svn path=/trunk/; revision=7186
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r--epan/tvbuff.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 94d707ccb9..4e8a2c2f0d 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -9,7 +9,7 @@
* the data of a backing tvbuff, or can be a composite of
* other tvbuffs.
*
- * $Id: tvbuff.c,v 1.40 2002/08/28 20:40:45 jmayer Exp $
+ * $Id: tvbuff.c,v 1.41 2003/02/24 01:22:26 guy Exp $
*
* Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
*
@@ -1617,6 +1617,41 @@ tvb_memeql(tvbuff_t *tvb, gint offset, const guint8 *str, gint size)
}
}
+/* Convert a string from Unicode to ASCII. At the moment we fake it by
+ * assuming all characters are ASCII )-: The caller must free the
+ * result returned. The len parameter is the number of guint16's to
+ * convert from Unicode. */
+char *
+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.
+ We do so by attempting to fetch the last character; it'll
+ throw an exception if it's past the end.
+
+ The byte order we use to fetch it is irrelevant here. */
+ tvb_get_letohs(tvb, offset + 2*(len - 1));
+
+ /* We know we won't throw an exception, so we don't have to worry
+ about leaking this buffer. */
+ buffer = g_malloc(len + 1);
+
+ for (i = 0; i < len; i++) {
+ character = little_endian ? tvb_get_letohs(tvb, offset)
+ : tvb_get_ntohs(tvb, offset);
+ buffer[i] = character & 0xff;
+ offset += 2;
+ }
+
+ buffer[len] = 0;
+
+ return buffer;
+}
+
/*
* Format the data in the tvb from offset for length ...
*/