Ethereal-dev: Re: [ethereal-dev] Dissector question: variable length structures

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

From: David Frascone <dave@xxxxxxxxxxxx>
Date: Fri, 14 Jul 2000 09:37:20 -0500
I usually just use a C structure like this:

typedef struct {
	int 	length;
	char    data[1];
} var_hdr;

Then I point this structure a the data, and let my index of var_hdr.data
be greater than 1.  

	var_hdr *hdr;

	hdr = (var_hdr *)data;

	/* stupid example that prints one char at a time */
	for (i=0;i<hdr->length;i++) 
		printf("%c", hdr->data[i]);

Get it?

On Fri, Jul 14, 2000 at 10:21:26AM -0400, Craig Rodrigues wrote:
> Hi,
> 
> I would like to give a shot at enhancing the packet-giop.c
> dissector for CORBA IIOP.  I was wondering, what technique
> do people use in the other dissectors for dealing with
> variable length data structures?  For example, IIOP
> defines a string which is represented by it's length n, followed
> by n + 1 bytes which contain the actual string (with other encoding
> schemes for wide characters).  Is there a glib structure that I can
> use?  I'm a bit lazy to do all the memory management by myself. :)
> 
> It's been a while since I have coded in C, so please forgive me
> if my question seems a bit newbie-ish. :)  
> -- 
> Craig Rodrigues        
> http://www.gis.net/~craigr    
> rodrigc@xxxxxxxxxxxx