Ethereal-dev: [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: "Paul Smith" <pihebbr@xxxxxxxxxxx>
Date: Thu, 21 Nov 2002 08:53:57 -0000
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?
 
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