2 * Routines for NTP packet dissection
3 * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
5 * $Id: packet-ntp.c,v 1.1 1999/10/14 05:10:30 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@unicom.net>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-tftp.c
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
45 #include "packet-ntp.h"
47 static int proto_ntp = -1;
48 static int hf_ntp_flags = -1;
49 static int hf_ntp_stratum = -1;
50 static int hf_ntp_ppoll = -1;
51 static int hf_ntp_precision = -1;
52 static int hf_ntp_rootdelay = -1;
53 static int hf_ntp_rootdispersion = -1;
54 static int hf_ntp_refid = -1;
55 static int hf_ntp_reftime = -1;
56 static int hf_ntp_org = -1;
57 static int hf_ntp_rec = -1;
58 static int hf_ntp_xmt = -1;
59 static int hf_ntp_keyid = -1;
60 static int hf_ntp_mac = -1;
63 dissect_ntp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
65 proto_tree *ntp_tree, *ti;
66 struct ntp_packet *pkt;
68 /* get at least a full packet structure */
69 if ( !BYTES_ARE_IN_FRAME(offset, 48) ) /* 48 without keyid or mac */
72 pkt = (struct ntp_packet *) &pd[offset];
74 if (check_col(fd, COL_PROTOCOL))
75 col_add_str(fd, COL_PROTOCOL, "NTP");
77 if (check_col(fd, COL_INFO))
78 col_add_str(fd, COL_INFO, "NTP");
81 ti = proto_tree_add_item(tree, proto_ntp, offset, END_OF_FRAME, NULL);
82 ntp_tree = proto_item_add_subtree(ti, ETT_NTP);
84 proto_tree_add_item(ntp_tree, hf_ntp_flags, offset, 1, pkt->flags);
85 proto_tree_add_item(ntp_tree, hf_ntp_stratum, offset+1, 1, pkt->stratum);
86 proto_tree_add_item(ntp_tree, hf_ntp_ppoll, offset+2, 1, pkt->ppoll);
87 proto_tree_add_item(ntp_tree, hf_ntp_precision, offset+3, 1, pkt->precision);
88 proto_tree_add_item(ntp_tree, hf_ntp_rootdelay, offset+4, 4, pkt->rootdelay);
89 proto_tree_add_item(ntp_tree, hf_ntp_rootdispersion, offset+8, 4, pkt->rootdispersion);
90 proto_tree_add_item(ntp_tree, hf_ntp_refid, offset+12, 4, pkt->refid);
91 proto_tree_add_item(ntp_tree, hf_ntp_reftime, offset+16, 8, pkt->reftime);
92 proto_tree_add_item(ntp_tree, hf_ntp_org, offset+24, 8, pkt->org);
93 proto_tree_add_item(ntp_tree, hf_ntp_rec, offset+32, 8, pkt->rec);
94 proto_tree_add_item(ntp_tree, hf_ntp_xmt, offset+40, 8, pkt->xmt);
96 if ( BYTES_ARE_IN_FRAME(offset, 50) )
97 proto_tree_add_item(ntp_tree, hf_ntp_keyid, offset+48, 4, pkt->keyid);
98 if ( BYTES_ARE_IN_FRAME(offset, 53) )
99 proto_tree_add_item(ntp_tree, hf_ntp_mac, offset+52, END_OF_FRAME, pkt->mac);
104 proto_register_ntp(void)
106 static hf_register_info hf[] = {
108 "Flags", "ntp.flags", FT_BYTES, BASE_HEX,
109 NULL, 0, "Flags (Leap/Version/Mode)" }},
111 "Peer Clock Stratum", "ntp.stratum", FT_BYTES, BASE_HEX,
112 NULL, 0, "Peer Clock Stratum" }},
114 "Peer Polling Interval", "ntp.ppoll", FT_BYTES, BASE_HEX,
115 NULL, 0, "Peer Polling Interval" }},
116 { &hf_ntp_precision, {
117 "Peer Clock Precision", "ntp.precision", FT_BYTES, BASE_HEX,
118 NULL, 0, "Peer Clock Precision" }},
119 { &hf_ntp_rootdelay, {
120 "Distance to Primary", "ntp.rootdelay", FT_BYTES, BASE_HEX,
121 NULL, 0, "Distance to Primary" }},
122 { &hf_ntp_rootdispersion, {
123 "Clock Dispersion", "ntp.rootdispersion", FT_BYTES, BASE_HEX,
124 NULL, 0, "Clock Dispersion" }},
126 "Reference Clock ID", "ntp.refid", FT_BYTES, BASE_HEX,
127 NULL, 0, "Reference Clock ID" }},
129 "Reference Clock Update Time", "ntp.reftime", FT_BYTES, BASE_HEX,
130 NULL, 0, "Reference Clock Update Time" }},
132 "Originate Time Stamp", "ntp.org", FT_BYTES, BASE_HEX,
133 NULL, 0, "Originate Time Stamp" }},
135 "Receive Time Stamp", "ntp.rec", FT_BYTES, BASE_HEX,
136 NULL, 0, "Receive Time Stamp" }},
138 "Transmit Time Stamp", "ntp.xmt", FT_BYTES, BASE_HEX,
139 NULL, 0, "Transmit Time Stamp" }},
141 "Key ID", "ntp.keyid", FT_BYTES, BASE_HEX,
142 NULL, 0, "Key ID" }},
144 "Message Authentication Code", "ntp.mac", FT_BYTES, BASE_HEX,
145 NULL, 0, "Message Authentication Code" }},
148 proto_ntp = proto_register_protocol("Network Time Protocol", "ntp");
149 proto_register_field_array(proto_ntp, hf, array_length(hf));