Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] Extract bytes from a tvbuff_t

From: ronnie sahlberg <ronniesahlberg@xxxxxxxxx>
Date: Sat, 25 May 2013 14:11:20 -0700
fwrite(extracted, sizeof(extracted), 1, file)

extracted is a pointer so sizeof(extracted) is the size of pointers on
your platform.   Often 4 on 32-bit platforms and 8 on 64-bit.

You need something like this :
fwrite(extracted, tvb_get_length(tvb, 0), 1, file)

On Sat, May 25, 2013 at 1:42 PM, Rion Carter <rion@xxxxxxxxxx> wrote:
> Hi,
>
> I'm trying to extract raw bytes from a tvbuff_t and am not having much luck.
> As a simple test I have code which tries to extract the bytes and write it
> to a file. When I compile and run I get an output file with only 4 bytes in
> it when I know there is more (extracting certificates).
>
> Here is what I've got. Any help is appreciated:
>
> guint8* extracted = (guint8*)ep_tvb_memdup(tvb, 0, -1);
> fwrite(extracted, size of extracted), 1, file);
>
> It's been awhile since I used c file io, and I'm pretty new to Wireshark
> dev. I may be missing obvious or going about this in the wrong fashion.
>
> Rion
>
> ___________________________________________________________________________
> Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
> Archives:    http://www.wireshark.org/lists/wireshark-dev
> Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
>              mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe