*
* 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
#define __TVBUFF_H__
#include <glib.h>
+#include <epan/ipv6-utils.h>
+#include <epan/guid-utils.h>
#include "exceptions.h"
/** @file
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
* 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.
*/
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);
/**
*/
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".
/**
* 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.
* 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