various string related changes, mainly replace sprintf/snprintf by g_snprintf
[obnox/wireshark/wip.git] / packet-wfleet-hdlc.c
1 /* packet-chdlc.c
2  * Routines for Wellfleet HDLC packet disassembly
3  * Copied from the Cisco HDLC packet disassembly routines
4  *
5  * $Id: packet-wfleet-hdlc.c,v 1.1 2002/12/20 07:56:07 sharpe Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
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 <glib.h>
31 #include <epan/packet.h>
32 #include "etypes.h"
33 #include <epan/resolv.h>
34 #include "packet-chdlc.h"
35 #include "packet-ip.h"
36
37 static int proto_wfleet_hdlc = -1;
38 static int hf_wfleet_hdlc_addr = -1;
39 static int hf_wfleet_hdlc_cmd = -1;
40
41 static gint ett_wfleet_hdlc = -1;
42
43 dissector_handle_t eth_handle;
44
45 static const value_string wfleet_hdlc_cmd_vals[] = {
46   { 0x03, "Un-numbered I frame"},
47   { 0,    NULL}
48 };
49
50 static void
51 dissect_wfleet_hdlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
52 {
53   proto_item *ti;
54   proto_tree *fh_tree = NULL;
55   tvbuff_t   *next_tvb;
56   guint8     addr;
57   guint8     cmd;
58
59   if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
60     col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A");
61   if (check_col(pinfo->cinfo, COL_RES_DL_DST))
62     col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A");
63   if (check_col(pinfo->cinfo, COL_PROTOCOL))
64     col_set_str(pinfo->cinfo, COL_PROTOCOL, "WHDLC");
65   if (check_col(pinfo->cinfo, COL_INFO))
66     col_clear(pinfo->cinfo, COL_INFO);
67
68   addr = tvb_get_guint8(tvb, 0);
69   cmd = tvb_get_guint8(tvb, 1);
70
71   if (tree) {
72     ti = proto_tree_add_item(tree, proto_wfleet_hdlc, tvb, 0, 2, FALSE);
73     fh_tree = proto_item_add_subtree(ti, ett_wfleet_hdlc);
74
75     proto_tree_add_uint(fh_tree, hf_wfleet_hdlc_addr, tvb, 0, 1, addr);
76     proto_tree_add_uint(fh_tree, hf_wfleet_hdlc_cmd, tvb, 1, 1, cmd);
77
78   }
79
80   /*
81    * Build a tvb of the piece past the first two bytes and call the 
82    * ethernet dissector
83    */
84
85   next_tvb = tvb_new_subset(tvb, 2, -1, -1);
86
87   call_dissector(eth_handle, next_tvb, pinfo, tree);
88
89 }
90
91 void
92 proto_register_wfleet_hdlc(void)
93 {
94   static hf_register_info hf[] = {
95     { &hf_wfleet_hdlc_addr,
96       { "Address", "wfleet_hdlc.address", FT_UINT8, BASE_HEX,
97         NULL, 0x0, "", HFILL }},
98     { &hf_wfleet_hdlc_cmd,
99       { "Command", "wfleet_hdlc.command", FT_UINT8, BASE_HEX,
100         VALS(wfleet_hdlc_cmd_vals), 0x0, "", HFILL }},
101   };
102   static gint *ett[] = {
103     &ett_wfleet_hdlc,
104   };
105
106   proto_wfleet_hdlc = proto_register_protocol("Wellfleet HDLC", "WHDLC", "whdlc");
107   proto_register_field_array(proto_wfleet_hdlc, hf, array_length(hf));
108   proto_register_subtree_array(ett, array_length(ett));
109
110   register_dissector("wfleet_hdlc", dissect_wfleet_hdlc, proto_wfleet_hdlc);
111
112 }
113
114 void
115 proto_reg_handoff_wfleet_hdlc(void)
116 {
117   dissector_handle_t wfleet_hdlc_handle;
118
119   wfleet_hdlc_handle = find_dissector("wfleet_hdlc");
120   dissector_add("wtap_encap", WTAP_ENCAP_WFLEET_HDLC, wfleet_hdlc_handle);
121
122   /* 
123    * Find the eth dissector and save a ref to it
124    */
125
126   eth_handle = find_dissector("eth");
127 }