forked from osmocom/wireshark
Introduce two new functions:
tvb_get_seasonal_string(); tvb_get_seasonal_stringz(); .. which work the same as the ephemeral versions of the functions, but use se_alloc() instead of ep_alloc(). svn path=/trunk/; revision=27868
This commit is contained in:
parent
411f9c9cf1
commit
1a71ec7c45
|
@ -1127,6 +1127,7 @@ String accessors:
|
|||
|
||||
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
|
||||
|
@ -1136,14 +1137,20 @@ as it includes a null character to terminate the string).
|
|||
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
|
||||
|
@ -1159,6 +1166,10 @@ 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_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);
|
||||
|
|
|
@ -2144,6 +2144,34 @@ tvb_get_ephemeral_string(tvbuff_t *tvb, gint offset, gint length)
|
|||
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
|
||||
|
@ -2192,6 +2220,31 @@ tvb_get_ephemeral_stringz(tvbuff_t *tvb, gint offset, gint *lengthp)
|
|||
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
|
||||
|
|
|
@ -460,9 +460,14 @@ extern gchar *tvb_format_stringzpad(tvbuff_t *tvb, gint offset, gint size);
|
|||
* 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);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -480,9 +485,14 @@ extern guint8 *tvb_get_ephemeral_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.
|
||||
|
|
Loading…
Reference in New Issue