Fix some "proto_tree_add_text()" calls.
[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.2 2000/03/06 20:04:53 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 void
43 dissect_time(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
44 {
45   proto_tree    *time_tree;
46   proto_item    *ti;
47   
48   if (check_col(fd, COL_PROTOCOL))
49     col_add_str(fd, COL_PROTOCOL, "TIME");
50   
51   if (check_col(fd, COL_INFO)) {
52     col_add_fstr(fd, COL_INFO, "TIME %s", pi.srcport == 37? "Response":"Request");
53   }
54   
55   if (tree) {
56     
57     ti = proto_tree_add_item(tree, proto_time, offset, END_OF_FRAME, NULL);
58     time_tree = proto_item_add_subtree(ti, ett_time);
59     
60     proto_tree_add_text(time_tree, offset, 0,
61                         pi.srcport==37? "Type: Response":"Type: Request");
62     if (pi.srcport == 37) { 
63       guint32 delta_seconds = pntohl(pd+offset);
64       proto_tree_add_text(time_tree, offset, 4,
65                           " %u seconds since midnight 1 January 1900 GMT",
66                           delta_seconds);
67     }
68   }
69 }
70
71 void
72 proto_register_time(void)
73 {
74
75   static hf_register_info hf[] = {
76     { &hf_time_time,
77       { "Time", "time",
78         FT_UINT32, BASE_DEC, NULL, 0x0,
79         "Seconds since 00:00 (midnight) 1 January 1900 GMT" }}
80   };
81   static gint *ett[] = {
82     &ett_time,
83   };
84
85   proto_time = proto_register_protocol("Time Protocol", "time");
86   proto_register_field_array(proto_time, hf, array_length(hf));
87   proto_register_subtree_array(ett, array_length(ett));
88 }