Don't assume the UDP header is always properly aligned (sometimes it
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 14 Oct 1998 08:47:16 +0000 (08:47 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 14 Oct 1998 08:47:16 +0000 (08:47 +0000)
isn't).

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@54 f5534014-38df-0310-8fa8-9805f1628bb7

packet-udp.c

index 40ae0e4d5689048a489b79cb4a0603de4312c046..cec5c5b9ee0dab9b4630e515dd39ebab4cd21d78 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-udp.c
  * Routines for UDP packet disassembly
  *
- * $Id: packet-udp.c,v 1.5 1998/10/14 04:09:13 gram Exp $
+ * $Id: packet-udp.c,v 1.6 1998/10/14 08:47:16 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 
 void
 dissect_udp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
-  e_udphdr  *uh;
+  e_udphdr  uh;
   guint16    uh_sport, uh_dport, uh_ulen, uh_sum;
   GtkWidget *udp_tree, *ti;
 
   /* To do: Check for {cap len,pkt len} < struct len */
-  uh = (e_udphdr *) &pd[offset];
-  uh_sport = ntohs(uh->uh_sport);
-  uh_dport = ntohs(uh->uh_dport);
-  uh_ulen  = ntohs(uh->uh_ulen);
-  uh_sum   = ntohs(uh->uh_sum);
+  /* Avoids alignment problems on many architectures. */
+  memcpy(&uh, &pd[offset], sizeof(e_udphdr));
+  uh_sport = ntohs(uh.uh_sport);
+  uh_dport = ntohs(uh.uh_dport);
+  uh_ulen  = ntohs(uh.uh_ulen);
+  uh_sum   = ntohs(uh.uh_sum);
   
   if (fd->win_info[COL_NUM]) {
     strcpy(fd->win_info[COL_PROTOCOL], "UDP");