Add a new "prefs_register_protocol()" routine, which is like
[obnox/wireshark/wip.git] / packet-time.c
1 /* packet-time.c
2  * Routines for time packet dissection
3  *
4  * Richard Sharpe <rsharpe@ns.aus.com>
5  * Craig Newell <CraigN@cheque.uq.edu.au>
6  *      RFC2347 TIME Option Extension
7  *
8  * $Id: packet-time.c,v 1.10 2001/01/03 06:55:34 guy Exp $
9  *
10  * Ethereal - Network traffic analyzer
11  * By Gerald Combs <gerald@zing.org>
12  * Copyright 1998 Gerald Combs
13  *
14  * Copied from packet-tftp.c
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  * 
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
29  */
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include "packet.h"
36
37 static int proto_time = -1;
38 static int hf_time_time = -1;
39
40 static gint ett_time = -1;
41
42 #define UDP_PORT_TIME    37
43
44 static void
45 dissect_time(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
46 {
47   proto_tree    *time_tree;
48   proto_item    *ti;
49
50   OLD_CHECK_DISPLAY_AS_DATA(proto_time, pd, offset, fd, tree);
51   
52   if (check_col(fd, COL_PROTOCOL))
53     col_set_str(fd, COL_PROTOCOL, "TIME");
54   
55   if (check_col(fd, COL_INFO)) {
56     col_add_fstr(fd, COL_INFO, "TIME %s", pi.srcport == UDP_PORT_TIME? "Response":"Request");
57   }
58   
59   if (tree) {
60     
61     ti = proto_tree_add_item(tree, proto_time, NullTVB, offset, END_OF_FRAME, FALSE);
62     time_tree = proto_item_add_subtree(ti, ett_time);
63     
64     proto_tree_add_text(time_tree, NullTVB, offset, 0,
65                         pi.srcport==37? "Type: Response":"Type: Request");
66     if (pi.srcport == 37) { 
67       guint32 delta_seconds = pntohl(pd+offset);
68       proto_tree_add_text(time_tree, NullTVB, offset, 4,
69                           " %u seconds since midnight 1 January 1900 GMT",
70                           delta_seconds);
71     }
72   }
73 }
74
75 void
76 proto_register_time(void)
77 {
78
79   static hf_register_info hf[] = {
80     { &hf_time_time,
81       { "Time", "time.time",
82         FT_UINT32, BASE_DEC, NULL, 0x0,
83         "Seconds since 00:00 (midnight) 1 January 1900 GMT" }}
84   };
85   static gint *ett[] = {
86     &ett_time,
87   };
88
89   proto_time = proto_register_protocol("Time Protocol", "TIME", "time");
90   proto_register_field_array(proto_time, hf, array_length(hf));
91   proto_register_subtree_array(ett, array_length(ett));
92 }
93
94 void
95 proto_reg_handoff_time(void)
96 {
97   old_dissector_add("udp.port", UDP_PORT_TIME, dissect_time);
98 }