From Kovarththanan Rajaratnam via bug 3548:
[obnox/wireshark/wip.git] / plugins / docsis / packet-sync.c
1 /* packet-sync.c
2  * $Id$
3  * Routines for Sync Message dissection
4  * Copyright 2007, Bruno Verstuyft  <bruno.verstuyft@excentis.com>
5  *
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include <epan/packet.h>
35
36
37 /* Initialize the protocol and registered fields */
38 static int proto_docsis_sync = -1;
39 static int hf_docsis_sync = -1;
40 static int hf_docsis_sync_cmts_timestamp = -1;
41
42
43 /* Initialize the subtree pointers */
44 static gint ett_docsis_sync = -1;
45
46 static void
47 dissect_sync (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
48 {
49         proto_item *it;
50         proto_tree *sync_tree;
51
52         if (check_col (pinfo->cinfo, COL_INFO))
53         {
54         col_clear (pinfo->cinfo, COL_INFO);
55         col_add_fstr (pinfo->cinfo, COL_INFO,
56                         "Sync Message:");
57         }
58
59         if (tree)
60         {
61         it = proto_tree_add_protocol_format (tree, proto_docsis_sync, tvb, 0, -1,"SYNC Message");
62         sync_tree = proto_item_add_subtree (it, ett_docsis_sync);
63
64         proto_tree_add_item (sync_tree, hf_docsis_sync_cmts_timestamp, tvb, 0, 4,
65                         FALSE);
66         }                               /* if(tree) */
67 }
68
69
70
71
72 /* Register the protocol with Wireshark */
73
74 /* this format is require because a script is used to build the C function
75    that calls all the protocol registration.
76 */
77
78
79 void
80 proto_register_docsis_sync (void)
81 {
82         /* Setup list of header fields  See Section 1.6.1 for details*/
83         static hf_register_info hf[] = {
84                 {&hf_docsis_sync,
85                 {"SYNC Message", "docsis_sync",
86                 FT_BYTES, BASE_NONE, NULL, 0x0,
87                 NULL, HFILL}
88                 },
89                 {&hf_docsis_sync_cmts_timestamp,
90                 {"CMTS Timestamp", "docsis_sync.cmts_timestamp",
91                 FT_UINT32, BASE_DEC, NULL, 0x0,
92                 "Sync CMTS Timestamp", HFILL}
93                 },
94         };
95
96         /* Setup protocol subtree array */
97         static gint *ett[] = {
98                 &ett_docsis_sync,
99         };
100
101         /* Register the protocol name and description */
102         proto_docsis_sync =
103                 proto_register_protocol ("DOCSIS Synchronisation Message",
104                                         "DOCSIS Sync", "docsis_sync");
105
106         /* Required function calls to register the header fields and subtrees used */
107         proto_register_field_array (proto_docsis_sync, hf, array_length (hf));
108         proto_register_subtree_array (ett, array_length (ett));
109
110         register_dissector ("docsis_sync", dissect_sync, proto_docsis_sync);
111 }
112
113
114 /* If this dissector uses sub-dissector registration add a registration routine.
115    This format is required because a script is used to find these routines and
116    create the code that calls these routines.
117 */
118 void
119 proto_reg_handoff_docsis_sync (void)
120 {
121         dissector_handle_t docsis_sync_handle;
122
123         docsis_sync_handle = find_dissector ("docsis_sync");
124         dissector_add ("docsis_mgmt", 1, docsis_sync_handle);
125 }