Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-dev: Re: [ethereal-dev] SIGBUS in packet-ntp

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: Thu, 2 Dec 1999 15:26:35 -0600
On Thu, Dec 02, 1999 at 02:18:10PM -0600, phil_t@xxxxxxxxxxxxx wrote:
> 
> 
> I put the SNMP build issue off to the side for now since I can get around 
> it.  Now I'm up and running (almost) with 0-7.9.  This is the first time 
> I've run against captures with NTP packets since the NTP support has been 
> added.
> 
> There are a couple of problems with the NTP decoding:
> 
> 1) It gets a SIGBUS on my Solaris box as it tries to do an unaligned access 
> referencing a long value in the packet instead of copying those bytes to an 
> aligned location then referencing it.  I haven't finished looking at it, 
> but most of the payload portion of the packet should probably be copied out 
> to avoid this type of problem.

Right. Just in case you (or anyone else reading on this list) haven't seen them,
packet.h has some macros to help doing that. They take a pointer, and construct
either 16-bit integer or a 32-bit integer from them the data pointed to:

#define pntohs(p)  ((guint16)                       \
                    ((guint16)*((guint8 *)p+0)<<8|  \
                     (guint16)*((guint8 *)p+1)<<0))

#define pntohl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
                    (guint32)*((guint8 *)p+1)<<16|  \
                    (guint32)*((guint8 *)p+2)<<8|   \
                    (guint32)*((guint8 *)p+3)<<0)

#define pletohs(p) ((guint16)                       \
                    ((guint16)*((guint8 *)p+1)<<8|  \
                     (guint16)*((guint8 *)p+0)<<0))

#define pletohl(p) ((guint32)*((guint8 *)p+3)<<24|  \
                    (guint32)*((guint8 *)p+2)<<16|  \
                    (guint32)*((guint8 *)p+1)<<8|   \
                    (guint32)*((guint8 *)p+0)<<0)

--gilbert