ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: Re: [Wireshark-dev] Memory Question

From: Jakub Zawadzki <darkjames@xxxxxxxxxxxxxxxx>
Date: Thu, 26 Feb 2009 16:47:42 +0100
Hi,

On Thu, Feb 26, 2009 at 09:15:04AM -0600, gogrady@xxxxxxxxx wrote:
> const BYTE* target;
> tvb_memcpy(tvb, target, offset, data_length);
> 
> and i get the error:
> packet-icom.c
> packet-icom.c(246) : error C2220: warning treated as error - no 'object' file ge
> nerated
> packet-icom.c(246) : warning C4090: 'function' : different 'const' qualifiers
> NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
> \cl.EXE"' : return code '0x2'
> Stop.
> 
> can someone please clarify this?

If you have problems with memory management in C,
you can use tvb_memdup() (which automagiclly allocates buffer)

assuming prototype: FOO *yourFunc(const BYTE *ptr, unsigned int len)

you can call:
{
	guint plen;
	void *ptr;
	FOO *bar;

	plen = tvb_length(tvb);			/* packet len */
	ptr  = tvb_memdup(tvb, 0, plen);	/* buffer */
	bar  = yourFunc((const BYTE *) ptr, plen);

	/* do what you want with bar */

	g_free(ptr);	/* free memory */
}

(and wireshark API has got also ep_tvb_memdup(), where you don't care
about freeing memory)

and that's all, hth!