Ethereal-dev: Re: [Ethereal-dev] Do *NOT* use "tvb_get_letohl()" to fetch IPv4 addresses

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: Tue, 30 Oct 2001 13:44:36 -0800 (PST)
> The correct way to fetch IPv4 addresses is with "tvb_memcpy()", as IPv4
> addresses are kept in *network* byte order, not *host* byte order,
> inside protocol trees:
> 
> 	guint32 ipv4_addr;
> 
> 		...
> 
> 	tvb_memcpy(tvb, (guint8 *)&ipv4_addr, offset, 4);

...or, if you're just doing

	proto_tree_add_ipv4(tree, hf_XXX, tvb, offset, 4,
	    tvb_get_letohl(tvb, offset));

you might as well just do

	proto_tree_add_item(tree, hf_XXX, tvb, offset, 4, FALSE);

and let "proto_tree_add_item()" do the fetching for you.

This also applies to

	proto_tree_add_uint(tree, hf_XXX, tvb, offset, 1,
	    tvb_get_guint8(tvb, offset));

which can be done as

	proto_tree_add_item(tree, hf_XXX, tvb, offset, 1, FALSE);

and

	proto_tree_add_uint(tree, hf_XXX, tvb, offset, 2,
	    tvb_get_ntohs(tvb, offset));

which can be done as

	proto_tree_add_item(tree, hf_XXX, tvb, offset, 2, FALSE);

and

	proto_tree_add_uint(tree, hf_XXX, tvb, offset, 3,
	    tvb_get_ntoh24(tvb, offset));

which can be done as

	proto_tree_add_item(tree, hf_XXX, tvb, offset, 3, FALSE);

and

	proto_tree_add_uint(tree, hf_XXX, tvb, offset, 4,
	    tvb_get_ntohl(tvb, offset));

which can be done as

	proto_tree_add_item(tree, hf_XXX, tvb, offset, 4, FALSE);

and

	proto_tree_add_uint(tree, hf_XXX, tvb, offset, 2,
	    tvb_get_letohs(tvb, offset));

which can be done as

	proto_tree_add_item(tree, hf_XXX, tvb, offset, 2, TRUE);

and

	proto_tree_add_uint(tree, hf_XXX, tvb, offset, 3,
	    tvb_get_letoh24(tvb, offset));

which can be done as

	proto_tree_add_item(tree, hf_XXX, tvb, offset, 3, TRUE);

and

	proto_tree_add_uint(tree, hf_XXX, tvb, offset, 4,
	    tvb_get_letohl(tvb, offset));

which can be done as

	proto_tree_add_item(tree, hf_XXX, tvb, offset, 4, TRUE);

and so on.