Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
tvbuff.h
Go to the documentation of this file.
1
21#ifndef __TVBUFF_H__
22#define __TVBUFF_H__
23
24#include <ws_symbol_export.h>
25#include <ws_attributes.h>
26
27#include <epan/guid-utils.h>
28
29#include <wsutil/inet_addr.h>
30#include <wsutil/nstime.h>
31#include "wsutil/ws_mempbrk.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif /* __cplusplus */
36
47struct tvbuff;
48typedef struct tvbuff tvbuff_t;
49
103typedef void (*tvbuff_free_cb_t)(void*);
104
110WS_DLL_PUBLIC tvbuff_t *tvb_new_octet_aligned(tvbuff_t *tvb,
111 uint32_t bit_offset, int32_t no_of_bits);
112
117 uint32_t bit_offset, int32_t no_of_bits);
118
119WS_DLL_PUBLIC tvbuff_t *tvb_new_chain(tvbuff_t *parent, tvbuff_t *backing);
120
121WS_DLL_PUBLIC tvbuff_t *tvb_clone(tvbuff_t *tvb);
122
123WS_DLL_PUBLIC tvbuff_t *tvb_clone_offset_len(tvbuff_t *tvb, unsigned offset,
124 unsigned len);
125
131WS_DLL_PUBLIC void tvb_free(tvbuff_t *tvb);
132
138WS_DLL_PUBLIC void tvb_free_chain(tvbuff_t *tvb);
139
144WS_DLL_PUBLIC void tvb_set_free_cb(tvbuff_t *tvb, const tvbuff_free_cb_t func);
145
155WS_DLL_PUBLIC void tvb_set_child_real_data_tvbuff(tvbuff_t *parent,
156 tvbuff_t *child);
157
158WS_DLL_PUBLIC tvbuff_t *tvb_new_child_real_data(tvbuff_t *parent,
159 const uint8_t *data, const unsigned length, const int reported_length);
160
165WS_DLL_PUBLIC tvbuff_t *tvb_new_real_data(const uint8_t *data,
166 const unsigned length, const int reported_length);
167
201WS_DLL_PUBLIC tvbuff_t *tvb_new_subset_length_caplen(tvbuff_t *backing,
202 const int backing_offset, const int backing_length,
203 const int reported_length);
204
210WS_DLL_PUBLIC tvbuff_t *tvb_new_subset_length(tvbuff_t *backing,
211 const int backing_offset, const int reported_length);
212
215WS_DLL_PUBLIC tvbuff_t *tvb_new_subset_remaining(tvbuff_t *backing,
216 const int backing_offset);
217
218/*
219* Both tvb_composite_append and tvb_composite_prepend can throw
220 * BoundsError if member_offset/member_length goes beyond bounds of
221 * the 'member' tvbuff. */
222
224WS_DLL_PUBLIC void tvb_composite_append(tvbuff_t *tvb, tvbuff_t *member);
225
227extern void tvb_composite_prepend(tvbuff_t *tvb, tvbuff_t *member);
228
230WS_DLL_PUBLIC tvbuff_t *tvb_new_composite(void);
231
234WS_DLL_PUBLIC void tvb_composite_finalize(tvbuff_t *tvb);
235
236
237/* Get amount of captured data in the buffer (which is *NOT* necessarily the
238 * length of the packet). You probably want tvb_reported_length instead. */
239WS_DLL_PUBLIC unsigned tvb_captured_length(const tvbuff_t *tvb);
240
245WS_DLL_PUBLIC int tvb_captured_length_remaining(const tvbuff_t *tvb, const int offset);
246
248WS_DLL_PUBLIC unsigned tvb_ensure_captured_length_remaining(const tvbuff_t *tvb,
249 const int offset);
250
251/* Checks (w/o throwing exception) that the bytes referred to by
252 * 'offset'/'length' actually exist in the buffer */
253WS_DLL_PUBLIC bool tvb_bytes_exist(const tvbuff_t *tvb, const int offset,
254 const int length);
255
259WS_DLL_PUBLIC void tvb_ensure_bytes_exist64(const tvbuff_t *tvb,
260 const int offset, const uint64_t length);
261
264WS_DLL_PUBLIC void tvb_ensure_bytes_exist(const tvbuff_t *tvb,
265 const int offset, const int length);
266
267/* Checks (w/o throwing exception) that offset exists in buffer */
268WS_DLL_PUBLIC bool tvb_offset_exists(const tvbuff_t *tvb,
269 const int offset);
270
271/* Get reported length of buffer */
272WS_DLL_PUBLIC unsigned tvb_reported_length(const tvbuff_t *tvb);
273
278WS_DLL_PUBLIC int tvb_reported_length_remaining(const tvbuff_t *tvb,
279 const int offset);
280
282WS_DLL_PUBLIC unsigned tvb_ensure_reported_length_remaining(const tvbuff_t *tvb,
283 const int offset);
284
291WS_DLL_PUBLIC void tvb_set_reported_length(tvbuff_t *tvb, const unsigned);
292
293/* Repair a tvbuff where the captured length is greater than the
294 * reported length; such a tvbuff makes no sense, as it's impossible
295 * to capture more data than is in the packet.
296 */
297WS_DLL_PUBLIC void tvb_fix_reported_length(tvbuff_t *tvb);
298
299WS_DLL_PUBLIC unsigned tvb_offset_from_real_beginning(const tvbuff_t *tvb);
300
301/* Returns the offset from the first byte of real data. */
302WS_DLL_PUBLIC int tvb_raw_offset(tvbuff_t *tvb);
303
307WS_DLL_PUBLIC void tvb_set_fragment(tvbuff_t *tvb);
308
309WS_DLL_PUBLIC struct tvbuff *tvb_get_ds_tvb(tvbuff_t *tvb);
310
311
312/************** START OF ACCESSORS ****************/
313/* All accessors will throw an exception if appropriate */
314
315WS_DLL_PUBLIC uint8_t tvb_get_uint8(tvbuff_t *tvb, const int offset);
316WS_DEPRECATED_X("Use tvb_get_uint8 instead")
317static inline uint8_t tvb_get_guint8(tvbuff_t *tvb, const int offset) { return tvb_get_uint8(tvb, offset); }
318WS_DLL_PUBLIC int8_t tvb_get_int8(tvbuff_t *tvb, const int offset);
319WS_DEPRECATED_X("Use tvb_get_int8 instead")
320static inline int8_t tvb_get_gint8(tvbuff_t *tvb, const int offset) { return tvb_get_int8(tvb, offset); }
321
322WS_DLL_PUBLIC uint16_t tvb_get_ntohs(tvbuff_t *tvb, const int offset);
323WS_DLL_PUBLIC int16_t tvb_get_ntohis(tvbuff_t *tvb, const int offset);
324WS_DLL_PUBLIC uint32_t tvb_get_ntoh24(tvbuff_t *tvb, const int offset);
325WS_DLL_PUBLIC int32_t tvb_get_ntohi24(tvbuff_t *tvb, const int offset);
326WS_DLL_PUBLIC uint32_t tvb_get_ntohl(tvbuff_t *tvb, const int offset);
327WS_DLL_PUBLIC int32_t tvb_get_ntohil(tvbuff_t *tvb, const int offset);
328WS_DLL_PUBLIC uint64_t tvb_get_ntoh40(tvbuff_t *tvb, const int offset);
329WS_DLL_PUBLIC int64_t tvb_get_ntohi40(tvbuff_t *tvb, const int offset);
330WS_DLL_PUBLIC uint64_t tvb_get_ntoh48(tvbuff_t *tvb, const int offset);
331WS_DLL_PUBLIC int64_t tvb_get_ntohi48(tvbuff_t *tvb, const int offset);
332WS_DLL_PUBLIC uint64_t tvb_get_ntoh56(tvbuff_t *tvb, const int offset);
333WS_DLL_PUBLIC int64_t tvb_get_ntohi56(tvbuff_t *tvb, const int offset);
334WS_DLL_PUBLIC uint64_t tvb_get_ntoh64(tvbuff_t *tvb, const int offset);
335WS_DLL_PUBLIC int64_t tvb_get_ntohi64(tvbuff_t *tvb, const int offset);
336WS_DLL_PUBLIC float tvb_get_ntohieee_float(tvbuff_t *tvb, const int offset);
337WS_DLL_PUBLIC double tvb_get_ntohieee_double(tvbuff_t *tvb,
338 const int offset);
339
340WS_DLL_PUBLIC uint16_t tvb_get_letohs(tvbuff_t *tvb, const int offset);
341WS_DLL_PUBLIC int16_t tvb_get_letohis(tvbuff_t *tvb, const int offset);
342WS_DLL_PUBLIC uint32_t tvb_get_letoh24(tvbuff_t *tvb, const int offset);
343WS_DLL_PUBLIC int32_t tvb_get_letohi24(tvbuff_t *tvb, const int offset);
344WS_DLL_PUBLIC uint32_t tvb_get_letohl(tvbuff_t *tvb, const int offset);
345WS_DLL_PUBLIC int32_t tvb_get_letohil(tvbuff_t *tvb, const int offset);
346WS_DLL_PUBLIC uint64_t tvb_get_letoh40(tvbuff_t *tvb, const int offset);
347WS_DLL_PUBLIC int64_t tvb_get_letohi40(tvbuff_t *tvb, const int offset);
348WS_DLL_PUBLIC uint64_t tvb_get_letoh48(tvbuff_t *tvb, const int offset);
349WS_DLL_PUBLIC int64_t tvb_get_letohi48(tvbuff_t *tvb, const int offset);
350WS_DLL_PUBLIC uint64_t tvb_get_letoh56(tvbuff_t *tvb, const int offset);
351WS_DLL_PUBLIC int64_t tvb_get_letohi56(tvbuff_t *tvb, const int offset);
352WS_DLL_PUBLIC uint64_t tvb_get_letoh64(tvbuff_t *tvb, const int offset);
353WS_DLL_PUBLIC int64_t tvb_get_letohi64(tvbuff_t *tvb, const int offset);
354WS_DLL_PUBLIC float tvb_get_letohieee_float(tvbuff_t *tvb, const int offset);
355WS_DLL_PUBLIC double tvb_get_letohieee_double(tvbuff_t *tvb,
356 const int offset);
357
358WS_DLL_PUBLIC uint16_t tvb_get_uint16(tvbuff_t *tvb, const int offset, const unsigned encoding);
359WS_DEPRECATED_X("Use tvb_get_uint16 instead")
360static inline uint16_t tvb_get_guint16(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_uint16(tvb, offset, encoding); }
361WS_DLL_PUBLIC int16_t tvb_get_int16(tvbuff_t *tvb, const int offset, const unsigned encoding);
362WS_DEPRECATED_X("Use tvb_get_int16 instead")
363static inline int16_t tvb_get_gint16(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_int16(tvb, offset, encoding); }
364WS_DLL_PUBLIC uint32_t tvb_get_uint24(tvbuff_t *tvb, const int offset, const unsigned encoding);
365WS_DEPRECATED_X("Use tvb_get_uint24 instead")
366static inline uint32_t tvb_get_guint24(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_uint24(tvb, offset, encoding); }
367WS_DLL_PUBLIC int32_t tvb_get_int24(tvbuff_t *tvb, const int offset, const unsigned encoding);
368WS_DEPRECATED_X("Use tvb_get_int24 instead")
369static inline int32_t tvb_get_gint24(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_int24(tvb, offset, encoding); }
370WS_DLL_PUBLIC uint32_t tvb_get_uint32(tvbuff_t *tvb, const int offset, const unsigned encoding);
371WS_DEPRECATED_X("Use tvb_get_uint32 instead")
372static inline uint32_t tvb_get_guint32(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_uint32(tvb, offset, encoding); }
373WS_DLL_PUBLIC int32_t tvb_get_int32(tvbuff_t *tvb, const int offset, const unsigned encoding);
374WS_DEPRECATED_X("Use tvb_get_int32 instead")
375static inline int32_t tvb_get_gint32(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_int32(tvb, offset, encoding); }
376WS_DLL_PUBLIC uint64_t tvb_get_uint40(tvbuff_t *tvb, const int offset, const unsigned encoding);
377WS_DEPRECATED_X("Use tvb_get_uint40 instead")
378static inline uint64_t tvb_get_guint40(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_uint40(tvb, offset, encoding); }
379WS_DLL_PUBLIC int64_t tvb_get_int40(tvbuff_t *tvb, const int offset, const unsigned encoding);
380WS_DEPRECATED_X("Use tvb_get_int40 instead")
381static inline int64_t tvb_get_gint40(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_int40(tvb, offset, encoding); }
382WS_DLL_PUBLIC uint64_t tvb_get_uint48(tvbuff_t *tvb, const int offset, const unsigned encoding);
383WS_DEPRECATED_X("Use tvb_get_uint48 instead")
384static inline uint64_t tvb_get_guint48(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_uint48(tvb, offset, encoding); }
385WS_DLL_PUBLIC int64_t tvb_get_int48(tvbuff_t *tvb, const int offset, const unsigned encoding);
386WS_DEPRECATED_X("Use tvb_get_int48 instead")
387static inline int64_t tvb_get_gint48(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_int48(tvb, offset, encoding); }
388WS_DLL_PUBLIC uint64_t tvb_get_uint56(tvbuff_t *tvb, const int offset, const unsigned encoding);
389WS_DEPRECATED_X("Use tvb_get_uint56 instead")
390static inline uint64_t tvb_get_guint56(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_uint56(tvb, offset, encoding); }
391WS_DLL_PUBLIC int64_t tvb_get_int56(tvbuff_t *tvb, const int offset, const unsigned encoding);
392WS_DEPRECATED_X("Use tvb_get_int56 instead")
393static inline int64_t tvb_get_gint56(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_int56(tvb, offset, encoding); }
394WS_DLL_PUBLIC uint64_t tvb_get_uint64(tvbuff_t *tvb, const int offset, const unsigned encoding);
395WS_DLL_PUBLIC uint64_t tvb_get_uint64_with_length(tvbuff_t *tvb, const int offset, unsigned length, const unsigned encoding);
396WS_DEPRECATED_X("Use tvb_get_uint64 instead")
397static inline uint64_t tvb_get_guint64(tvbuff_t *tvb, const int offset, const unsigned encoding) {return tvb_get_uint64(tvb, offset, encoding); }
398WS_DLL_PUBLIC int64_t tvb_get_int64(tvbuff_t *tvb, const int offset, const unsigned encoding);
399WS_DEPRECATED_X("Use tvb_get_int64 instead")
400static inline int64_t tvb_get_gint64(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_int64(tvb, offset, encoding); }
401WS_DLL_PUBLIC float tvb_get_ieee_float(tvbuff_t *tvb, const int offset, const unsigned encoding);
402WS_DLL_PUBLIC double tvb_get_ieee_double(tvbuff_t *tvb, const int offset, const unsigned encoding);
403
404/*
405 * Fetch 16-bit and 32-bit values in host byte order.
406 * Used for some pseudo-headers in pcap/pcapng files, in which the
407 * headers are, when capturing, in the byte order of the host, and
408 * are converted to the byte order of the host reading the file
409 * when reading a capture file.
410 */
411#if G_BYTE_ORDER == G_LITTLE_ENDIAN
412#define tvb_get_h_uint16 tvb_get_letohs
413#define tvb_get_h_uint32 tvb_get_letohl
414#elif G_BYTE_ORDER == G_BIG_ENDIAN
415#define tvb_get_h_uint16 tvb_get_ntohs
416#define tvb_get_h_uint32 tvb_get_ntohl
417#else
418#error "Unsupported byte order"
419#endif
420
421
422/* Fetch a time value from an ASCII-style string in the tvb.
423 *
424 * @param[in] offset The beginning offset in the tvb (cannot be negative)
425 * @param[in] length The field's length in the tvb (or -1 for remaining)
426 * @param[in] encoding The ENC_* that defines the format (e.g., ENC_ISO_8601_DATE_TIME)
427 * @param[in,out] ns The pre-allocated nstime_t that will be set to the decoded value
428 * @param[out] endoff if not NULL, should point to a int that this
429 * routine will then set to be the offset to the character after
430 * the last character used in the conversion. This is useful because
431 * they may not consume the whole section.
432 *
433 * @return a pointer to the nstime_t passed-in, or NULL on failure; if no
434 * valid conversion could be performed, *endoff is set to 0, and the
435 * nstime_t* passed-in will be cleared.
436 *
437 * @note The conversion ignores leading spaces, and will succeed even if it does
438 * not consume the entire string. If you care about such things, always compare
439 * the *endoff to where you expect it to be (namely, offset+length).
440 *
441 * This routine will not throw an error unless the passed-in arguments are
442 * invalid (e.g., offset is beyond the tvb's length).
443 *
444 * @warning This only works for string encodings which encode ASCII characters in
445 * a single byte: ENC_ASCII, ENC_UTF_8, ENC_ISO_8859_*, etc. It does NOT work
446 * for purely multi-byte encodings such as ENC_UTF_16, ENC_UCS_*, etc.
447 */
448WS_DLL_PUBLIC
449nstime_t* tvb_get_string_time(tvbuff_t *tvb, const int offset, const int length,
450 const unsigned encoding, nstime_t* ns, int *endoff);
451
452/* Similar to above, but returns a GByteArray based on the case-insensitive
453 * hex-char strings with optional separators, and with optional leading spaces.
454 * The separators allowed are based on the ENC_SEP_* passed in the encoding param.
455 *
456 * The passed-in bytes is set to the values, and its pointer is also the return
457 * value or NULL on error. The GByteArray bytes must be pre-constructed with
458 * g_byte_array_new().
459 */
460WS_DLL_PUBLIC
461GByteArray* tvb_get_string_bytes(tvbuff_t *tvb, const int offset, const int length,
462 const unsigned encoding, GByteArray* bytes, int *endoff);
463
468WS_DLL_PUBLIC uint32_t tvb_get_ipv4(tvbuff_t *tvb, const int offset);
469
470/* Fetch an IPv6 address. */
471WS_DLL_PUBLIC void tvb_get_ipv6(tvbuff_t *tvb, const int offset,
472 ws_in6_addr *addr);
473
484extern int tvb_get_ipv4_addr_with_prefix_len(tvbuff_t *tvb, int offset,
485 ws_in4_addr *addr, uint32_t prefix_len);
486
497extern int tvb_get_ipv6_addr_with_prefix_len(tvbuff_t *tvb, int offset,
498 ws_in6_addr *addr, uint32_t prefix_len);
499
500/* Fetch a GUID. */
501WS_DLL_PUBLIC void tvb_get_ntohguid(tvbuff_t *tvb, const int offset,
502 e_guid_t *guid);
503
504WS_DLL_PUBLIC void tvb_get_letohguid(tvbuff_t *tvb, const int offset,
505 e_guid_t *guid);
506
507WS_DLL_PUBLIC void tvb_get_guid(tvbuff_t *tvb, const int offset,
508 e_guid_t *guid, const unsigned encoding);
509
510/* Fetches a byte array given a bit offset in a tvb */
511WS_DLL_PUBLIC uint8_t* tvb_get_bits_array(wmem_allocator_t *scope, tvbuff_t *tvb,
512 const int offset, size_t length, size_t *data_length, const unsigned encoding);
513
514/* Fetch a specified number of bits from bit offset in a tvb. All of these
515 * functions are equivalent, except for the type of the return value. Note
516 * that the parameter encoding (where supplied) indicates the *bit* ordering
517 * within each octet, but offsets 0-7 still indicate octet 0 in the buffer.
518 * Versions of Wireshark prior to 3.6 ignored the encoding parameter.
519 */
520
521/* get 1 - 8 bits returned in a uint8_t */
522WS_DLL_PUBLIC uint8_t tvb_get_bits8(tvbuff_t *tvb, unsigned bit_offset,
523 const int no_of_bits);
524
525/* get 1 - 16 bits returned in a uint16_t */
526WS_DLL_PUBLIC uint16_t tvb_get_bits16(tvbuff_t *tvb, unsigned bit_offset,
527 const int no_of_bits, const unsigned encoding);
528
529/* get 1 - 32 bits returned in a uint32_t */
530WS_DLL_PUBLIC uint32_t tvb_get_bits32(tvbuff_t *tvb, unsigned bit_offset,
531 const int no_of_bits, const unsigned encoding);
532
533/* get 1 - 64 bits returned in a uint64_t */
534WS_DLL_PUBLIC uint64_t tvb_get_bits64(tvbuff_t *tvb, unsigned bit_offset,
535 const int no_of_bits, const unsigned encoding);
536
540WS_DLL_PUBLIC
541WS_DEPRECATED_X("Use tvb_get_bits32() instead")
542uint32_t tvb_get_bits(tvbuff_t *tvb, const unsigned bit_offset,
543 const int no_of_bits, const unsigned encoding);
544
551WS_DLL_PUBLIC void *tvb_memcpy(tvbuff_t *tvb, void *target, const int offset,
552 size_t length);
553
569WS_DLL_PUBLIC void *tvb_memdup(wmem_allocator_t *scope, tvbuff_t *tvb,
570 const int offset, size_t length);
571
597WS_DLL_PUBLIC const uint8_t *tvb_get_ptr(tvbuff_t *tvb, const int offset,
598 const int length);
599
607WS_DLL_PUBLIC int tvb_find_uint8(tvbuff_t *tvb, const int offset,
608 const int maxlength, const uint8_t needle);
609
610WS_DEPRECATED_X("Use tvb_find_uint8 instead")
611static inline int tvb_find_guint8(tvbuff_t* tvb, const int offset,
612 const int maxlength, const uint8_t needle) { return tvb_find_uint8(tvb, offset, maxlength, needle); }
613
615WS_DLL_PUBLIC int tvb_find_uint16(tvbuff_t *tvb, const int offset,
616 const int maxlength, const uint16_t needle);
617
618WS_DEPRECATED_X("Use tvb_find_uint16 instead")
619static inline int tvb_find_guint16(tvbuff_t* tvb, const int offset,
620 const int maxlength, const uint16_t needle) {
621 return tvb_find_uint16(tvb, offset, maxlength, needle);
622}
631WS_DLL_PUBLIC int tvb_ws_mempbrk_pattern_uint8(tvbuff_t *tvb, const int offset,
632 const int maxlength, const ws_mempbrk_pattern* pattern, unsigned char *found_needle);
633
634WS_DEPRECATED_X("Use tvb_ws_mempbrk_pattern_uint8 instead")
635static inline int tvb_ws_mempbrk_pattern_guint8(tvbuff_t* tvb, const int offset,
636 const int maxlength, const ws_mempbrk_pattern* pattern, unsigned char* found_needle) {
637 return tvb_ws_mempbrk_pattern_uint8(tvb, offset, maxlength, pattern, found_needle);
638}
639
645WS_DLL_PUBLIC unsigned tvb_strsize(tvbuff_t *tvb, const int offset);
646
653WS_DLL_PUBLIC unsigned tvb_unicode_strsize(tvbuff_t *tvb, const int offset);
654
659WS_DLL_PUBLIC int tvb_strnlen(tvbuff_t *tvb, const int offset,
660 const unsigned maxlength);
661
665WS_DLL_PUBLIC char *tvb_format_text(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset,
666 const int size);
667
672WS_DLL_PUBLIC char *tvb_format_text_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const int offset,
673 const int size);
674
679extern char *tvb_format_stringzpad(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset,
680 const int size);
681
686extern char *tvb_format_stringzpad_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const int offset,
687 const int size);
688
709WS_DLL_PUBLIC uint8_t *tvb_get_string_enc(wmem_allocator_t *scope,
710 tvbuff_t *tvb, const int offset, const int length, const unsigned encoding);
711
734 tvbuff_t *tvb, const int bit_offset, int no_of_chars);
735
758 tvbuff_t *tvb, const int offset, int length);
759
781 tvbuff_t *tvb, const int offset, int length);
782
803WS_DLL_PUBLIC char *tvb_get_ascii_7bits_string(wmem_allocator_t *scope,
804 tvbuff_t *tvb, const int bit_offset, int no_of_chars);
805
826WS_DLL_PUBLIC uint8_t *tvb_get_stringzpad(wmem_allocator_t *scope,
827 tvbuff_t *tvb, const int offset, const int length, const unsigned encoding);
828
855WS_DLL_PUBLIC uint8_t *tvb_get_stringz_enc(wmem_allocator_t *scope,
856 tvbuff_t *tvb, const int offset, int *lengthp, const unsigned encoding);
857
882WS_DLL_PUBLIC
883WS_DEPRECATED_X("Use APIs that return a valid UTF-8 string instead")
884const uint8_t *tvb_get_const_stringz(tvbuff_t *tvb,
885 const int offset, int *lengthp);
886
896WS_DLL_PUBLIC int tvb_get_raw_bytes_as_stringz(tvbuff_t *tvb, const int offset,
897 const unsigned bufsize, uint8_t *buffer);
898
899/*
900 * Given a tvbuff, an offset into the tvbuff, a buffer, and a buffer size,
901 * extract as many raw bytes from the tvbuff, starting at the offset,
902 * as 1) are available in the tvbuff and 2) will fit in the buffer, leaving
903 * room for a terminating NUL.
904 */
905WS_DLL_PUBLIC int tvb_get_raw_bytes_as_string(tvbuff_t *tvb, const int offset, char *buffer, size_t bufsize);
906
911WS_DLL_PUBLIC bool tvb_ascii_isprint(tvbuff_t *tvb, const int offset,
912 const int length);
913
923WS_DLL_PUBLIC bool tvb_utf_8_isprint(tvbuff_t *tvb, const int offset,
924 const int length);
925
930WS_DLL_PUBLIC bool tvb_ascii_isdigit(tvbuff_t *tvb, const int offset,
931 const int length);
932
952WS_DLL_PUBLIC int tvb_find_line_end(tvbuff_t *tvb, const int offset, int len,
953 int *next_offset, const bool desegment);
954
973WS_DLL_PUBLIC int tvb_find_line_end_unquoted(tvbuff_t *tvb, const int offset,
974 int len, int *next_offset);
975
993WS_DLL_PUBLIC int tvb_skip_wsp(tvbuff_t *tvb, const int offset,
994 const int maxlength);
995
996WS_DLL_PUBLIC int tvb_skip_wsp_return(tvbuff_t *tvb, const int offset);
997
998int tvb_skip_uint8(tvbuff_t *tvb, int offset, const int maxlength, const uint8_t ch);
999WS_DEPRECATED_X("Use tvb_skip_uint8 instead")
1000static inline int tvb_skip_guint8(tvbuff_t *tvb, int offset, const int maxlength, const uint8_t ch) {
1001 return tvb_skip_uint8(tvb, offset, maxlength, ch);
1002}
1003
1022WS_DLL_PUBLIC int tvb_get_token_len(tvbuff_t *tvb, const int offset, int len, int *next_offset, const bool desegment);
1023
1028WS_DLL_PUBLIC int tvb_strneql(tvbuff_t *tvb, const int offset,
1029 const char *str, const size_t size);
1030
1035WS_DLL_PUBLIC int tvb_strncaseeql(tvbuff_t *tvb, const int offset,
1036 const char *str, const size_t size);
1037
1042WS_DLL_PUBLIC int tvb_memeql(tvbuff_t *tvb, const int offset,
1043 const uint8_t *str, size_t size);
1044
1050WS_DLL_PUBLIC char *tvb_bytes_to_str_punct(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset,
1051 const int len, const char punct);
1052
1057WS_DLL_PUBLIC char *tvb_bytes_to_str(wmem_allocator_t *allocator, tvbuff_t *tvb,
1058 const int offset, const int len);
1059
1070typedef struct dgt_set_t
1071{
1072 const unsigned char out[16];
1073}
1075
1076WS_DLL_PUBLIC const char *tvb_bcd_dig_to_str(wmem_allocator_t *scope,
1077 tvbuff_t *tvb, const int offset, const int len, const dgt_set_t *dgt,
1078 bool skip_first);
1079
1091WS_DLL_PUBLIC const char *tvb_bcd_dig_to_str_be(wmem_allocator_t *scope,
1092 tvbuff_t *tvb, const int offset, const int len, const dgt_set_t *dgt,
1093 bool skip_first);
1094
1110WS_DLL_PUBLIC char *tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb,
1111 const int offset, int len, const dgt_set_t *dgt,
1112 bool skip_first, bool odd, bool bigendian);
1113
1118WS_DLL_PUBLIC int tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb,
1119 const int haystack_offset);
1120
1121/* From tvbuff_zlib.c */
1122
1123WS_DEPRECATED_X("Use tvb_uncompress_zlib instead")
1124WS_DLL_PUBLIC tvbuff_t *tvb_uncompress(tvbuff_t *tvb, const int offset,
1125 int comprlen);
1126
1136WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_zlib(tvbuff_t *tvb, const int offset,
1137 int comprlen);
1138
1139WS_DEPRECATED_X("Use tvb_child_uncompress_zlib instead")
1140WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress(tvbuff_t *parent, tvbuff_t *tvb,
1141 const int offset, int comprlen);
1142
1148WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_zlib(tvbuff_t *parent, tvbuff_t *tvb,
1149 const int offset, int comprlen);
1150
1151/* From tvbuff_brotli.c */
1152
1162WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_brotli(tvbuff_t *tvb, const int offset,
1163 int comprlen);
1164
1170WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_brotli(tvbuff_t *parent, tvbuff_t *tvb,
1171 const int offset, int comprlen);
1172
1173/* From tvbuff_snappy.c */
1174
1180WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_snappy(tvbuff_t *tvb, const int offset,
1181 int comprlen);
1182
1188WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_snappy(tvbuff_t *parent, tvbuff_t *tvb,
1189 const int offset, int comprlen);
1190
1191/* From tvbuff_lz77.c */
1192
1203WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_lz77(tvbuff_t *tvb,
1204 const int offset, int comprlen);
1205
1212WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_lz77(tvbuff_t *parent,
1213 tvbuff_t *tvb, const int offset, int comprlen);
1214
1215/* From tvbuff_lz77huff.c */
1216
1227WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_lz77huff(tvbuff_t *tvb,
1228 const int offset, int comprlen);
1229
1236WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_lz77huff(tvbuff_t *parent,
1237 tvbuff_t *tvb, const int offset, int comprlen);
1238
1239/* From tvbuff_lznt1.c */
1240
1251WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_lznt1(tvbuff_t *tvb,
1252 const int offset, int comprlen);
1253
1260WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_lznt1(tvbuff_t *parent,
1261 tvbuff_t *tvb, const int offset, int comprlen);
1262
1273WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_zstd(tvbuff_t *tvb,
1274 const int offset, int comprlen);
1275
1282WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_zstd(tvbuff_t *parent,
1283 tvbuff_t *tvb, const int offset, int comprlen);
1284
1285/* From tvbuff_base64.c */
1286
1296extern tvbuff_t* base64_to_tvb(tvbuff_t *parent, const char *base64);
1297
1298
1308extern tvbuff_t* base64_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length);
1309
1310extern tvbuff_t* base64uri_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length);
1311
1312/* From tvbuff_hpackhuff.c */
1313
1314WS_DLL_PUBLIC wmem_strbuf_t* tvb_get_hpack_huffman_strbuf(wmem_allocator_t *scope,
1315 tvbuff_t *tvb, const int offset, const int len);
1316
1317WS_DLL_PUBLIC tvbuff_t* tvb_child_uncompress_hpack_huff(tvbuff_t *parent,
1318 int offset, int length);
1319
1333WS_DLL_PUBLIC unsigned tvb_get_varint(tvbuff_t *tvb, unsigned offset, unsigned maxlen, uint64_t *value, const unsigned encoding);
1334
1335/************** END OF ACCESSORS ****************/
1336
1339#ifdef __cplusplus
1340}
1341#endif /* __cplusplus */
1342
1343#endif /* __TVBUFF_H__ */
1344
1345/*
1346 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1347 *
1348 * Local variables:
1349 * c-basic-offset: 4
1350 * tab-width: 8
1351 * indent-tabs-mode: nil
1352 * End:
1353 *
1354 * vi: set shiftwidth=4 tabstop=8 expandtab:
1355 * :indentSize=4:tabSize=8:noTabs=true:
1356 */
WS_DLL_PUBLIC bool tvb_ascii_isprint(tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:4117
WS_DLL_PUBLIC bool tvb_ascii_isdigit(tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:4148
WS_DLL_PUBLIC int tvb_find_uint16(tvbuff_t *tvb, const int offset, const int maxlength, const uint16_t needle)
Definition tvbuff.c:2491
WS_DLL_PUBLIC int tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb, const int haystack_offset)
Definition tvbuff.c:4735
WS_DLL_PUBLIC int tvb_strnlen(tvbuff_t *tvb, const int offset, const unsigned maxlength)
Definition tvbuff.c:2667
WS_DLL_PUBLIC tvbuff_t * tvb_child_uncompress_brotli(tvbuff_t *parent, tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_brotli.c:173
int tvb_get_ipv4_addr_with_prefix_len(tvbuff_t *tvb, int offset, ws_in4_addr *addr, uint32_t prefix_len)
Definition tvbuff.c:2123
WS_DLL_PUBLIC void tvb_set_fragment(tvbuff_t *tvb)
Definition tvbuff.c:4773
WS_DLL_PUBLIC int tvb_get_token_len(tvbuff_t *tvb, const int offset, int len, int *next_offset, const bool desegment)
Definition tvbuff.c:4529
WS_DLL_PUBLIC char * tvb_get_etsi_ts_102_221_annex_a_string(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, int length)
Definition tvbuff.c:3084
WS_DLL_PUBLIC int tvb_strneql(tvbuff_t *tvb, const int offset, const char *str, const size_t size)
Definition tvbuff.c:2695
WS_DLL_PUBLIC tvbuff_t * tvb_new_octet_aligned(tvbuff_t *tvb, uint32_t bit_offset, int32_t no_of_bits)
Definition tvbuff.c:366
WS_DLL_PUBLIC void tvb_free(tvbuff_t *tvb)
Definition tvbuff.c:109
WS_DLL_PUBLIC char * tvb_get_ascii_7bits_string(wmem_allocator_t *scope, tvbuff_t *tvb, const int bit_offset, int no_of_chars)
Definition tvbuff.c:3096
WS_DLL_PUBLIC tvbuff_t * tvb_new_subset_length(tvbuff_t *backing, const int backing_offset, const int reported_length)
Definition tvbuff_subset.c:191
WS_DLL_PUBLIC tvbuff_t * tvb_uncompress_lz77huff(tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_lz77huff.c:360
WS_DLL_PUBLIC unsigned tvb_ensure_captured_length_remaining(const tvbuff_t *tvb, const int offset)
Definition tvbuff.c:573
WS_DLL_PUBLIC int tvb_get_raw_bytes_as_stringz(tvbuff_t *tvb, const int offset, const unsigned bufsize, uint8_t *buffer)
Definition tvbuff.c:4067
WS_DLL_PUBLIC char * tvb_format_text_wsp(wmem_allocator_t *allocator, tvbuff_t *tvb, const int offset, const int size)
Definition tvbuff.c:2791
WS_DLL_PUBLIC uint8_t * tvb_get_stringz_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, int *lengthp, const unsigned encoding)
Definition tvbuff.c:3783
WS_DLL_PUBLIC char * tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, int len, const dgt_set_t *dgt, bool skip_first, bool odd, bool bigendian)
Definition tvbuff.c:4622
WS_DLL_PUBLIC tvbuff_t * tvb_child_uncompress_lznt1(tvbuff_t *parent, tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_lznt1.c:148
WS_DLL_PUBLIC uint8_t * tvb_get_stringzpad(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int length, const unsigned encoding)
Definition tvbuff.c:3552
WS_DLL_PUBLIC unsigned tvb_unicode_strsize(tvbuff_t *tvb, const int offset)
Definition tvbuff.c:2646
WS_DLL_PUBLIC void tvb_free_chain(tvbuff_t *tvb)
Definition tvbuff.c:115
WS_DLL_PUBLIC uint8_t * tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int length, const unsigned encoding)
Definition tvbuff.c:3286
WS_DLL_PUBLIC const uint8_t * tvb_get_const_stringz(tvbuff_t *tvb, const int offset, int *lengthp)
Definition tvbuff.c:3651
WS_DLL_PUBLIC char * tvb_bytes_to_str_punct(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int len, const char punct)
Definition tvbuff.c:4600
WS_DLL_PUBLIC tvbuff_t * tvb_child_uncompress_zstd(tvbuff_t *parent, tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_zstd.c:101
WS_DLL_PUBLIC void tvb_set_child_real_data_tvbuff(tvbuff_t *parent, tvbuff_t *child)
Definition tvbuff_real.c:96
void(* tvbuff_free_cb_t)(void *)
Definition tvbuff.h:103
WS_DLL_PUBLIC char * tvb_get_ts_23_038_7bits_string_unpacked(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, int length)
Definition tvbuff.c:3072
WS_DLL_PUBLIC char * tvb_format_text(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int size)
Definition tvbuff.c:2776
WS_DLL_PUBLIC unsigned tvb_ensure_reported_length_remaining(const tvbuff_t *tvb, const int offset)
Definition tvbuff.c:770
WS_DLL_PUBLIC void tvb_composite_append(tvbuff_t *tvb, tvbuff_t *member)
Definition tvbuff_composite.c:216
WS_DLL_PUBLIC tvbuff_t * tvb_new_composite(void)
Definition tvbuff_composite.c:201
WS_DLL_PUBLIC void tvb_ensure_bytes_exist(const tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:648
WS_DLL_PUBLIC int tvb_strncaseeql(tvbuff_t *tvb, const int offset, const char *str, const size_t size)
Definition tvbuff.c:2722
WS_DLL_PUBLIC char * tvb_get_ts_23_038_7bits_string_packed(wmem_allocator_t *scope, tvbuff_t *tvb, const int bit_offset, int no_of_chars)
Definition tvbuff.c:3058
WS_DLL_PUBLIC int tvb_find_uint8(tvbuff_t *tvb, const int offset, const int maxlength, const uint8_t needle)
Definition tvbuff.c:2452
WS_DLL_PUBLIC tvbuff_t * tvb_child_uncompress_snappy(tvbuff_t *parent, tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_snappy.c:66
tvbuff_t * base64_to_tvb(tvbuff_t *parent, const char *base64)
Definition tvbuff_base64.c:169
WS_DLL_PUBLIC int tvb_reported_length_remaining(const tvbuff_t *tvb, const int offset)
Definition tvbuff.c:752
WS_DLL_PUBLIC const uint8_t * tvb_get_ptr(tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:1001
WS_DLL_PUBLIC void tvb_set_reported_length(tvbuff_t *tvb, const unsigned)
Definition tvbuff.c:793
WS_DLL_PUBLIC void tvb_ensure_bytes_exist64(const tvbuff_t *tvb, const int offset, const uint64_t length)
Definition tvbuff.c:631
WS_DLL_PUBLIC const char * tvb_bcd_dig_to_str_be(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int len, const dgt_set_t *dgt, bool skip_first)
Definition tvbuff.c:4714
WS_DLL_PUBLIC int tvb_captured_length_remaining(const tvbuff_t *tvb, const int offset)
Definition tvbuff.c:558
WS_DLL_PUBLIC tvbuff_t * tvb_child_uncompress_zlib(tvbuff_t *parent, tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_zlib.c:309
WS_DLL_PUBLIC uint32_t tvb_get_ipv4(tvbuff_t *tvb, const int offset)
Definition tvbuff.c:2098
WS_DLL_PUBLIC tvbuff_t * tvb_uncompress_lznt1(tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_lznt1.c:109
WS_DLL_PUBLIC int tvb_find_line_end(tvbuff_t *tvb, const int offset, int len, int *next_offset, const bool desegment)
Definition tvbuff.c:4185
WS_DLL_PUBLIC tvbuff_t * tvb_new_subset_remaining(tvbuff_t *backing, const int backing_offset)
Definition tvbuff_subset.c:240
WS_DLL_PUBLIC void * tvb_memcpy(tvbuff_t *tvb, void *target, const int offset, size_t length)
Definition tvbuff.c:924
WS_DLL_PUBLIC void tvb_composite_finalize(tvbuff_t *tvb)
Definition tvbuff_composite.c:262
WS_DLL_PUBLIC int tvb_memeql(tvbuff_t *tvb, const int offset, const uint8_t *str, size_t size)
Definition tvbuff.c:2750
tvbuff_t * base64_tvb_to_new_tvb(tvbuff_t *parent, int offset, int length)
Definition tvbuff_base64.c:184
WS_DLL_PUBLIC tvbuff_t * tvb_child_uncompress_lz77(tvbuff_t *parent, tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_lz77.c:137
WS_DLL_PUBLIC tvbuff_t * tvb_new_subset_length_caplen(tvbuff_t *backing, const int backing_offset, const int backing_length, const int reported_length)
Definition tvbuff_subset.c:155
WS_DLL_PUBLIC bool tvb_utf_8_isprint(tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:4134
WS_DLL_PUBLIC char * tvb_bytes_to_str(wmem_allocator_t *allocator, tvbuff_t *tvb, const int offset, const int len)
Definition tvbuff.c:4726
WS_DLL_PUBLIC tvbuff_t * tvb_new_octet_right_aligned(tvbuff_t *tvb, uint32_t bit_offset, int32_t no_of_bits)
Definition tvbuff.c:432
WS_DLL_PUBLIC void tvb_set_free_cb(tvbuff_t *tvb, const tvbuff_free_cb_t func)
Definition tvbuff_real.c:86
char * tvb_format_stringzpad_wsp(wmem_allocator_t *allocator, tvbuff_t *tvb, const int offset, const int size)
Definition tvbuff.c:2826
int tvb_get_ipv6_addr_with_prefix_len(tvbuff_t *tvb, int offset, ws_in6_addr *addr, uint32_t prefix_len)
Definition tvbuff.c:2144
WS_DLL_PUBLIC unsigned tvb_strsize(tvbuff_t *tvb, const int offset)
Definition tvbuff.c:2616
WS_DLL_PUBLIC tvbuff_t * tvb_uncompress_brotli(tvbuff_t *tvb, const int offset, int comprlen)
WS_DLL_PUBLIC tvbuff_t * tvb_child_uncompress_lz77huff(tvbuff_t *parent, tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_lz77huff.c:406
WS_DLL_PUBLIC int tvb_ws_mempbrk_pattern_uint8(tvbuff_t *tvb, const int offset, const int maxlength, const ws_mempbrk_pattern *pattern, unsigned char *found_needle)
Definition tvbuff.c:2572
WS_DLL_PUBLIC void * tvb_memdup(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, size_t length)
Definition tvbuff.c:982
WS_DLL_PUBLIC int tvb_skip_wsp(tvbuff_t *tvb, const int offset, const int maxlength)
Definition tvbuff.c:4457
WS_DLL_PUBLIC tvbuff_t * tvb_new_real_data(const uint8_t *data, const unsigned length, const int reported_length)
Definition tvbuff_real.c:58
char * tvb_format_stringzpad(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int size)
Definition tvbuff.c:2807
WS_DLL_PUBLIC unsigned tvb_get_varint(tvbuff_t *tvb, unsigned offset, unsigned maxlen, uint64_t *value, const unsigned encoding)
Definition tvbuff.c:4785
WS_DLL_PUBLIC tvbuff_t * tvb_uncompress_snappy(tvbuff_t *tvb, const int offset, int comprlen)
void tvb_composite_prepend(tvbuff_t *tvb, tvbuff_t *member)
Definition tvbuff_composite.c:239
WS_DLL_PUBLIC uint32_t tvb_get_bits(tvbuff_t *tvb, const unsigned bit_offset, const int no_of_bits, const unsigned encoding)
Definition tvbuff.c:2422
WS_DLL_PUBLIC tvbuff_t * tvb_uncompress_zstd(tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_zstd.c:28
WS_DLL_PUBLIC tvbuff_t * tvb_uncompress_lz77(tvbuff_t *tvb, const int offset, int comprlen)
Definition tvbuff_lz77.c:98
WS_DLL_PUBLIC tvbuff_t * tvb_uncompress_zlib(tvbuff_t *tvb, const int offset, int comprlen)
WS_DLL_PUBLIC int tvb_find_line_end_unquoted(tvbuff_t *tvb, const int offset, int len, int *next_offset)
Definition tvbuff.c:4308
Definition guid-utils.h:23
Definition wmem_allocator.h:27
Definition wmem_strbuf.h:42
Definition mcast_stream.h:30
Definition tvbuff.h:1071
Definition inet_addr.h:21
Definition nstime.h:26
Definition tvbuff-int.h:35
unsigned length
Definition tvbuff-int.h:61
unsigned reported_length
Definition tvbuff-int.h:67
Definition ws_mempbrk.h:21