HTTPS (almost) everywhere.
[metze/wireshark/wip.git] / epan / dissectors / packet-chargen.c
1 /* packet-chargen.c
2  * Routines for chargen packet dissection
3  * Copyright 2014, Dario Lombardo <lomato@gmail.com>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * Chargen specs taken from RFC 864
10  * http://tools.ietf.org/html/rfc864
11  *
12  * SPDX-License-Identifier: GPL-2.0-or-later
13  */
14
15 #include "config.h"
16
17 #include <epan/packet.h>
18 #define CHARGEN_PORT_UDP 19
19 #define CHARGEN_PORT_TCP 19
20
21 void proto_register_chargen(void);
22 void proto_reg_handoff_chargen(void);
23
24 static int proto_chargen = -1;
25
26 static int hf_chargen_data = -1;
27
28 static gint ett_chargen = -1;
29
30 /* dissect_chargen - dissects chargen packet data
31  * tvb - tvbuff for packet data (IN)
32  * pinfo - packet info
33  * proto_tree - resolved protocol tree
34  */
35 static int
36 dissect_chargen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* dissector_data _U_)
37 {
38         proto_tree* chargen_tree;
39         proto_item* ti;
40         guint8* data;
41         guint32 len;
42
43         col_set_str(pinfo->cinfo, COL_PROTOCOL, "Chargen");
44         col_set_str(pinfo->cinfo, COL_INFO, "Chargen");
45
46         ti = proto_tree_add_item(tree, proto_chargen, tvb, 0, -1, ENC_NA);
47         chargen_tree = proto_item_add_subtree(ti, ett_chargen);
48
49         len = tvb_reported_length(tvb);
50         data = tvb_get_string_enc(wmem_packet_scope(), tvb, 0, len, ENC_ASCII);
51
52         proto_tree_add_string_format(chargen_tree, hf_chargen_data, tvb, 0,
53                 len, "Data", "Data (%u): %s", len, data);
54
55 /*      proto_tree_add_item(chargen_tree, hf_chargen_data, tvb, 0, -1, ENC_ASCII|ENC_NA); */
56         return tvb_captured_length(tvb);
57 }
58
59 void
60 proto_register_chargen(void)
61 {
62         static hf_register_info hf[] = {
63                 { &hf_chargen_data, {
64                         "Data", "chargen.data", FT_STRING, BASE_NONE,
65                         NULL, 0, NULL, HFILL }}
66                 };
67
68         static gint *ett[] = {
69                 &ett_chargen,
70         };
71
72         proto_chargen = proto_register_protocol("Character Generator Protocol", "Chargen",
73             "chargen");
74         proto_register_field_array(proto_chargen, hf, array_length(hf));
75         proto_register_subtree_array(ett, array_length(ett));
76 }
77
78 void
79 proto_reg_handoff_chargen(void)
80 {
81         dissector_handle_t chargen_handle;
82
83         chargen_handle = create_dissector_handle(dissect_chargen, proto_chargen);
84         dissector_add_uint_with_preference("udp.port", CHARGEN_PORT_UDP, chargen_handle);
85         dissector_add_uint_with_preference("tcp.port", CHARGEN_PORT_TCP, chargen_handle);
86 }
87
88 /*
89  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
90  *
91  * Local variables:
92  * c-basic-offset: 8
93  * tab-width: 8
94  * indent-tabs-mode: t
95  * End:
96  *
97  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
98  * :indentSize=8:tabSize=8:noTabs=false:
99  */