summaryrefslogtreecommitdiff
path: root/packet-ip.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1999-12-09 21:58:04 +0000
committerGuy Harris <guy@alum.mit.edu>1999-12-09 21:58:04 +0000
commit537cbc8d42b2847e1027904de4581503d5acf1fb (patch)
tree5d2227452c5c0134b3413e139c7fc422edf615e4 /packet-ip.c
parent7ce8202f0031754df9aa224e68ab0e5eea47464b (diff)
downloadwireshark-537cbc8d42b2847e1027904de4581503d5acf1fb.tar.gz
Thou Shalt Not Cast Pointers Into A Packet To Pointers To Anything
Bigger Than A Byte, as there's no guarantee that the pointer is aligned the way you'd like (consider, for example, FDDI packets, which may be aligned on an *odd-byte* boundary). svn path=/trunk/; revision=1268
Diffstat (limited to 'packet-ip.c')
-rw-r--r--packet-ip.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/packet-ip.c b/packet-ip.c
index 38642a9fc6..88916bf8d3 100644
--- a/packet-ip.c
+++ b/packet-ip.c
@@ -1,7 +1,7 @@
/* packet-ip.c
* Routines for IP and miscellaneous IP protocol packet disassembly
*
- * $Id: packet-ip.c,v 1.65 1999/12/08 17:54:41 gram Exp $
+ * $Id: packet-ip.c,v 1.66 1999/12/09 21:58:04 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -752,12 +752,14 @@ static const true_false_string flags_set_truth = {
static char *ip_checksum_state(e_ip *iph)
{
unsigned long Sum;
- unsigned short *Ptr, *PtrEnd;
+ unsigned char *Ptr, *PtrEnd;
+ unsigned short word;
Sum = 0;
- PtrEnd = (unsigned short *) (lo_nibble(iph->ip_v_hl) * 4 + (char *)iph);
- for (Ptr = (unsigned short *) iph; Ptr < PtrEnd; Ptr++) {
- Sum += *Ptr;
+ PtrEnd = (lo_nibble(iph->ip_v_hl) * 4 + (char *)iph);
+ for (Ptr = (unsigned char *) iph; Ptr < PtrEnd; Ptr += 2) {
+ memcpy(&word, Ptr, sizeof word);
+ Sum += word;
}
Sum = (Sum & 0xFFFF) + (Sum >> 16);