guint8 *tvb_get_string(tvbuff_t*, gint offset, gint length);
guint8 *tvb_get_ephemeral_string(tvbuff_t*, gint offset, gint length);
+guint8 *tvb_get_seasonal_string(tvbuff_t*, gint offset, gint length);
Returns a null-terminated buffer containing data from the specified
tvbuff, starting at the specified offset, and containing the specified
tvb_get_string() returns a buffer allocated by g_malloc() so you must
g_free() it when you are finished with the string. Failure to g_free() this
buffer will lead to memory leaks.
+
tvb_get_ephemeral_string() returns a buffer allocated from a special heap
with a lifetime until the next packet is dissected. You do not need to
free() this buffer, it will happen automatically once the next packet is
dissected.
+tvb_get_seasonal_string() returns a buffer allocated from a special heap
+with a lifetime of the current capture session. You do not need to
+free() this buffer, it will happen automatically once the a new capture or
+file is opened.
guint8 *tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
guint8 *tvb_get_ephemeral_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
+guint8 *tvb_get_seasonal_stringz(tvbuff_t *tvb, gint offset, gint *lengthp);
Returns a null-terminated buffer, allocated with "g_malloc()",
containing data from the specified tvbuff, starting at the
free() this buffer, it will happen automatically once the next packet is
dissected.
+tvb_get_seasonal_stringz() returns a buffer allocated from a special heap
+with a lifetime of the current capture session. You do not need to
+free() this buffer, it will happen automatically once the a new capture or
+file is opened.
guint8 *tvb_fake_unicode(tvbuff_t*, gint offset, gint length, gboolean little_endian);
guint8 *tvb_get_ephemeral_faked_unicode(tvbuff_t*, gint offset, gint length, gboolean little_endian);
return strbuf;
}
+/*
+ * 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.
+ *
+ * Throws an exception if the tvbuff ends before the string does.
+ *
+ * This function allocates memory from a buffer with capture session lifetime.
+ * You do not have to free this buffer, it will be automatically freed
+ * when wireshark starts or opens a new capture.
+ */
+guint8 *
+tvb_get_seasonal_string(tvbuff_t *tvb, gint offset, gint length)
+{
+ const guint8 *ptr;
+ guint8 *strbuf = NULL;
+
+ tvb_ensure_bytes_exist(tvb, offset, length);
+
+ ptr = ensure_contiguous(tvb, offset, length);
+ strbuf = se_alloc(length + 1);
+ if (length != 0) {
+ memcpy(strbuf, ptr, length);
+ }
+ strbuf[length] = '\0';
+ return strbuf;
+}
/*
* Given a tvbuff and an offset, with the offset assumed to refer to
return strptr;
}
+/*
+ * Given a tvbuff and an offset, with the offset assumed to refer to
+ * a null-terminated string, find the length of that string (and throw
+ * an exception if the tvbuff ends before we find the null), allocate
+ * 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.
+ *
+ * This function allocates memory from a buffer with capture session lifetime.
+ * You do not have to free this buffer, it will be automatically freed
+ * when wireshark starts or opens a new capture.
+ */
+guint8 *
+tvb_get_seasonal_stringz(tvbuff_t *tvb, gint offset, gint *lengthp)
+{
+ guint size;
+ guint8 *strptr;
+
+ size = tvb_strsize(tvb, offset);
+ strptr = se_alloc(size);
+ tvb_memcpy(tvb, strptr, offset, size);
+ *lengthp = size;
+ return strptr;
+}
+
/* 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
* tvb_get_ephemeral_string() returns a string that does not need to be freed,
* instead it will automatically be freed once the next
* packet is dissected.
+ *
+ * tvb_get_seasonal_string() returns a string that does not need to be freed,
+ * instead it will automatically be freed when a new capture
+ * or file is opened.
*/
extern guint8 *tvb_get_string(tvbuff_t *tvb, gint offset, gint length);
extern guint8 *tvb_get_ephemeral_string(tvbuff_t *tvb, gint offset, gint length);
+extern guint8 *tvb_get_seasonal_string(tvbuff_t *tvb, gint offset, gint length);
/**
* 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.
+ *
+ * tvb_get_seasonal_stringz() returns a string that does not need to be freed,
+ * instead it will automatically be freed when a new capture
+ * or file is opened.
*/
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);
+extern guint8 *tvb_get_seasonal_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.