3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
21 * Uncompresses a snappy compressed packet inside a message of tvb at offset with
22 * length comprlen. Returns an uncompressed tvbuffer if uncompression
23 * succeeded or NULL if uncompression failed.
27 tvb_uncompress_snappy(tvbuff_t
*tvb
, const int offset
, int comprlen
)
29 tvbuff_t
*uncompr_tvb
= NULL
;
30 unsigned char *decompressed_buffer
= NULL
;
33 const void *compr_ptr
;
35 if (tvb
== NULL
|| comprlen
<= 0 || comprlen
> tvb_captured_length_remaining(tvb
, offset
)) {
39 compr_ptr
= tvb_get_ptr(tvb
, offset
, comprlen
);
40 ret
= snappy_uncompressed_length(compr_ptr
, comprlen
, &orig_size
);
42 if (ret
== SNAPPY_OK
) {
43 decompressed_buffer
= (unsigned char *)g_malloc(orig_size
);
45 ret
= snappy_uncompress(compr_ptr
, comprlen
, decompressed_buffer
, &orig_size
);
47 if (ret
== SNAPPY_OK
) {
48 uncompr_tvb
= tvb_new_real_data(decompressed_buffer
, (uint32_t)orig_size
, (uint32_t)orig_size
);
49 tvb_set_free_cb(uncompr_tvb
, g_free
);
51 g_free(decompressed_buffer
);
59 tvb_uncompress_snappy(tvbuff_t
*tvb _U_
, const int offset _U_
, int comprlen _U_
)
66 tvb_child_uncompress_snappy(tvbuff_t
*parent
, tvbuff_t
*tvb
, const int offset
, int comprlen
)
68 tvbuff_t
*new_tvb
= tvb_uncompress_snappy(tvb
, offset
, comprlen
);
70 tvb_set_child_real_data_tvbuff(parent
, new_tvb
);
75 * Editor modelines - https://www.wireshark.org/tools/modelines.html
80 * indent-tabs-mode: nil
83 * vi: set shiftwidth=4 tabstop=8 expandtab:
84 * :indentSize=4:tabSize=8:noTabs=true: