Ethereal-dev: Re: [Ethereal-dev] referencing specific tcp protocol data

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

From: Guy Harris <guy@xxxxxxxxxx>
Date: Fri, 29 Mar 2002 14:22:06 -0800
On Fri, Mar 29, 2002 at 02:10:49PM -0600, Gilbert Ramirez wrote:
> Let's say we add a new function,
> 
> int
> proto_registar_lookup_abbrev(const char*)
> 
> Then you could find the ID via:
> 
> tcp_hdr_len_id = proto_registar_lookup_abbrev("tcp.hdr_len")
> 
> With that, you could get an array of field_info pointers, since
> a proto_tree might have more than 1 such field_info, via:
> 
> GPtrArray*
> proto_get_finfo_ptr_array(proto_tree *tree, int id)
> 
> Then you could iterate across the array. For each field_finfo, you could
> get the integer value via:
> 
> fvalue_get_integer(finfo_ptr->value);

In his particular case, he might want *specific* instances of that
field, e.g. if you have a protocol tree (displayed with siblings at the
same indentation level, and children indented):

	Frame
	Ethernet
	IP
	{some encapsulation protocol or protocols}
      ->IP
	TCP
	{protocols atop TCP, if any}

he'd presumably want the IP instance with the arrow pointing to it, to
get the length of the payload of the TCP below it.

What he'd want there would be

	header_field_info *
	proto_registrar_get_byabbrev(const char *)

which would take an abbreviation and return a "header_field_info *" for
the field.

Then he'd iterate over the tree, using code similar to your
"proto_hier_stats.c" code, except that his equivalent to
"process_node()" would ignore nodes other than TCP or IP nodes (nodes
where the "header_field_info *" was something other than what's returned
by

	proto_registrar_get_byabbrev("ip")

or

	proto_registrar_get_byabbrev("ipv6")

or

	proto_registrar_get_byabbrev("tcp")

) and would:

	for IP nodes ("ip" or "ipv6"), fetch the header length and total
	length values, and save them, *overwriting any previously
	fetched values for that frame* so that it gets the topmost IP
	values;

	for TCP nodes ("tcp"), fetch the other information (and
	presumably, again, overwrite previous values fetched for that
	frame).

It'd fetch those values by scanning the children of those nodes, looking
for nodes with "header_field_info *" values equal to the return values
of:

	proto_registrar_get_byabbrev("ip.hdr_len"), for the IP header
	length;

	proto_registrar_get_byabbrev("ip.len"), for the IP datagram
	total length;

	proto_registrar_get_byabbrev("tcp.seq"), for the TCP sequence
	number;

	proto_registrar_get_byabbrev("tcp.flags.ack"), to see if the ACK
	flag is set, and thus to see if the acknowledgement number is
	present;

	if it is present, proto_registrar_get_byabbrev("tcp.ack"), for
	the TCP acknowledgment number;

	proto_registrar_get_byabbrev("tcp.hdr_len"), for the TCP header
	length.