Ethereal-dev: Re: [ethereal-dev] proto_tree_add_ipv4

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

From: Gilbert Ramirez <gram@xxxxxxxxxx>
Date: Fri, 07 Jul 2000 08:01:57 -0500
On Fri, Jul 07, 2000 at 12:55:45PM +0200, Michael Tuxen wrote:
> Dear all,
> the last parameter of the proto_tree_add_ipv4 function is the guint32
> address in network byte order. In the corresponding IPv6 function it is a
> pointer.
> When dealing with tvbuffs I think it would be a goot idea to change
> proto_tree_add_ipv4 so that the last paramter is also a pointer. Then
> both functions are similiar and I don't have
> to use first a tvb_memcpy call to get the ip address in network byte
> order and than to call
> proto_tree_add_ipv4. I could only call proto_tree_add_ipv4 and use
> tvb_get_ptr for the last argument.

I agree that the need for a tvb_memcpy() in the dissector is a bit much.

There are different ways to handle this:

1) Have proto_tree_add_ipv4() accept IPv4 address in *host* order, and
convert to network order before storing the value.
The dissector looks like this:

	proto_tree_add_ipv4(..., tvb_get_ntohl(..))

But then, on little-endian machines, the address is getting byte-swapped
twice. Also, proto_tree_add_item(), when dealing with FT_IPv4 fields,
would not know whether the data in the packet was in host order or not,
because that decision has been removed from proto_tree routines and
placed in the dissector.

2) Your example of having proto_tree_add_ipv4() accept a pointer.
The dissector looks like this:

	proto_tree_add_ipv4(..., tvb_get_ptr(.., 4))

It still assumes a certain byte order in the packet, which is good,
since proto_tree_add_item() will still work for FT_IPv4 fields.


So, yes, I like your suggestion.

--gilbert