When dissecting the reference clock ID field:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 6 Dec 1999 03:18:24 +0000 (03:18 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 6 Dec 1999 03:18:24 +0000 (03:18 +0000)
if it's stratum 0 or 1, use "memcmp()" to compare it against the
strings in our table, rather than assuming it's aligned on a
4-byte boundary and doing an integral comparison - neither of
the strings being compared are necessarily so aligned - and, if
it doesn't match any of them, include the value in the
"Unidentified reference source" description;

if it's stratum 2 or higher, extract the value with "pntohl()"
before interpreting it as an IP address - IP addresses are in
network byte order, and, again, it's not necessarily neatly
aligned on a 4-byte boundary.

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

packet-ntp.c

index b511fdbce035b008288cbb314f69e99ba18af9dc..e1aa4cdfebf4d04886b279a69da5219490146818 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for NTP packet dissection
  * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
  *
- * $Id: packet-ntp.c,v 1.5 1999/11/16 11:42:43 guy Exp $
+ * $Id: packet-ntp.c,v 1.6 1999/12/06 03:18:24 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@unicom.net>
@@ -320,11 +320,18 @@ dissect_ntp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
                 * level server. My decision was to resolve this address.
                 */
                if (*pkt->stratum <= 1) {
-                       strcpy (buff, "unindentified reference source"); 
-                       for (i = 0; primary_sources[i].id; i++)
-                               if (*((guint32 *) pkt->refid) == *((guint32 *) primary_sources[i].id))
-                                       strcpy (buff, primary_sources[i].data); 
-               } else strcpy (buff, get_hostname (*((u_int *) pkt->refid)));
+                       snprintf (buff, sizeof buff,
+                           "Unindentified reference source '%.4s'",
+                           pkt->refid); 
+                       for (i = 0; primary_sources[i].id; i++) {
+                               if (memcmp (pkt->refid, primary_sources[i].id,
+                                   4) == 0) {
+                                       strcpy (buff, primary_sources[i].data);
+                                       break;
+                               }
+                       }
+               } else
+                       strcpy (buff, get_hostname (pntohl(pkt->refid)));
                proto_tree_add_item_format(ntp_tree, hf_ntp_refid, offset+12, 4, pkt->refid,
                                           "Reference Clock ID: %s", buff);
                /* Reference Timestamp: This is the time at which the local clock was