Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-ntp.c
index 388d69266c60c24b13499adf99df1ca1402ccdfd..4ca885e1f26efcbdaee59b618c140a83a1b438da 100644 (file)
@@ -2,10 +2,10 @@
  * Routines for NTP packet dissection
  * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
  *
- * $Id: packet-ntp.c,v 1.27 2001/04/09 21:42:01 guy Exp $
+ * $Id: packet-ntp.c,v 1.36 2002/08/02 23:35:55 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
  * Copied from packet-tftp.c
 
 #include <stdio.h>
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-
 #include <string.h>
 #include <time.h>
 #include <math.h>
@@ -48,8 +40,8 @@
 # include "snprintf.h"
 #endif
 
-#include "packet.h"
-#include "resolv.h"
+#include <epan/packet.h>
+#include <epan/resolv.h>
 #include "packet-ntp.h"
 
 /*
@@ -236,10 +228,14 @@ ntp_fmt_ts(const guint8 *reftime, char* buff)
        } else {
                temptime = tempstmp - (guint32) NTP_BASETIME;
                bd = gmtime(&temptime);
-               fractime = bd->tm_sec + tempfrac / 4294967296.0;
-               snprintf(buff, NTP_TS_SIZE, "%04d-%02d-%02d %02d:%02d:%07.4f UTC",
-                        bd->tm_year + 1900, bd->tm_mon + 1, bd->tm_mday,
-                        bd->tm_hour, bd->tm_min, fractime);
+               if (bd != NULL) {
+                       fractime = bd->tm_sec + tempfrac / 4294967296.0;
+                       snprintf(buff, NTP_TS_SIZE,
+                                "%04d-%02d-%02d %02d:%02d:%07.4f UTC",
+                                bd->tm_year + 1900, bd->tm_mon + 1, bd->tm_mday,
+                                bd->tm_hour, bd->tm_min, fractime);
+               } else
+                       strncpy(buff, "Not representable", NTP_TS_SIZE);
        }
        return buff;
 }
@@ -261,6 +257,7 @@ dissect_ntp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        double          rootdelay;
        double          rootdispersion;
        const guint8    *refid;
+       guint32         refid_addr;
        const guint8    *reftime;
        const guint8    *org;
        const guint8    *rec;
@@ -268,16 +265,15 @@ dissect_ntp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        gchar           buff[NTP_TS_SIZE];
        int             i;
 
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_set_str(pinfo->fd, COL_PROTOCOL, "NTP");
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "NTP");
 
-       if (check_col(pinfo->fd, COL_INFO))
-               col_set_str(pinfo->fd, COL_INFO, "NTP");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_set_str(pinfo->cinfo, COL_INFO, "NTP");
 
        if (tree) {
                /* Adding NTP item and subtree */
-               ti = proto_tree_add_item(tree, proto_ntp, tvb, 0,
-                   tvb_length(tvb), FALSE);
+               ti = proto_tree_add_item(tree, proto_ntp, tvb, 0, -1, FALSE);
                ntp_tree = proto_item_add_subtree(ti, ett_ntp);
 
                flags = tvb_get_guint8(tvb, 0);
@@ -372,7 +368,8 @@ dissect_ntp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        }
                } else {
                        buff[sizeof(buff) - 1] = '\0';
-                       strncpy (buff, get_hostname (htonl(tvb_get_ntohl(tvb, 12))),
+                       tvb_memcpy(tvb, (guint8 *)&refid_addr, 12, 4);
+                       strncpy (buff, get_hostname (refid_addr),
                            sizeof(buff));
                        if (buff[sizeof(buff) - 1] != '\0')
                                strcpy(&buff[sizeof(buff) - 4], "...");
@@ -437,52 +434,52 @@ proto_register_ntp(void)
        static hf_register_info hf[] = {
                { &hf_ntp_flags, {      
                        "Flags", "ntp.flags", FT_UINT8, BASE_HEX, 
-                       NULL, 0, "Flags (Leap/Version/Mode)" }},
+                       NULL, 0, "Flags (Leap/Version/Mode)", HFILL }},
                { &hf_ntp_flags_li, {
                        "Leap Indicator", "ntp.flags.li", FT_UINT8, BASE_DEC,
-                       VALS(li_types), NTP_LI_MASK, "Leap Indicator" }},
+                       VALS(li_types), NTP_LI_MASK, "Leap Indicator", HFILL }},
                { &hf_ntp_flags_vn, {
                        "Version number", "ntp.flags.vn", FT_UINT8, BASE_DEC,
-                       VALS(ver_nums), NTP_VN_MASK, "Version number" }},
+                       VALS(ver_nums), NTP_VN_MASK, "Version number", HFILL }},
                { &hf_ntp_flags_mode, {
                        "Mode", "ntp.flags.mode", FT_UINT8, BASE_DEC,
-                       VALS(mode_types), NTP_MODE_MASK, "Mode" }},
+                       VALS(mode_types), NTP_MODE_MASK, "Mode", HFILL }},
                { &hf_ntp_stratum, {    
                        "Peer Clock Stratum", "ntp.stratum", FT_UINT8, BASE_DEC,
-                       NULL, 0, "Peer Clock Stratum" }},
+                       NULL, 0, "Peer Clock Stratum", HFILL }},
                { &hf_ntp_ppoll, {      
                        "Peer Polling Interval", "ntp.ppoll", FT_UINT8, BASE_DEC, 
-                       NULL, 0, "Peer Polling Interval" }},
+                       NULL, 0, "Peer Polling Interval", HFILL }},
                { &hf_ntp_precision, {  
                        "Peer Clock Precision", "ntp.precision", FT_UINT8, BASE_DEC, 
-                       NULL, 0, "Peer Clock Precision" }},
+                       NULL, 0, "Peer Clock Precision", HFILL }},
                { &hf_ntp_rootdelay, {  
                        "Root Delay", "ntp.rootdelay", FT_DOUBLE, BASE_DEC,
-                       NULL, 0, "Root Delay" }},
+                       NULL, 0, "Root Delay", HFILL }},
                { &hf_ntp_rootdispersion, {     
                        "Clock Dispersion", "ntp.rootdispersion", FT_DOUBLE, BASE_DEC, 
-                       NULL, 0, "Clock Dispersion" }},
+                       NULL, 0, "Clock Dispersion", HFILL }},
                { &hf_ntp_refid, {      
                        "Reference Clock ID", "ntp.refid", FT_BYTES, BASE_NONE, 
-                       NULL, 0, "Reference Clock ID" }},
+                       NULL, 0, "Reference Clock ID", HFILL }},
                { &hf_ntp_reftime, {    
                        "Reference Clock Update Time", "ntp.reftime", FT_BYTES, BASE_NONE, 
-                       NULL, 0, "Reference Clock Update Time" }},
+                       NULL, 0, "Reference Clock Update Time", HFILL }},
                { &hf_ntp_org, {        
                        "Originate Time Stamp", "ntp.org", FT_BYTES, BASE_NONE, 
-                       NULL, 0, "Originate Time Stamp" }},
+                       NULL, 0, "Originate Time Stamp", HFILL }},
                { &hf_ntp_rec, {        
                        "Receive Time Stamp", "ntp.rec", FT_BYTES, BASE_NONE, 
-                       NULL, 0, "Receive Time Stamp" }},
+                       NULL, 0, "Receive Time Stamp", HFILL }},
                { &hf_ntp_xmt, {        
                        "Transmit Time Stamp", "ntp.xmt", FT_BYTES, BASE_NONE, 
-                       NULL, 0, "Transmit Time Stamp" }},
+                       NULL, 0, "Transmit Time Stamp", HFILL }},
                { &hf_ntp_keyid, {      
                        "Key ID", "ntp.keyid", FT_BYTES, BASE_HEX, 
-                       NULL, 0, "Key ID" }},
+                       NULL, 0, "Key ID", HFILL }},
                { &hf_ntp_mac, {        
                        "Message Authentication Code", "ntp.mac", FT_BYTES, BASE_HEX, 
-                       NULL, 0, "Message Authentication Code" }},
+                       NULL, 0, "Message Authentication Code", HFILL }},
         };
        static gint *ett[] = {
                &ett_ntp,
@@ -498,6 +495,9 @@ proto_register_ntp(void)
 void
 proto_reg_handoff_ntp(void)
 {
-       dissector_add("udp.port", UDP_PORT_NTP, dissect_ntp, proto_ntp);
-       dissector_add("tcp.port", TCP_PORT_NTP, dissect_ntp, proto_ntp);
+       dissector_handle_t ntp_handle;
+
+       ntp_handle = create_dissector_handle(dissect_ntp, proto_ntp);
+       dissector_add("udp.port", UDP_PORT_NTP, ntp_handle);
+       dissector_add("tcp.port", TCP_PORT_NTP, ntp_handle);
 }