From beb4876cb4dda2b9964c223041386e5e6e33a31e Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 8 Apr 2014 10:57:59 -0700 Subject: Don't assume the data pointed to by an address structure is aligned. And don't assume you can dereference the pointer nonetheless; that doesn't work on SPARC, for example - you get an unaligned-access trap. Instead, use pntoh32() to fetch IPv4 address values from the address structures. While we're at it, just use guint32 for those addresses; we don't need in_addr_t. Change-Id: I84e6c653fe33b1bc6e67d9097ce423b82f1eb0c8 Reviewed-on: https://code.wireshark.org/review/1024 Reviewed-by: Guy Harris --- epan/dissectors/packet-lbmr.c | 15 +++++---------- epan/dissectors/packet-lbtrm.c | 19 +++++++------------ 2 files changed, 12 insertions(+), 22 deletions(-) (limited to 'epan') diff --git a/epan/dissectors/packet-lbmr.c b/epan/dissectors/packet-lbmr.c index 47b4543e4a..32cf854c02 100644 --- a/epan/dissectors/packet-lbmr.c +++ b/epan/dissectors/packet-lbmr.c @@ -25,8 +25,6 @@ #include "config.h" #ifdef HAVE_ARPA_INET_H #include -#else - typedef unsigned int in_addr_t; #endif #if HAVE_WINSOCK2_H #include @@ -44,6 +42,7 @@ #include #include #include +#include #include "packet-lbm.h" #include "packet-lbtru.h" #include "packet-lbtrm.h" @@ -2043,17 +2042,13 @@ static void lbmr_tag_free_cb(void * record) static gboolean lbmr_match_packet(packet_info * pinfo, const lbmr_tag_entry_t * entry) { - in_addr_t dest_addr; - in_addr_t src_addr; - in_addr_t dest_addr_h; - in_addr_t src_addr_h; + guint32 dest_addr_h; + guint32 src_addr_h; if (pinfo->dst.type != AT_IPv4 || pinfo->src.type != AT_IPv4) return (FALSE); - dest_addr = *((in_addr_t *)pinfo->dst.data); - dest_addr_h = g_ntohl(dest_addr); - src_addr = *((in_addr_t *)pinfo->src.data); - src_addr_h = g_ntohl(src_addr); + dest_addr_h = pntoh32(pinfo->dst.data); + src_addr_h = pntoh32(pinfo->src.data); if (IN_MULTICAST(dest_addr_h)) { diff --git a/epan/dissectors/packet-lbtrm.c b/epan/dissectors/packet-lbtrm.c index d4f97f9c5f..ee8f512a25 100644 --- a/epan/dissectors/packet-lbtrm.c +++ b/epan/dissectors/packet-lbtrm.c @@ -25,8 +25,6 @@ #include "config.h" #ifdef HAVE_ARPA_INET_H #include -#else - typedef unsigned int in_addr_t; #endif #if HAVE_WINSOCK2_H #include @@ -43,6 +41,7 @@ #include #include #include +#include #include "packet-lbm.h" #include "packet-lbtrm.h" @@ -742,16 +741,14 @@ static char * lbtrm_tag_find(packet_info * pinfo) { guint idx; lbtrm_tag_entry_t * tag = NULL; - in_addr_t dest_addr; - in_addr_t dest_addr_h; + guint32 dest_addr_h; if (!lbtrm_use_tag) { return (NULL); } - dest_addr = *((in_addr_t *)pinfo->dst.data); - dest_addr_h = g_ntohl(dest_addr); + dest_addr_h = pntoh32(pinfo->dst.data); for (idx = 0; idx < lbtrm_tag_count; ++idx) { tag = &(lbtrm_tag_entry[idx]); @@ -1531,8 +1528,7 @@ static int dissect_lbtrm(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, static gboolean test_lbtrm_packet(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * user_data) { - in_addr_t dest_addr; - in_addr_t dest_addr_h; + guint32 dest_addr_h; gboolean valid_packet = FALSE; guint8 ver_type = 0; guint8 packet_type = 0; @@ -1584,8 +1580,7 @@ static gboolean test_lbtrm_packet(tvbuff_t * tvb, packet_info * pinfo, proto_tre } else { - dest_addr = *((in_addr_t *)pinfo->dst.data); - dest_addr_h = g_ntohl(dest_addr); + dest_addr_h = pntoh32(pinfo->dst.data); /* Is the destination a multicast address? */ if (IN_MULTICAST(dest_addr_h)) @@ -1633,8 +1628,8 @@ void proto_reg_handoff_lbtrm(void) { static gboolean already_registered = FALSE; struct in_addr addr; - in_addr_t dest_addr_h_low; - in_addr_t dest_addr_h_high; + guint32 dest_addr_h_low; + guint32 dest_addr_h_high; if (!already_registered) { -- cgit v1.2.3