2 * Routines for chargen packet dissection
3 * Copyright 2014, Dario Lombardo <lomato@gmail.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * Chargen specs taken from RFC 864
10 * http://tools.ietf.org/html/rfc864
12 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include <epan/packet.h>
18 #define CHARGEN_PORT_UDP 19
19 #define CHARGEN_PORT_TCP 19
21 void proto_register_chargen(void);
22 void proto_reg_handoff_chargen(void);
24 static int proto_chargen = -1;
26 static int hf_chargen_data = -1;
28 static gint ett_chargen = -1;
30 /* dissect_chargen - dissects chargen packet data
31 * tvb - tvbuff for packet data (IN)
33 * proto_tree - resolved protocol tree
36 dissect_chargen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* dissector_data _U_)
38 proto_tree* chargen_tree;
43 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Chargen");
44 col_set_str(pinfo->cinfo, COL_INFO, "Chargen");
46 ti = proto_tree_add_item(tree, proto_chargen, tvb, 0, -1, ENC_NA);
47 chargen_tree = proto_item_add_subtree(ti, ett_chargen);
49 len = tvb_reported_length(tvb);
50 data = tvb_get_string_enc(wmem_packet_scope(), tvb, 0, len, ENC_ASCII);
52 proto_tree_add_string_format(chargen_tree, hf_chargen_data, tvb, 0,
53 len, "Data", "Data (%u): %s", len, data);
55 /* proto_tree_add_item(chargen_tree, hf_chargen_data, tvb, 0, -1, ENC_ASCII|ENC_NA); */
56 return tvb_captured_length(tvb);
60 proto_register_chargen(void)
62 static hf_register_info hf[] = {
64 "Data", "chargen.data", FT_STRING, BASE_NONE,
65 NULL, 0, NULL, HFILL }}
68 static gint *ett[] = {
72 proto_chargen = proto_register_protocol("Character Generator Protocol", "Chargen",
74 proto_register_field_array(proto_chargen, hf, array_length(hf));
75 proto_register_subtree_array(ett, array_length(ett));
79 proto_reg_handoff_chargen(void)
81 dissector_handle_t chargen_handle;
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);
89 * Editor modelines - https://www.wireshark.org/tools/modelines.html
97 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
98 * :indentSize=8:tabSize=8:noTabs=false: