Wireshark 4.5.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
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_DEPRECATED_X("Use tvb_get_uint64 instead")
396static inline uint64_t tvb_get_guint64(tvbuff_t *tvb, const int offset, const unsigned encoding) {return tvb_get_uint64(tvb, offset, encoding); }
397WS_DLL_PUBLIC int64_t tvb_get_int64(tvbuff_t *tvb, const int offset, const unsigned encoding);
398WS_DEPRECATED_X("Use tvb_get_int64 instead")
399static inline int64_t tvb_get_gint64(tvbuff_t *tvb, const int offset, const unsigned encoding) { return tvb_get_int64(tvb, offset, encoding); }
400WS_DLL_PUBLIC float tvb_get_ieee_float(tvbuff_t *tvb, const int offset, const unsigned encoding);
401WS_DLL_PUBLIC double tvb_get_ieee_double(tvbuff_t *tvb, const int offset, const unsigned encoding);
402
403/*
404 * Fetch 16-bit and 32-bit values in host byte order.
405 * Used for some pseudo-headers in pcap/pcapng files, in which the
406 * headers are, when capturing, in the byte order of the host, and
407 * are converted to the byte order of the host reading the file
408 * when reading a capture file.
409 */
410#if G_BYTE_ORDER == G_LITTLE_ENDIAN
411#define tvb_get_h_uint16 tvb_get_letohs
412#define tvb_get_h_uint32 tvb_get_letohl
413#elif G_BYTE_ORDER == G_BIG_ENDIAN
414#define tvb_get_h_uint16 tvb_get_ntohs
415#define tvb_get_h_uint32 tvb_get_ntohl
416#else
417#error "Unsupported byte order"
418#endif
419
420
421/* Fetch a time value from an ASCII-style string in the tvb.
422 *
423 * @param[in] offset The beginning offset in the tvb (cannot be negative)
424 * @param[in] length The field's length in the tvb (or -1 for remaining)
425 * @param[in] encoding The ENC_* that defines the format (e.g., ENC_ISO_8601_DATE_TIME)
426 * @param[in,out] ns The pre-allocated nstime_t that will be set to the decoded value
427 * @param[out] endoff if not NULL, should point to a int that this
428 * routine will then set to be the offset to the character after
429 * the last character used in the conversion. This is useful because
430 * they may not consume the whole section.
431 *
432 * @return a pointer to the nstime_t passed-in, or NULL on failure; if no
433 * valid conversion could be performed, *endoff is set to 0, and the
434 * nstime_t* passed-in will be cleared.
435 *
436 * @note The conversion ignores leading spaces, and will succeed even if it does
437 * not consume the entire string. If you care about such things, always compare
438 * the *endoff to where you expect it to be (namely, offset+length).
439 *
440 * This routine will not throw an error unless the passed-in arguments are
441 * invalid (e.g., offset is beyond the tvb's length).
442 *
443 * @warning This only works for string encodings which encode ASCII characters in
444 * a single byte: ENC_ASCII, ENC_UTF_8, ENC_ISO_8859_*, etc. It does NOT work
445 * for purely multi-byte encodings such as ENC_UTF_16, ENC_UCS_*, etc.
446 */
447WS_DLL_PUBLIC
448nstime_t* tvb_get_string_time(tvbuff_t *tvb, const int offset, const int length,
449 const unsigned encoding, nstime_t* ns, int *endoff);
450
451/* Similar to above, but returns a GByteArray based on the case-insensitive
452 * hex-char strings with optional separators, and with optional leading spaces.
453 * The separators allowed are based on the ENC_SEP_* passed in the encoding param.
454 *
455 * The passed-in bytes is set to the values, and its pointer is also the return
456 * value or NULL on error. The GByteArray bytes must be pre-constructed with
457 * g_byte_array_new().
458 */
459WS_DLL_PUBLIC
460GByteArray* tvb_get_string_bytes(tvbuff_t *tvb, const int offset, const int length,
461 const unsigned encoding, GByteArray* bytes, int *endoff);
462
467WS_DLL_PUBLIC uint32_t tvb_get_ipv4(tvbuff_t *tvb, const int offset);
468
469/* Fetch an IPv6 address. */
470WS_DLL_PUBLIC void tvb_get_ipv6(tvbuff_t *tvb, const int offset,
471 ws_in6_addr *addr);
472
483extern int tvb_get_ipv4_addr_with_prefix_len(tvbuff_t *tvb, int offset,
484 ws_in4_addr *addr, uint32_t prefix_len);
485
496extern int tvb_get_ipv6_addr_with_prefix_len(tvbuff_t *tvb, int offset,
497 ws_in6_addr *addr, uint32_t prefix_len);
498
499/* Fetch a GUID. */
500WS_DLL_PUBLIC void tvb_get_ntohguid(tvbuff_t *tvb, const int offset,
501 e_guid_t *guid);
502
503WS_DLL_PUBLIC void tvb_get_letohguid(tvbuff_t *tvb, const int offset,
504 e_guid_t *guid);
505
506WS_DLL_PUBLIC void tvb_get_guid(tvbuff_t *tvb, const int offset,
507 e_guid_t *guid, const unsigned encoding);
508
509/* Fetches a byte array given a bit offset in a tvb */
510WS_DLL_PUBLIC uint8_t* tvb_get_bits_array(wmem_allocator_t *scope, tvbuff_t *tvb,
511 const int offset, size_t length, size_t *data_length, const unsigned encoding);
512
513/* Fetch a specified number of bits from bit offset in a tvb. All of these
514 * functions are equivalent, except for the type of the return value. Note
515 * that the parameter encoding (where supplied) indicates the *bit* ordering
516 * within each octet, but offsets 0-7 still indicate octet 0 in the buffer.
517 * Versions of Wireshark prior to 3.6 ignored the encoding parameter.
518 */
519
520/* get 1 - 8 bits returned in a uint8_t */
521WS_DLL_PUBLIC uint8_t tvb_get_bits8(tvbuff_t *tvb, unsigned bit_offset,
522 const int no_of_bits);
523
524/* get 1 - 16 bits returned in a uint16_t */
525WS_DLL_PUBLIC uint16_t tvb_get_bits16(tvbuff_t *tvb, unsigned bit_offset,
526 const int no_of_bits, const unsigned encoding);
527
528/* get 1 - 32 bits returned in a uint32_t */
529WS_DLL_PUBLIC uint32_t tvb_get_bits32(tvbuff_t *tvb, unsigned bit_offset,
530 const int no_of_bits, const unsigned encoding);
531
532/* get 1 - 64 bits returned in a uint64_t */
533WS_DLL_PUBLIC uint64_t tvb_get_bits64(tvbuff_t *tvb, unsigned bit_offset,
534 const int no_of_bits, const unsigned encoding);
535
540WS_DLL_PUBLIC uint32_t tvb_get_bits(tvbuff_t *tvb, const unsigned bit_offset,
541 const int no_of_bits, const unsigned encoding);
542
549WS_DLL_PUBLIC void *tvb_memcpy(tvbuff_t *tvb, void *target, const int offset,
550 size_t length);
551
567WS_DLL_PUBLIC void *tvb_memdup(wmem_allocator_t *scope, tvbuff_t *tvb,
568 const int offset, size_t length);
569
595WS_DLL_PUBLIC const uint8_t *tvb_get_ptr(tvbuff_t *tvb, const int offset,
596 const int length);
597
605WS_DLL_PUBLIC int tvb_find_uint8(tvbuff_t *tvb, const int offset,
606 const int maxlength, const uint8_t needle);
607
608WS_DEPRECATED_X("Use tvb_find_uint8 instead")
609static inline int tvb_find_guint8(tvbuff_t* tvb, const int offset,
610 const int maxlength, const uint8_t needle) { return tvb_find_uint8(tvb, offset, maxlength, needle); }
611
613WS_DLL_PUBLIC int tvb_find_uint16(tvbuff_t *tvb, const int offset,
614 const int maxlength, const uint16_t needle);
615
616WS_DEPRECATED_X("Use tvb_find_uint16 instead")
617static inline int tvb_find_guint16(tvbuff_t* tvb, const int offset,
618 const int maxlength, const uint16_t needle) {
619 return tvb_find_uint16(tvb, offset, maxlength, needle);
620}
629WS_DLL_PUBLIC int tvb_ws_mempbrk_pattern_uint8(tvbuff_t *tvb, const int offset,
630 const int maxlength, const ws_mempbrk_pattern* pattern, unsigned char *found_needle);
631
632WS_DEPRECATED_X("Use tvb_ws_mempbrk_pattern_uint8 instead")
633static inline int tvb_ws_mempbrk_pattern_guint8(tvbuff_t* tvb, const int offset,
634 const int maxlength, const ws_mempbrk_pattern* pattern, unsigned char* found_needle) {
635 return tvb_ws_mempbrk_pattern_uint8(tvb, offset, maxlength, pattern, found_needle);
636}
637
643WS_DLL_PUBLIC unsigned tvb_strsize(tvbuff_t *tvb, const int offset);
644
651WS_DLL_PUBLIC unsigned tvb_unicode_strsize(tvbuff_t *tvb, const int offset);
652
657WS_DLL_PUBLIC int tvb_strnlen(tvbuff_t *tvb, const int offset,
658 const unsigned maxlength);
659
663WS_DLL_PUBLIC char *tvb_format_text(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset,
664 const int size);
665
670WS_DLL_PUBLIC char *tvb_format_text_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const int offset,
671 const int size);
672
677extern char *tvb_format_stringzpad(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset,
678 const int size);
679
684extern char *tvb_format_stringzpad_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const int offset,
685 const int size);
686
707WS_DLL_PUBLIC uint8_t *tvb_get_string_enc(wmem_allocator_t *scope,
708 tvbuff_t *tvb, const int offset, const int length, const unsigned encoding);
709
732 tvbuff_t *tvb, const int bit_offset, int no_of_chars);
733
756 tvbuff_t *tvb, const int offset, int length);
757
779 tvbuff_t *tvb, const int offset, int length);
780
801WS_DLL_PUBLIC char *tvb_get_ascii_7bits_string(wmem_allocator_t *scope,
802 tvbuff_t *tvb, const int bit_offset, int no_of_chars);
803
824WS_DLL_PUBLIC uint8_t *tvb_get_stringzpad(wmem_allocator_t *scope,
825 tvbuff_t *tvb, const int offset, const int length, const unsigned encoding);
826
853WS_DLL_PUBLIC uint8_t *tvb_get_stringz_enc(wmem_allocator_t *scope,
854 tvbuff_t *tvb, const int offset, int *lengthp, const unsigned encoding);
855
880WS_DLL_PUBLIC
881WS_DEPRECATED_X("Use APIs that return a valid UTF-8 string instead")
882const uint8_t *tvb_get_const_stringz(tvbuff_t *tvb,
883 const int offset, int *lengthp);
884
894WS_DLL_PUBLIC int tvb_get_raw_bytes_as_stringz(tvbuff_t *tvb, const int offset,
895 const unsigned bufsize, uint8_t *buffer);
896
897/*
898 * Given a tvbuff, an offset into the tvbuff, a buffer, and a buffer size,
899 * extract as many raw bytes from the tvbuff, starting at the offset,
900 * as 1) are available in the tvbuff and 2) will fit in the buffer, leaving
901 * room for a terminating NUL.
902 */
903WS_DLL_PUBLIC int tvb_get_raw_bytes_as_string(tvbuff_t *tvb, const int offset, char *buffer, size_t bufsize);
904
909WS_DLL_PUBLIC bool tvb_ascii_isprint(tvbuff_t *tvb, const int offset,
910 const int length);
911
921WS_DLL_PUBLIC bool tvb_utf_8_isprint(tvbuff_t *tvb, const int offset,
922 const int length);
923
928WS_DLL_PUBLIC bool tvb_ascii_isdigit(tvbuff_t *tvb, const int offset,
929 const int length);
930
950WS_DLL_PUBLIC int tvb_find_line_end(tvbuff_t *tvb, const int offset, int len,
951 int *next_offset, const bool desegment);
952
971WS_DLL_PUBLIC int tvb_find_line_end_unquoted(tvbuff_t *tvb, const int offset,
972 int len, int *next_offset);
973
991WS_DLL_PUBLIC int tvb_skip_wsp(tvbuff_t *tvb, const int offset,
992 const int maxlength);
993
994WS_DLL_PUBLIC int tvb_skip_wsp_return(tvbuff_t *tvb, const int offset);
995
996int tvb_skip_uint8(tvbuff_t *tvb, int offset, const int maxlength, const uint8_t ch);
997WS_DEPRECATED_X("Use tvb_skip_uint8 instead")
998static inline int tvb_skip_guint8(tvbuff_t *tvb, int offset, const int maxlength, const uint8_t ch) {
999 return tvb_skip_uint8(tvb, offset, maxlength, ch);
1000}
1001
1020WS_DLL_PUBLIC int tvb_get_token_len(tvbuff_t *tvb, const int offset, int len, int *next_offset, const bool desegment);
1021
1026WS_DLL_PUBLIC int tvb_strneql(tvbuff_t *tvb, const int offset,
1027 const char *str, const size_t size);
1028
1033WS_DLL_PUBLIC int tvb_strncaseeql(tvbuff_t *tvb, const int offset,
1034 const char *str, const size_t size);
1035
1040WS_DLL_PUBLIC int tvb_memeql(tvbuff_t *tvb, const int offset,
1041 const uint8_t *str, size_t size);
1042
1048WS_DLL_PUBLIC char *tvb_bytes_to_str_punct(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset,
1049 const int len, const char punct);
1050
1055WS_DLL_PUBLIC char *tvb_bytes_to_str(wmem_allocator_t *allocator, tvbuff_t *tvb,
1056 const int offset, const int len);
1057
1068typedef struct dgt_set_t
1069{
1070 const unsigned char out[16];
1071}
1073
1074WS_DLL_PUBLIC const char *tvb_bcd_dig_to_str(wmem_allocator_t *scope,
1075 tvbuff_t *tvb, const int offset, const int len, const dgt_set_t *dgt,
1076 bool skip_first);
1077
1089WS_DLL_PUBLIC const char *tvb_bcd_dig_to_str_be(wmem_allocator_t *scope,
1090 tvbuff_t *tvb, const int offset, const int len, const dgt_set_t *dgt,
1091 bool skip_first);
1092
1108WS_DLL_PUBLIC char *tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb,
1109 const int offset, int len, const dgt_set_t *dgt,
1110 bool skip_first, bool odd, bool bigendian);
1111
1116WS_DLL_PUBLIC int tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb,
1117 const int haystack_offset);
1118
1119/* From tvbuff_zlib.c */
1120
1121WS_DEPRECATED_X("Use tvb_uncompress_zlib instead")
1122WS_DLL_PUBLIC tvbuff_t *tvb_uncompress(tvbuff_t *tvb, const int offset,
1123 int comprlen);
1124
1134WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_zlib(tvbuff_t *tvb, const int offset,
1135 int comprlen);
1136
1137WS_DEPRECATED_X("Use tvb_child_uncompress_zlib instead")
1138WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress(tvbuff_t *parent, tvbuff_t *tvb,
1139 const int offset, int comprlen);
1140
1146WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_zlib(tvbuff_t *parent, tvbuff_t *tvb,
1147 const int offset, int comprlen);
1148
1149/* From tvbuff_brotli.c */
1150
1160WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_brotli(tvbuff_t *tvb, const int offset,
1161 int comprlen);
1162
1168WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_brotli(tvbuff_t *parent, tvbuff_t *tvb,
1169 const int offset, int comprlen);
1170
1171/* From tvbuff_snappy.c */
1172
1178WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_snappy(tvbuff_t *tvb, const int offset,
1179 int comprlen);
1180
1186WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_snappy(tvbuff_t *parent, tvbuff_t *tvb,
1187 const int offset, int comprlen);
1188
1189/* From tvbuff_lz77.c */
1190
1201WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_lz77(tvbuff_t *tvb,
1202 const int offset, int comprlen);
1203
1210WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_lz77(tvbuff_t *parent,
1211 tvbuff_t *tvb, const int offset, int comprlen);
1212
1213/* From tvbuff_lz77huff.c */
1214
1225WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_lz77huff(tvbuff_t *tvb,
1226 const int offset, int comprlen);
1227
1234WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_lz77huff(tvbuff_t *parent,
1235 tvbuff_t *tvb, const int offset, int comprlen);
1236
1237/* From tvbuff_lznt1.c */
1238
1249WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_lznt1(tvbuff_t *tvb,
1250 const int offset, int comprlen);
1251
1258WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_lznt1(tvbuff_t *parent,
1259 tvbuff_t *tvb, const int offset, int comprlen);
1260
1271WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_zstd(tvbuff_t *tvb,
1272 const int offset, int comprlen);
1273
1280WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_zstd(tvbuff_t *parent,
1281 tvbuff_t *tvb, const int offset, int comprlen);
1282
1283/* From tvbuff_base64.c */
1284
1294extern tvbuff_t* base64_to_tvb(tvbuff_t *parent, const char *base64);
1295
1296
1306extern tvbuff_t* base64_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length);
1307
1308extern tvbuff_t* base64uri_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length);
1309
1310/* From tvbuff_hpackhuff.c */
1311
1312WS_DLL_PUBLIC wmem_strbuf_t* tvb_get_hpack_huffman_strbuf(wmem_allocator_t *scope,
1313 tvbuff_t *tvb, const int offset, const int len);
1314
1315WS_DLL_PUBLIC tvbuff_t* tvb_child_uncompress_hpack_huff(tvbuff_t *parent,
1316 int offset, int length);
1317
1331WS_DLL_PUBLIC unsigned tvb_get_varint(tvbuff_t *tvb, unsigned offset, unsigned maxlen, uint64_t *value, const unsigned encoding);
1332
1333/************** END OF ACCESSORS ****************/
1334
1337#ifdef __cplusplus
1338}
1339#endif /* __cplusplus */
1340
1341#endif /* __TVBUFF_H__ */
1342
1343/*
1344 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1345 *
1346 * Local variables:
1347 * c-basic-offset: 4
1348 * tab-width: 8
1349 * indent-tabs-mode: nil
1350 * End:
1351 *
1352 * vi: set shiftwidth=4 tabstop=8 expandtab:
1353 * :indentSize=4:tabSize=8:noTabs=true:
1354 */
WS_DLL_PUBLIC bool tvb_ascii_isprint(tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:4060
WS_DLL_PUBLIC bool tvb_ascii_isdigit(tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:4091
WS_DLL_PUBLIC int tvb_find_uint16(tvbuff_t *tvb, const int offset, const int maxlength, const uint16_t needle)
Definition tvbuff.c:2434
WS_DLL_PUBLIC int tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb, const int haystack_offset)
Definition tvbuff.c:4678
WS_DLL_PUBLIC int tvb_strnlen(tvbuff_t *tvb, const int offset, const unsigned maxlength)
Definition tvbuff.c:2610
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:2065
WS_DLL_PUBLIC void tvb_set_fragment(tvbuff_t *tvb)
Definition tvbuff.c:4716
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:4472
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:3027
WS_DLL_PUBLIC int tvb_strneql(tvbuff_t *tvb, const int offset, const char *str, const size_t size)
Definition tvbuff.c:2638
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:3039
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:358
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:4010
WS_DLL_PUBLIC char * tvb_format_text_wsp(wmem_allocator_t *allocator, tvbuff_t *tvb, const int offset, const int size)
Definition tvbuff.c:2734
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:3726
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:4565
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:3495
WS_DLL_PUBLIC unsigned tvb_unicode_strsize(tvbuff_t *tvb, const int offset)
Definition tvbuff.c:2589
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:3229
WS_DLL_PUBLIC const uint8_t * tvb_get_const_stringz(tvbuff_t *tvb, const int offset, int *lengthp)
Definition tvbuff.c:3594
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:4543
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:3015
WS_DLL_PUBLIC char * tvb_format_text(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int size)
Definition tvbuff.c:2719
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:206
WS_DLL_PUBLIC tvbuff_t * tvb_new_composite(void)
Definition tvbuff_composite.c:192
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:2665
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:3001
WS_DLL_PUBLIC int tvb_find_uint8(tvbuff_t *tvb, const int offset, const int maxlength, const uint8_t needle)
Definition tvbuff.c:2395
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:4657
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:326
WS_DLL_PUBLIC uint32_t tvb_get_ipv4(tvbuff_t *tvb, const int offset)
Definition tvbuff.c:2040
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:4128
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:252
WS_DLL_PUBLIC int tvb_memeql(tvbuff_t *tvb, const int offset, const uint8_t *str, size_t size)
Definition tvbuff.c:2693
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:4077
WS_DLL_PUBLIC char * tvb_bytes_to_str(wmem_allocator_t *allocator, tvbuff_t *tvb, const int offset, const int len)
Definition tvbuff.c:4669
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:2769
int tvb_get_ipv6_addr_with_prefix_len(tvbuff_t *tvb, int offset, ws_in6_addr *addr, uint32_t prefix_len)
Definition tvbuff.c:2086
WS_DLL_PUBLIC unsigned tvb_strsize(tvbuff_t *tvb, const int offset)
Definition tvbuff.c:2559
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:404
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:2515
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:4400
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:2750
WS_DLL_PUBLIC unsigned tvb_get_varint(tvbuff_t *tvb, unsigned offset, unsigned maxlen, uint64_t *value, const unsigned encoding)
Definition tvbuff.c:4728
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:229
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:2365
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:4251
Definition guid-utils.h:23
Definition wmem_allocator.h:27
Definition wmem_strbuf.h:42
Definition mcast_stream.h:30
Definition tvbuff.h:1069
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