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: Phil Williams <csypbw@xxxxxxxxxxxxxxxx>
Date: Thu, 18 Apr 2002 16:21:03 +0100 (BST)
> Pleas send us that code, so we can make it a standard part of Ethereal,
> so that you don't have to keep modifying Ethereal as each new release
> comes out.
>
Sorry about the wait, I completely forgot. Anyway, below is a routine
when added to epan/proto.c (and the prototype in epan/proto.h) will do a
name lookup, given a pointer to a string, it will return a
header_field_info pointer if the protocol database contains that string,
and a null pointer if not.  It looks up on the unique abbreviations
registered, e.g. "ip" for IP packets, "ip.len" for the ip packet length
etc.

Let me know if you find it if of use.
I used it to test for certain protocol frames and extract protocol specific
data from a protocol tree.
I also have some code that adds some metrics to the pop up summary
window in Ethereal, its a bit hacked together, but you can have a copy
if you want.

add to epan/proto.h:
______________________________________________


header_field_info* proto_return_hf_ptr(const char *field_name);

----------------------------------------------

and to epan/proto.c:

----------------------------------------------

header_field_info*
proto_return_hf_ptr(const char *field_name) {

	header_field_info	*hfinfo, *parent_hfinfo;
	int			i, len, hf_num;
	const char 		*enum_name;

	hf_num = -1;
	len = gpa_hfinfo->len;

	for (i = 0; i < len ; i++) {
		hfinfo = proto_registrar_get_nth(i);

		if((strcmp(hfinfo->abbrev,field_name))== 0){
			hf_num = hfinfo->id;
		}
	}


	if (hf_num == -1) {
		return NULL;
	}

	else{
		return proto_registrar_get_nth(hf_num);
	}

}
------------------------------------------------------------------------

Phil Williams

phil@xxxxxxxxxxxxxx