Ethereal-dev: [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:39:36 -0800 (PST)
I suspect many people writing code that fetches IPv4 addresses from
packets assume that they should convert it from network byte order, use
"tvb_get_ntohl()", find that doing so doesn't give the right answers on
the PC that they're probably developing on, try "tvb_get_letohl()"
instead, find that doing so *does* work on their PC, and assume,
therefore, that it's the right way to fetch IPv4 addresses.

It isn't.  That won't give the right answer on big-endian platforms such
as SPARC and, I suspect, most PowerPC machines.

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);

not

	ipv4_addr = tvb_get_ntohl(tvb, offset);

or

	ipv4_addr = tvb_get_letohl(tvb, offset);

I've put a note in README.developer about this, right after describing
the "tvb_get_ntohX()" and "tvb_get_letohX()" routines.

I've fixed the places I've found where "tvb_get_letohl()" was being
used.