aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2000-01-15 04:17:37 +0000
committerGuy Harris <guy@alum.mit.edu>2000-01-15 04:17:37 +0000
commit7063b3ae251be32e727b3bfd9dad28bb8ed0a075 (patch)
treeeffd0ff49a3ee02739db891b65ac3c0d8851c021
parent339d67b043a1f1ac860b84ed48ec6ba77d96f487 (diff)
Fix up a bunch of places where a pointer into the packet buffer was cast
to a type requiring 2-byte or better alignment and was then dereferenced; doing that requires that the code generated by your compiler not trap if it makes an unaligned reference, and on most RISC processors the code generated by the compiler *will* trap on an unaligned reference by default. svn path=/trunk/; revision=1480
-rw-r--r--packet-afs.c16
-rw-r--r--packet-bgp.c54
-rw-r--r--packet-ipv6.c6
-rw-r--r--packet-pim.c32
4 files changed, 54 insertions, 54 deletions
diff --git a/packet-afs.c b/packet-afs.c
index 50be628a2e..120002e529 100644
--- a/packet-afs.c
+++ b/packet-afs.c
@@ -6,7 +6,7 @@
* Portions based on information retrieved from the RX definitions
* in Arla, the free AFS client at http://www.stacken.kth.se/project/arla/
*
- * $Id: packet-afs.c,v 1.8 2000/01/07 22:05:28 guy Exp $
+ * $Id: packet-afs.c,v 1.9 2000/01/15 04:17:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -764,8 +764,8 @@ dissect_afs(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
}
request_key.conversation = conversation->index;
- request_key.service = ntohs(rxh->serviceId);
- request_key.callnumber = ntohl(rxh->callNumber);
+ request_key.service = pntohs(&rxh->serviceId);
+ request_key.callnumber = pntohl(&rxh->callNumber);
request_val = (struct afs_request_val *) g_hash_table_lookup(
afs_request_hash, &request_key);
@@ -778,7 +778,7 @@ dissect_afs(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
*new_request_key = request_key;
request_val = g_mem_chunk_alloc(afs_request_vals);
- request_val -> opcode = ntohl(afsh->opcode);
+ request_val -> opcode = pntohl(&afsh->opcode);
opcode = request_val->opcode;
g_hash_table_insert(afs_request_hash, new_request_key,
@@ -959,7 +959,7 @@ dissect_afs(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
*/
/* Get the next available integer, be sure and call TRUNC beforehand */
-#define GETINT() (ntohl( *((int*)&pd[curoffset]) ))
+#define GETINT() (pntohl(&pd[curoffset]))
/* Check if enough bytes are present, if not, return to caller
after adding a 'Truncated' message to tree */
@@ -1108,7 +1108,7 @@ dissect_afs(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
#define STROUT(field) \
{ int i; \
TRUNC(4); \
- i = ntohl(*((int *) &pd[curoffset])); \
+ i = pntohl(&pd[curoffset]); \
curoffset += 4; \
TRUNC(i); \
if ( i > 0 ) { \
@@ -1188,7 +1188,7 @@ static void dissect_acl(const u_char *pd, int offset, frame_data *fd, proto_tree
curoffset = offset;
TRUNC(sizeof(guint32));
- bytes = ntohl(*((int *) &pd[curoffset]));
+ bytes = pntohl(&pd[curoffset]);
UINTOUT(hf_afs_fs_acl_datasize);
TRUNC(bytes);
@@ -1367,7 +1367,7 @@ dissect_fs_request(const u_char *pd, int offset, frame_data *fd, proto_tree *tre
unsigned int j,i;
TRUNC(1);
- j = ntohl( *((int*)&pd[curoffset]) );
+ j = pntohl(&pd[curoffset]);
curoffset += 1;
for (i=0; i<j; i++)
{
diff --git a/packet-bgp.c b/packet-bgp.c
index 1921388ced..aafe62bfb3 100644
--- a/packet-bgp.c
+++ b/packet-bgp.c
@@ -324,7 +324,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
p = &pd[offset + BGP_HEADER_SIZE]; /*XXX*/
/* check for withdrawals */
- len = ntohs(*(guint16 *)p);
+ len = pntohs(p);
proto_tree_add_text(tree, p - pd, 2,
"Unfeasible routes length: %u %s", len, (len == 1) ? "byte" : "bytes");
p += 2;
@@ -347,7 +347,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
}
/* check for advertisements */
- len = ntohs(*(guint16 *)p);
+ len = pntohs(p);
proto_tree_add_text(tree, p - pd, 2, "Total path attribute length: %u %s",
len, (len == 1) ? "byte" : "bytes");
@@ -366,7 +366,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
memcpy(&bgpa, &p[i], sizeof(bgpa));
/* check for the Extended Length bit */
if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
- alen = ntohs(*(guint16 *)&p[i + sizeof(bgpa)]);
+ alen = pntohs(&p[i + sizeof(bgpa)]);
aoff = sizeof(bgpa) + 2;
} else {
alen = p[i + sizeof(bgpa)];
@@ -455,7 +455,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
"%s: %u (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- ntohl(*(guint32 *)&p[i + aoff]), alen + aoff,
+ pntohl(&p[i + aoff]), alen + aoff,
(alen + aoff == 1) ? "byte" : "bytes");
break;
case BGPTYPE_LOCAL_PREF:
@@ -464,7 +464,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
"%s: %u (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- ntohl(*(guint32 *)&p[i + aoff]), alen + aoff,
+ pntohl(&p[i + aoff]), alen + aoff,
(alen + aoff == 1) ? "byte" : "bytes");
break;
case BGPTYPE_ATOMIC_AGGREGATE:
@@ -481,7 +481,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
"%s: AS: %u origin: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- ntohs(*(guint16 *)&p[i + aoff]),
+ pntohs(&p[i + aoff]),
ip_to_str(&p[i + aoff + 2]), alen + aoff,
(alen + aoff == 1) ? "byte" : "bytes");
break;
@@ -490,18 +490,18 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
goto default_attribute_top;
/* check for well-known communities */
- if (ntohl(*(guint32 *)&p[i + aoff]) == BGP_COMM_NO_EXPORT)
+ if (pntohl(&p[i + aoff]) == BGP_COMM_NO_EXPORT)
strncpy(junk_buf, "NO_EXPORT", 10);
- else if (ntohl(*(guint32 *)&p[i + aoff]) ==
+ else if (pntohl(&p[i + aoff]) ==
BGP_COMM_NO_ADVERTISE)
strncpy(junk_buf, "NO_ADVERTISE", 13);
- else if (ntohl(*(guint32 *)&p[i + aoff]) ==
+ else if (pntohl(&p[i + aoff]) ==
BGP_COMM_NO_EXPORT_SUBCONFED)
strncpy(junk_buf, "NO_EXPORT_SUBCONFED", 20);
else {
snprintf(junk_buf, sizeof(junk_buf), "%u:%u",
- ntohs(*(guint16 *)&p[i + aoff]),
- ntohs(*(guint16 *)&p[i + aoff + 2]));
+ pntohs(&p[i + aoff]),
+ pntohs(&p[i + aoff + 2]));
}
ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
@@ -687,7 +687,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
} else {
proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
"Multi exit discriminator: %u",
- ntohl(*(guint32 *)&p[i + aoff]));
+ pntohl(&p[i + aoff]));
}
break;
case BGPTYPE_LOCAL_PREF:
@@ -698,7 +698,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
} else {
proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
"Local preference: %u",
- ntohl(*(guint32 *)&p[i + aoff]));
+ pntohl(&p[i + aoff]));
}
break;
case BGPTYPE_ATOMIC_AGGREGATE:
@@ -716,7 +716,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
} else {
proto_tree_add_text(subtree2, p - pd + i + aoff, 2,
"Aggregator AS: %u",
- ntohs(*(guint16 *)&p[i + aoff]));
+ pntohs(&p[i + aoff]));
proto_tree_add_text(subtree2, p - pd + i + aoff + 2, 4,
"Aggregator origin: %s",
ip_to_str(&p[i + aoff + 2]));
@@ -729,36 +729,36 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
(alen == 1) ? "byte" : "bytes");
}
/* check for reserved values */
- else if (ntohs(*(guint16 *)&p[i + aoff]) == FOURHEX0 ||
- ntohs(*(guint16 *)&p[i + aoff]) == FOURHEXF) {
+ else if (pntohs(&p[i + aoff]) == FOURHEX0 ||
+ pntohs(&p[i + aoff]) == FOURHEXF) {
/* check for well-known communities */
- if (ntohl(*(guint32 *)&p[i + aoff]) == BGP_COMM_NO_EXPORT)
+ if (pntohl(&p[i + aoff]) == BGP_COMM_NO_EXPORT)
proto_tree_add_text(subtree2, p - pd + i + aoff, 4,
"Communities: NO_EXPORT (0x%x)",
- ntohl(*(guint32 *)&p[i + aoff]));
- else if (ntohl(*(guint32 *)&p[i + aoff]) ==
+ pntohl(&p[i + aoff]));
+ else if (pntohl(&p[i + aoff]) ==
BGP_COMM_NO_ADVERTISE)
proto_tree_add_text(subtree2, p - pd + i + aoff, 4,
"Communities: NO_ADVERTISE (0x%x)",
- ntohl(*(guint32 *)&p[i + aoff]));
- else if (ntohl(*(guint32 *)&p[i + aoff]) ==
+ pntohl(&p[i + aoff]));
+ else if (pntohl(&p[i + aoff]) ==
BGP_COMM_NO_EXPORT_SUBCONFED)
proto_tree_add_text(subtree2, p - pd + i + aoff, 4,
"Communities: NO_EXPORT_SUBCONFED (0x%x)",
- ntohl(*(guint32 *)&p[i + aoff]));
+ pntohl(&p[i + aoff]));
else {
proto_tree_add_text(subtree2, p - pd + i + aoff, 4,
"Communities (reserved): 0x%x",
- ntohl(*(guint32 *)&p[i + aoff]));
+ pntohl(&p[i + aoff]));
}
}
else {
proto_tree_add_text(subtree2, p - pd + i + aoff, 2,
"Communities AS: %u",
- ntohs(*(guint16 *)&p[i + aoff]));
+ pntohs(&p[i + aoff]));
proto_tree_add_text(subtree2, p - pd + i + aoff + 2, 2,
"Communities value: %u",
- ntohs(*(guint16 *)&p[i + aoff + 2]));
+ pntohs(&p[i + aoff + 2]));
}
break;
case BGPTYPE_ORIGINATOR_ID:
@@ -773,7 +773,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
}
break;
case BGPTYPE_MP_REACH_NLRI:
- af = ntohs(*(guint16 *)&p[i + aoff]);
+ af = pntohs(&p[i + aoff]);
proto_tree_add_text(subtree2, p - pd + i + aoff, 2,
"Address family: %s (%u)",
val_to_str(af, afnumber, "Unknown"), af);
@@ -868,7 +868,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
break;
case BGPTYPE_MP_UNREACH_NLRI:
- af = ntohs(*(guint16 *)&p[i + aoff]);
+ af = pntohs(&p[i + aoff]);
proto_tree_add_text(subtree2, p - pd + i + aoff, 2,
"Address family: %s (%u)",
val_to_str(af, afnumber, "Unknown"), af);
diff --git a/packet-ipv6.c b/packet-ipv6.c
index 3c30156391..f40f475d9d 100644
--- a/packet-ipv6.c
+++ b/packet-ipv6.c
@@ -1,7 +1,7 @@
/* packet-ipv6.c
* Routines for IPv6 packet disassembly
*
- * $Id: packet-ipv6.c,v 1.25 1999/11/16 11:42:36 guy Exp $
+ * $Id: packet-ipv6.c,v 1.26 2000/01/15 04:17:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -196,7 +196,7 @@ dissect_opts(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
if (p[1] == 4) {
proto_tree_add_text(dstopt_tree, p - pd, p[1] + 2,
"Jumbo payload: %u (%d bytes)",
- ntohl(*(guint32 *)&p[2]), p[1] + 2);
+ pntohl(&p[2]), p[1] + 2);
} else {
proto_tree_add_text(dstopt_tree, p - pd, p[1] + 2,
"Jumbo payload: Invalid length (%d bytes)",
@@ -210,7 +210,7 @@ dissect_opts(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
char *rta;
if (p[1] == 2) {
- rta = val_to_str(ntohs(*(guint16 *)&p[2]), rtalertvals,
+ rta = val_to_str(pntohs(&p[2]), rtalertvals,
"Unknown");
} else
rta = "Invalid length";
diff --git a/packet-pim.c b/packet-pim.c
index a42b5f18ca..37d2471440 100644
--- a/packet-pim.c
+++ b/packet-pim.c
@@ -2,7 +2,7 @@
* Routines for PIM disassembly
* (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
*
- * $Id: packet-pim.c,v 1.7 1999/11/16 11:42:46 guy Exp $
+ * $Id: packet-pim.c,v 1.8 2000/01/15 04:17:35 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -248,11 +248,11 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
guint16 *w;
w = (guint16 *)&pd[offset + sizeof(struct pim)];
while ((guint8 *)w < &pd[offset + END_OF_FRAME]) {
- if (ntohs(w[0]) == 1 && ntohs(w[1]) == 2
+ if (pntohs(&w[0]) == 1 && pntohs(&w[1]) == 2
&& (guint8 *)&w[3] <= &pd[offset + END_OF_FRAME]) {
proto_tree_add_text(pimopt_tree, (guint8 *)w - pd, 6,
- "Holdtime: %u%s", ntohs(w[2]),
- ntohs(w[2]) == 0xffff ? " (infty)" : "");
+ "Holdtime: %u%s", pntohs(&w[2]),
+ pntohs(&w[2]) == 0xffff ? " (infty)" : "");
w += 3;
} else
break;
@@ -269,7 +269,7 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
flagoff = offset + sizeof(struct pim);
tiflag = proto_tree_add_text(pimopt_tree, flagoff, 4,
- "Flags: 0x%08x", ntohl(*(guint32 *)&pd[flagoff]));
+ "Flags: 0x%08x", pntohl(&pd[flagoff]));
flag_tree = proto_item_add_subtree(tiflag, ett_pim);
proto_tree_add_text(flag_tree, flagoff, 1, "%s",
decode_boolean_bitfield(pd[flagoff], 0x80000000, 32,
@@ -361,8 +361,8 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
if (PIM_TYPE(pim.pim_typever) != 7) {
/* not graft-ack */
proto_tree_add_text(pimopt_tree, offset, 2,
- "Holdtime: %u%s", ntohs(*(guint16 *)&pd[offset]),
- ntohs(*(guint16 *)&pd[offset]) == 0xffff ? " (infty)" : "");
+ "Holdtime: %u%s", pntohs(&pd[offset]),
+ pntohs(&pd[offset]) == 0xffff ? " (infty)" : "");
}
offset += 2;
@@ -380,8 +380,8 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
if (&pd[offset + 4] > ep)
goto breakbreak3;
- njoin = ntohs(*(guint16 *)&pd[offset]);
- nprune = ntohs(*(guint16 *)&pd[offset + 2]);
+ njoin = pntohs(&pd[offset]);
+ nprune = pntohs(&pd[offset + 2]);
tisub = proto_tree_add_text(grouptree, offset, 2,
"Join: %d", njoin);
@@ -428,7 +428,7 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
if (END_OF_FRAME < 2)
break;
proto_tree_add_text(pimopt_tree, offset, 2,
- "Fragment tag: 0x%04x", ntohs(*(guint16 *)&pd[offset]));
+ "Fragment tag: 0x%04x", pntohs(&pd[offset]));
offset += 2;
if (END_OF_FRAME < 2)
@@ -477,8 +477,8 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
if (END_OF_FRAME < 4)
goto breakbreak4;
proto_tree_add_text(grouptree, offset, 2,
- "Holdtime: %u%s", ntohs(*(guint16 *)&pd[offset]),
- ntohs(*(guint16 *)&pd[offset]) == 0xffff ? " (infty)" : "");
+ "Holdtime: %u%s", pntohs(&pd[offset]),
+ pntohs(&pd[offset]) == 0xffff ? " (infty)" : "");
proto_tree_add_text(grouptree, offset + 3, 1,
"Priority: %u", pd[offset + 3]);
@@ -517,13 +517,13 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
decode_boolean_bitfield(pd[offset], 0x80, 8,
"RP Tree", "Not RP Tree"));
proto_tree_add_text(pimopt_tree, offset, 4, "Preference: %u",
- ntohl(*(guint32 *)&pd[offset] & 0x7fffffff));
+ pntohl(&pd[offset]) & 0x7fffffff);
offset += 4;
if (END_OF_FRAME < 4)
break;
proto_tree_add_text(pimopt_tree, offset, 4, "Metric: %u",
- ntohl(*(guint32 *)&pd[offset]));
+ pntohl(&pd[offset]));
break;
}
@@ -544,8 +544,8 @@ dissect_pim(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
proto_tree_add_text(pimopt_tree, offset + 1, 1,
"Priority: %u", pd[offset + 1]);
proto_tree_add_text(pimopt_tree, offset + 2, 2,
- "Holdtime: %u%s", ntohs(*(guint16 *)&pd[offset + 2]),
- ntohs(*(guint16 *)&pd[offset + 2]) == 0xffff ? " (infty)" : "");
+ "Holdtime: %u%s", pntohs(&pd[offset + 2]),
+ pntohs(&pd[offset + 2]) == 0xffff ? " (infty)" : "");
offset += 4;
if (END_OF_FRAME <= 0)