Ethereal-dev: Re: [Ethereal-dev] Buffers and pointers in a dissector

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Richard Sharpe <rsharpe@xxxxxxxxxx>
Date: Fri, 22 Nov 2002 04:51:39 +1030 (CST)
On Thu, 21 Nov 2002, Paul Smith wrote:

> I am attempting to write my first dissector for Ethereal. The most 
> efficient way that I can work out to do this particular dissector isto 
> define a structure that is the right shape for the elements of the 
> protocol. Then simply assign a pointer of this type to the start of the 
> buffer. Can I do this in Ethereal?

You can do this, but it will not work in a very portable way.

> Example:
> 
> struct udp
> {
>     unsigned short source_port;
>     unsigned short destination_port
>     unsigned short length;
>     unsigned short checksum;
> }
> 
> struct udp_header *udp_hdr;
> 
> udp_hdr=(struct udp_header*)data_buffer
> 
> I cannot work out if I can do this (with tvb_get_ptr??). Everything I tried didn't work.
> 
> By using this method, if I want to read the UDP source port, I can simply access "udp_hdr->source_port".
> 
> For complex protocols, this saves me LOADS of effort using the tvb_get type access mechanisms.
> 
> Thanks in advance for any help/advice you can give

-- 
Regards
-----
Richard Sharpe, rsharpe[at]ns.aus.com, rsharpe[at]samba.org, 
sharpe[at]ethereal.com, http://www.richardsharpe.com