Don't set the focus on the display filter entry when we're passed a
[obnox/wireshark/wip.git] / epan / tvbuff.h
index 859c40365ad187659aebb68944c3fe1becc3483f..6b06c210ee19fe8e6d42d1b2d577c53109709acb 100644 (file)
@@ -13,8 +13,8 @@
  *
  * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
@@ -36,6 +36,8 @@
 #define __TVBUFF_H__
 
 #include <glib.h>
+#include <epan/ipv6-utils.h>
+#include <epan/guid-utils.h>
 #include "exceptions.h"
 
 /** @file
@@ -320,23 +322,43 @@ extern guint64 tvb_get_letoh64(tvbuff_t*, gint offset);
 extern gfloat tvb_get_letohieee_float(tvbuff_t*, gint offset);
 extern gdouble tvb_get_letohieee_double(tvbuff_t*, gint offset);
 
+/**
+ * Fetch an IPv4 address, in network byte order.
+ * We do *not* convert it to host byte order; we leave it in
+ * network byte order, as that's what its callers expect. */
+extern guint32 tvb_get_ipv4(tvbuff_t*, gint offset);
+
+/* Fetch an IPv6 address. */
+extern void tvb_get_ipv6(tvbuff_t*, gint offset, struct e_in6_addr *addr);
+
+/* Fetch a GUID. */
+extern void tvb_get_ntohguid(tvbuff_t *tvb, gint offset, e_guid_t *guid);
+extern void tvb_get_letohguid(tvbuff_t *tvb, gint offset, e_guid_t *guid);
+extern void tvb_get_guid(tvbuff_t *tvb, gint offset, e_guid_t *guid, gboolean little_endian);
+
+/* Fetch a specified number of bits from bit offset in a tvb */
+extern guint8 tvb_get_bits8(tvbuff_t *tvb, gint bit_offset, gint no_of_bits);
+extern guint16 tvb_get_bits16(tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean little_endian);
+extern guint32 tvb_get_bits32(tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean little_endian);
+extern guint64 tvb_get_bits64(tvbuff_t *tvb, gint bit_offset, gint no_of_bits, gboolean little_endian);
+
 /** Returns target for convenience. Does not suffer from possible
  * expense of tvb_get_ptr(), since this routine is smart enough
  * to copy data in chunks if the request range actually exists in
  * different TVBUFF_REAL_DATA tvbuffs. This function assumes that the
  * target memory is already allocated; it does not allocate or free the
  * target memory. */
-extern guint8* tvb_memcpy(tvbuff_t*, guint8* target, gint offset, gint length);
+extern void* tvb_memcpy(tvbuff_t*, void* target, gint offset, gint length);
 
 /** It is the user's responsibility to g_free() the memory allocated by
  * tvb_memdup(). Calls tvb_memcpy() */
-extern guint8* tvb_memdup(tvbuff_t*, gint offset, gint length);
+extern void* tvb_memdup(tvbuff_t*, gint offset, gint length);
 
 /* 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 guint8* ep_tvb_memdup(tvbuff_t *tvb, gint offset, gint length);
+extern void* ep_tvb_memdup(tvbuff_t *tvb, gint offset, gint length);
 
 /** WARNING! This function is possibly expensive, temporarily allocating
  * another copy of the packet data. Furthermore, it's dangerous because once
@@ -374,7 +396,7 @@ extern gint tvb_find_guint8(tvbuff_t*, gint offset, gint maxlength,
  * maxlength exceeds boundary of tvbuff; in that case, -1 will be returned if
  * the boundary is reached before finding needle. */
 extern gint tvb_pbrk_guint8(tvbuff_t *, gint offset, gint maxlength,
-    guint8 *needles);
+    const guint8 *needles);
 
 /** Find size of stringz (NUL-terminated string) by looking for terminating
  * NUL.  The size of the string includes the terminating NUL.
@@ -383,23 +405,26 @@ extern gint tvb_pbrk_guint8(tvbuff_t *, gint offset, gint maxlength,
  */
 extern guint tvb_strsize(tvbuff_t *tvb, gint offset);
 
-/** Find length of string by looking for end of string ('\0'), up to
+/** Find length of string by looking for end of zero terminated string, up to
  * 'maxlength' characters'; if 'maxlength' is -1, searches to end
  * of tvbuff.
  * Returns -1 if 'maxlength' reached before finding EOS. */
 extern gint tvb_strnlen(tvbuff_t*, gint offset, guint maxlength);
 
 /** 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. */
+ * assuming all characters are ASCII  )-:  The len parameter is the number 
+ * of guint16's to convert from Unicode. 
+ *
+ * tvb_fake_unicode() returns a buffer allocated by g_malloc() and must
+ *                    be g_free() by the caller.
+ * tvb_get_ephemeral_faked_unicode() returns a buffer that does not need
+ *                    to be explicitely freed. Instead this buffer is
+ *                    automatically freed when wireshark starts dissecting
+ *                    the next packet.
+ */
 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,
+extern char *tvb_get_ephemeral_faked_unicode(tvbuff_t *tvb, int offset, int len,
                               gboolean little_endian);
 
 /**
@@ -407,6 +432,12 @@ extern char *ep_tvb_fake_unicode(tvbuff_t *tvb, int offset, int len,
  */
 extern gchar * tvb_format_text(tvbuff_t *tvb, gint offset, gint size);
 
+/**
+ * Like "tvb_format_text()", but for 'wsp'; don't show
+ * the characters as C-style escapes.
+ */
+extern gchar * tvb_format_text_wsp(tvbuff_t *tvb, gint offset, gint size);
+
 /**
  * Like "tvb_format_text()", but for null-padded strings; don't show
  * the null padding characters as "\000".
@@ -417,7 +448,7 @@ extern gchar *tvb_format_stringzpad(tvbuff_t *tvb, gint offset, gint size);
 /**
  * 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
+ * plus a trailing zero, copy the string into it, and return a pointer
  * to the string.
  *
  * Throws an exception if the tvbuff ends before the string does.
@@ -441,14 +472,23 @@ extern guint8 *tvb_get_ephemeral_string(tvbuff_t *tvb, gint offset, gint length)
  * a buffer big enough to hold the string, copy the string into it,
  * and return a pointer to the string.  Also return the length of the
  * string (including the terminating null) through a pointer.
+ *
+ * tvb_get_stringz() returns a string allocated by g_malloc() and therefore
+ *                   MUST be g_free() by the caller in order not to leak
+ *                   memory.
+ *
+ * tvb_get_ephemeral_stringz() returns a string that does not need to be freed,
+ *                   instead it will automatically be freed once the next
+ *                   packet is dissected.
  */
 extern guint8 *tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
+extern guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
 
 /** Looks for a stringz (NUL-terminated string) in tvbuff and copies
  * no more than bufsize number of bytes, including terminating NUL, to buffer.
  * Returns length of string (not including terminating NUL), or -1 if the string was
  * truncated in the buffer due to not having reached the terminating NUL.
- * In this way, it acts like snprintf().
+ * In this way, it acts like g_snprintf().
  *
  * When processing a packet where the remaining number of bytes is less
  * than bufsize, an exception is not thrown if the end of the packet