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_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
541WS_DLL_PUBLIC uint32_t tvb_get_bits(tvbuff_t *tvb, const unsigned bit_offset,
542 const int no_of_bits, const unsigned encoding);
543
550WS_DLL_PUBLIC void *tvb_memcpy(tvbuff_t *tvb, void *target, const int offset,
551 size_t length);
552
568WS_DLL_PUBLIC void *tvb_memdup(wmem_allocator_t *scope, tvbuff_t *tvb,
569 const int offset, size_t length);
570
596WS_DLL_PUBLIC const uint8_t *tvb_get_ptr(tvbuff_t *tvb, const int offset,
597 const int length);
598
606WS_DLL_PUBLIC int tvb_find_uint8(tvbuff_t *tvb, const int offset,
607 const int maxlength, const uint8_t needle);
608
609WS_DEPRECATED_X("Use tvb_find_uint8 instead")
610static inline int tvb_find_guint8(tvbuff_t* tvb, const int offset,
611 const int maxlength, const uint8_t needle) { return tvb_find_uint8(tvb, offset, maxlength, needle); }
612
614WS_DLL_PUBLIC int tvb_find_uint16(tvbuff_t *tvb, const int offset,
615 const int maxlength, const uint16_t needle);
616
617WS_DEPRECATED_X("Use tvb_find_uint16 instead")
618static inline int tvb_find_guint16(tvbuff_t* tvb, const int offset,
619 const int maxlength, const uint16_t needle) {
620 return tvb_find_uint16(tvb, offset, maxlength, needle);
621}
630WS_DLL_PUBLIC int tvb_ws_mempbrk_pattern_uint8(tvbuff_t *tvb, const int offset,
631 const int maxlength, const ws_mempbrk_pattern* pattern, unsigned char *found_needle);
632
633WS_DEPRECATED_X("Use tvb_ws_mempbrk_pattern_uint8 instead")
634static inline int tvb_ws_mempbrk_pattern_guint8(tvbuff_t* tvb, const int offset,
635 const int maxlength, const ws_mempbrk_pattern* pattern, unsigned char* found_needle) {
636 return tvb_ws_mempbrk_pattern_uint8(tvb, offset, maxlength, pattern, found_needle);
637}
638
644WS_DLL_PUBLIC unsigned tvb_strsize(tvbuff_t *tvb, const int offset);
645
652WS_DLL_PUBLIC unsigned tvb_unicode_strsize(tvbuff_t *tvb, const int offset);
653
658WS_DLL_PUBLIC int tvb_strnlen(tvbuff_t *tvb, const int offset,
659 const unsigned maxlength);
660
664WS_DLL_PUBLIC char *tvb_format_text(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset,
665 const int size);
666
671WS_DLL_PUBLIC char *tvb_format_text_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const int offset,
672 const int size);
673
678extern char *tvb_format_stringzpad(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset,
679 const int size);
680
685extern char *tvb_format_stringzpad_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const int offset,
686 const int size);
687
708WS_DLL_PUBLIC uint8_t *tvb_get_string_enc(wmem_allocator_t *scope,
709 tvbuff_t *tvb, const int offset, const int length, const unsigned encoding);
710
733 tvbuff_t *tvb, const int bit_offset, int no_of_chars);
734
757 tvbuff_t *tvb, const int offset, int length);
758
780 tvbuff_t *tvb, const int offset, int length);
781
802WS_DLL_PUBLIC char *tvb_get_ascii_7bits_string(wmem_allocator_t *scope,
803 tvbuff_t *tvb, const int bit_offset, int no_of_chars);
804
825WS_DLL_PUBLIC uint8_t *tvb_get_stringzpad(wmem_allocator_t *scope,
826 tvbuff_t *tvb, const int offset, const int length, const unsigned encoding);
827
854WS_DLL_PUBLIC uint8_t *tvb_get_stringz_enc(wmem_allocator_t *scope,
855 tvbuff_t *tvb, const int offset, int *lengthp, const unsigned encoding);
856
881WS_DLL_PUBLIC
882WS_DEPRECATED_X("Use APIs that return a valid UTF-8 string instead")
883const uint8_t *tvb_get_const_stringz(tvbuff_t *tvb,
884 const int offset, int *lengthp);
885
895WS_DLL_PUBLIC int tvb_get_raw_bytes_as_stringz(tvbuff_t *tvb, const int offset,
896 const unsigned bufsize, uint8_t *buffer);
897
898/*
899 * Given a tvbuff, an offset into the tvbuff, a buffer, and a buffer size,
900 * extract as many raw bytes from the tvbuff, starting at the offset,
901 * as 1) are available in the tvbuff and 2) will fit in the buffer, leaving
902 * room for a terminating NUL.
903 */
904WS_DLL_PUBLIC int tvb_get_raw_bytes_as_string(tvbuff_t *tvb, const int offset, char *buffer, size_t bufsize);
905
910WS_DLL_PUBLIC bool tvb_ascii_isprint(tvbuff_t *tvb, const int offset,
911 const int length);
912
922WS_DLL_PUBLIC bool tvb_utf_8_isprint(tvbuff_t *tvb, const int offset,
923 const int length);
924
929WS_DLL_PUBLIC bool tvb_ascii_isdigit(tvbuff_t *tvb, const int offset,
930 const int length);
931
951WS_DLL_PUBLIC int tvb_find_line_end(tvbuff_t *tvb, const int offset, int len,
952 int *next_offset, const bool desegment);
953
972WS_DLL_PUBLIC int tvb_find_line_end_unquoted(tvbuff_t *tvb, const int offset,
973 int len, int *next_offset);
974
992WS_DLL_PUBLIC int tvb_skip_wsp(tvbuff_t *tvb, const int offset,
993 const int maxlength);
994
995WS_DLL_PUBLIC int tvb_skip_wsp_return(tvbuff_t *tvb, const int offset);
996
997int tvb_skip_uint8(tvbuff_t *tvb, int offset, const int maxlength, const uint8_t ch);
998WS_DEPRECATED_X("Use tvb_skip_uint8 instead")
999static inline int tvb_skip_guint8(tvbuff_t *tvb, int offset, const int maxlength, const uint8_t ch) {
1000 return tvb_skip_uint8(tvb, offset, maxlength, ch);
1001}
1002
1021WS_DLL_PUBLIC int tvb_get_token_len(tvbuff_t *tvb, const int offset, int len, int *next_offset, const bool desegment);
1022
1027WS_DLL_PUBLIC int tvb_strneql(tvbuff_t *tvb, const int offset,
1028 const char *str, const size_t size);
1029
1034WS_DLL_PUBLIC int tvb_strncaseeql(tvbuff_t *tvb, const int offset,
1035 const char *str, const size_t size);
1036
1041WS_DLL_PUBLIC int tvb_memeql(tvbuff_t *tvb, const int offset,
1042 const uint8_t *str, size_t size);
1043
1049WS_DLL_PUBLIC char *tvb_bytes_to_str_punct(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset,
1050 const int len, const char punct);
1051
1056WS_DLL_PUBLIC char *tvb_bytes_to_str(wmem_allocator_t *allocator, tvbuff_t *tvb,
1057 const int offset, const int len);
1058
1069typedef struct dgt_set_t
1070{
1071 const unsigned char out[16];
1072}
1074
1075WS_DLL_PUBLIC const char *tvb_bcd_dig_to_str(wmem_allocator_t *scope,
1076 tvbuff_t *tvb, const int offset, const int len, const dgt_set_t *dgt,
1077 bool skip_first);
1078
1090WS_DLL_PUBLIC const char *tvb_bcd_dig_to_str_be(wmem_allocator_t *scope,
1091 tvbuff_t *tvb, const int offset, const int len, const dgt_set_t *dgt,
1092 bool skip_first);
1093
1109WS_DLL_PUBLIC char *tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb,
1110 const int offset, int len, const dgt_set_t *dgt,
1111 bool skip_first, bool odd, bool bigendian);
1112
1117WS_DLL_PUBLIC int tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb,
1118 const int haystack_offset);
1119
1120/* From tvbuff_zlib.c */
1121
1122WS_DEPRECATED_X("Use tvb_uncompress_zlib instead")
1123WS_DLL_PUBLIC tvbuff_t *tvb_uncompress(tvbuff_t *tvb, const int offset,
1124 int comprlen);
1125
1135WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_zlib(tvbuff_t *tvb, const int offset,
1136 int comprlen);
1137
1138WS_DEPRECATED_X("Use tvb_child_uncompress_zlib instead")
1139WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress(tvbuff_t *parent, tvbuff_t *tvb,
1140 const int offset, int comprlen);
1141
1147WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_zlib(tvbuff_t *parent, tvbuff_t *tvb,
1148 const int offset, int comprlen);
1149
1150/* From tvbuff_brotli.c */
1151
1161WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_brotli(tvbuff_t *tvb, const int offset,
1162 int comprlen);
1163
1169WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_brotli(tvbuff_t *parent, tvbuff_t *tvb,
1170 const int offset, int comprlen);
1171
1172/* From tvbuff_snappy.c */
1173
1179WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_snappy(tvbuff_t *tvb, const int offset,
1180 int comprlen);
1181
1187WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_snappy(tvbuff_t *parent, tvbuff_t *tvb,
1188 const int offset, int comprlen);
1189
1190/* From tvbuff_lz77.c */
1191
1202WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_lz77(tvbuff_t *tvb,
1203 const int offset, int comprlen);
1204
1211WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_lz77(tvbuff_t *parent,
1212 tvbuff_t *tvb, const int offset, int comprlen);
1213
1214/* From tvbuff_lz77huff.c */
1215
1226WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_lz77huff(tvbuff_t *tvb,
1227 const int offset, int comprlen);
1228
1235WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_lz77huff(tvbuff_t *parent,
1236 tvbuff_t *tvb, const int offset, int comprlen);
1237
1238/* From tvbuff_lznt1.c */
1239
1250WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_lznt1(tvbuff_t *tvb,
1251 const int offset, int comprlen);
1252
1259WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_lznt1(tvbuff_t *parent,
1260 tvbuff_t *tvb, const int offset, int comprlen);
1261
1272WS_DLL_PUBLIC tvbuff_t *tvb_uncompress_zstd(tvbuff_t *tvb,
1273 const int offset, int comprlen);
1274
1281WS_DLL_PUBLIC tvbuff_t *tvb_child_uncompress_zstd(tvbuff_t *parent,
1282 tvbuff_t *tvb, const int offset, int comprlen);
1283
1284/* From tvbuff_base64.c */
1285
1295extern tvbuff_t* base64_to_tvb(tvbuff_t *parent, const char *base64);
1296
1297
1307extern tvbuff_t* base64_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length);
1308
1309extern tvbuff_t* base64uri_tvb_to_new_tvb(tvbuff_t* parent, int offset, int length);
1310
1311/* From tvbuff_hpackhuff.c */
1312
1313WS_DLL_PUBLIC wmem_strbuf_t* tvb_get_hpack_huffman_strbuf(wmem_allocator_t *scope,
1314 tvbuff_t *tvb, const int offset, const int len);
1315
1316WS_DLL_PUBLIC tvbuff_t* tvb_child_uncompress_hpack_huff(tvbuff_t *parent,
1317 int offset, int length);
1318
1332WS_DLL_PUBLIC unsigned tvb_get_varint(tvbuff_t *tvb, unsigned offset, unsigned maxlen, uint64_t *value, const unsigned encoding);
1333
1334/************** END OF ACCESSORS ****************/
1335
1338#ifdef __cplusplus
1339}
1340#endif /* __cplusplus */
1341
1342#endif /* __TVBUFF_H__ */
1343
1344/*
1345 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1346 *
1347 * Local variables:
1348 * c-basic-offset: 4
1349 * tab-width: 8
1350 * indent-tabs-mode: nil
1351 * End:
1352 *
1353 * vi: set shiftwidth=4 tabstop=8 expandtab:
1354 * :indentSize=4:tabSize=8:noTabs=true:
1355 */
WS_DLL_PUBLIC bool tvb_ascii_isprint(tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:4118
WS_DLL_PUBLIC bool tvb_ascii_isdigit(tvbuff_t *tvb, const int offset, const int length)
Definition tvbuff.c:4149
WS_DLL_PUBLIC int tvb_find_uint16(tvbuff_t *tvb, const int offset, const int maxlength, const uint16_t needle)
Definition tvbuff.c:2492
WS_DLL_PUBLIC int tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb, const int haystack_offset)
Definition tvbuff.c:4736
WS_DLL_PUBLIC int tvb_strnlen(tvbuff_t *tvb, const int offset, const unsigned maxlength)
Definition tvbuff.c:2668
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:4774
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:4530
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:3085
WS_DLL_PUBLIC int tvb_strneql(tvbuff_t *tvb, const int offset, const char *str, const size_t size)
Definition tvbuff.c:2696
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:3097
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:4068
WS_DLL_PUBLIC char * tvb_format_text_wsp(wmem_allocator_t *allocator, tvbuff_t *tvb, const int offset, const int size)
Definition tvbuff.c:2792
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:3784
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:4623
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:3553
WS_DLL_PUBLIC unsigned tvb_unicode_strsize(tvbuff_t *tvb, const int offset)
Definition tvbuff.c:2647
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:3287
WS_DLL_PUBLIC const uint8_t * tvb_get_const_stringz(tvbuff_t *tvb, const int offset, int *lengthp)
Definition tvbuff.c:3652
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:4601
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:3073
WS_DLL_PUBLIC char * tvb_format_text(wmem_allocator_t *scope, tvbuff_t *tvb, const int offset, const int size)
Definition tvbuff.c:2777
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:2723
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:3059
WS_DLL_PUBLIC int tvb_find_uint8(tvbuff_t *tvb, const int offset, const int maxlength, const uint8_t needle)
Definition tvbuff.c:2453
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:4715
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: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:4186
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:2751
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:4135
WS_DLL_PUBLIC char * tvb_bytes_to_str(wmem_allocator_t *allocator, tvbuff_t *tvb, const int offset, const int len)
Definition tvbuff.c:4727
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:2827
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:2617
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:2573
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:4458
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:2808
WS_DLL_PUBLIC unsigned tvb_get_varint(tvbuff_t *tvb, unsigned offset, unsigned maxlen, uint64_t *value, const unsigned encoding)
Definition tvbuff.c:4786
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:2423
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:4309
Definition guid-utils.h:23
Definition wmem_allocator.h:27
Definition wmem_strbuf.h:42
Definition mcast_stream.h:30
Definition tvbuff.h:1070
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