Ethereal-dev: Re: [Ethereal-dev] ntohl(), pntohl(), g_ntohl() ?

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

From: "Ronnie Sahlberg" <sahlberg@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Aug 2002 22:05:16 +1000
From: "Yaniv Kaul"
Sent: Thursday, August 15, 2002 5:27 PM
Subject: RE: [Ethereal-dev] ntohl(), pntohl(), g_ntohl() ?


> Thanks. Follow up question, on performance:
> Which method is preferable:
> (1)
>
> struct some_hdr hdr;
> tvb_memcpy(tvb, (guint8 *)&hdr, offset, sizeof(hdr));
> proto_tree_add_X(...,hdr.a);
> proto_tree_add_Y(...,hdr.b);
>
> -or-
>
> (2)
>
> struct some_hdr hdr;
> hdr.a = tvb_get_X();
> hdr.b = tvb_get_Y();
> proto_tree_add_X(...,hdr.a);
> proto_tree_add_Y(...,hdr.b);
>

I would say (2) would be preferable. Not for performance but for
correctness.
(2) will automatically make it work regardless of whether the host is LE or
BE.