diff options
author | Michael Mann <mmann78@netscape.net> | 2014-12-05 19:42:47 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2014-12-07 16:17:15 +0000 |
commit | 1bc8791fe69fdf5cf14925d067d21bc313142b0a (patch) | |
tree | 197933fa07d4f390f0d762737bfca1b05edb9772 | |
parent | afa5558479a492d415b617788142ee268f60bc8d (diff) |
Eliminate proto_tree_add_text from packet-telnet.c
Change-Id: I0e8610f381e650f2c5b3f78ea927b727ec9ac62a
Reviewed-on: https://code.wireshark.org/review/5637
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r-- | epan/dissectors/packet-telnet.c | 130 |
1 files changed, 96 insertions, 34 deletions
diff --git a/epan/dissectors/packet-telnet.c b/epan/dissectors/packet-telnet.c index bb64ae1f61..af69968a8c 100644 --- a/epan/dissectors/packet-telnet.c +++ b/epan/dissectors/packet-telnet.c @@ -64,13 +64,24 @@ static int hf_telnet_comport_subopt_data_size = -1; static int hf_telnet_comport_subopt_parity = -1; static int hf_telnet_comport_subopt_stop = -1; static int hf_telnet_comport_subopt_control = -1; +static int hf_telnet_comport_linestate = -1; +static int hf_telnet_comport_set_linestate_mask = -1; +static int hf_telnet_comport_modemstate = -1; +static int hf_telnet_comport_set_modemstate_mask = -1; +static int hf_telnet_comport_subopt_flow_control_suspend = -1; +static int hf_telnet_comport_subopt_flow_control_resume = -1; static int hf_telnet_comport_subopt_purge = -1; static int hf_telnet_rfc_subopt_cmd = -1; +static int hf_telnet_tabstop = -1; static int hf_telnet_enc_cmd = -1; static int hf_telnet_enc_type = -1; +static int hf_telnet_enc_type_data = -1; +static int hf_telnet_enc_key_id = -1; static int hf_telnet_data = -1; +static int hf_telnet_option_data = -1; +static int hf_telnet_subcommand_data = -1; static int hf_tn3270_subopt = -1; static int hf_tn3270_connect = -1; @@ -79,6 +90,7 @@ static int hf_tn3270_request_string = -1; static int hf_tn3270_reason = -1; static int hf_tn3270_request = -1; static int hf_tn3270_regime_subopt_value = -1; +static int hf_tn3270_regime_cmd = -1; static gint ett_telnet = -1; static gint ett_telnet_cmd = -1; @@ -253,7 +265,7 @@ dissect_string_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, in switch (cmd) { case 0: /* IS */ - proto_tree_add_text(tree, tvb, offset, 1, "Here's my %s", optname); + proto_tree_add_uint_format(tree, hf_telnet_subcmd, tvb, offset, 1, cmd, "Here's my %s", optname); offset++; len--; if (len > 0) { @@ -263,11 +275,11 @@ dissect_string_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, in break; case 1: /* SEND */ - proto_tree_add_text(tree, tvb, offset, 1, "Send your %s", optname); + proto_tree_add_uint_format(tree, hf_telnet_subcmd, tvb, offset, 1, cmd, "Send your %s", optname); offset++; len--; if (len > 0) - proto_tree_add_text(tree, tvb, offset, len, "Extra data"); + proto_tree_add_bytes_format(tree, hf_telnet_subcommand_data, tvb, offset, len, NULL, "Extra data"); break; default: @@ -276,14 +288,14 @@ dissect_string_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, in offset++; len--; if (len > 0) - proto_tree_add_text(tree, tvb, offset, len, "Subcommand data"); + proto_tree_add_item(tree, hf_telnet_subcommand_data, tvb, offset, len, ENC_NA); break; } } static void dissect_tn3270_regime_subopt(packet_info *pinfo, const char *optname _U_, tvbuff_t *tvb, int offset, - int len, proto_tree *tree, proto_item *item) + int len, proto_tree *tree, proto_item *item _U_) { #define TN3270_REGIME_ARE 0x01 #define TN3270_REGIME_IS 0x00 @@ -296,16 +308,16 @@ dissect_tn3270_regime_subopt(packet_info *pinfo, const char *optname _U_, tvbuff case TN3270_REGIME_ARE: case TN3270_REGIME_IS: if (cmd == TN3270_REGIME_ARE) { - proto_tree_add_text(tree, tvb, offset, 1, "ARE"); + proto_tree_add_uint_format(tree, hf_tn3270_regime_cmd, tvb, offset, 1, cmd, "ARE"); add_tn3270_conversation(pinfo, 0, 0); } else { - proto_tree_add_text(tree, tvb, offset, 1, "IS"); + proto_tree_add_uint_format(tree, hf_tn3270_regime_cmd, tvb, offset, 1, cmd, "IS"); } proto_tree_add_item(tree, hf_tn3270_regime_subopt_value, tvb, offset + 1, len - 1, ENC_NA|ENC_ASCII); len -= len; return; default: - expert_add_info_format(pinfo, item, &ei_telnet_invalid_subcommand, "Bogus value: %u", cmd); + proto_tree_add_uint_format(tree, hf_tn3270_regime_cmd, tvb, offset, 1, cmd, "Bogus value: %u", cmd); break; } offset++; @@ -489,13 +501,13 @@ dissect_htstops_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i switch (cmd) { case 0: /* IS */ - proto_tree_add_text(tree, tvb, offset, 1, "Here's my %s", optname); + proto_tree_add_uint_format(tree, hf_telnet_subcmd, tvb, offset, 1, cmd, "Here's my %s", optname); offset++; len--; break; case 1: /* SEND */ - proto_tree_add_text(tree, tvb, offset, 1, "Send your %s", optname); + proto_tree_add_uint_format(tree, hf_telnet_subcmd, tvb, offset, 1, cmd, "Send your %s", optname); offset++; len--; break; @@ -505,7 +517,7 @@ dissect_htstops_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i offset++; len--; if (len > 0) - proto_tree_add_text(tree, tvb, offset, len, "Subcommand data"); + proto_tree_add_item(tree, hf_telnet_subcommand_data, tvb, offset, len, ENC_NA); return; } @@ -514,13 +526,13 @@ dissect_htstops_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i switch (tabval) { case 0: - proto_tree_add_text(tree, tvb, offset, 1, - "Sender wants to handle tab stops"); + proto_tree_add_uint_format(tree, hf_telnet_tabstop, tvb, offset, 1, + tabval, "Sender wants to handle tab stops"); break; default: - proto_tree_add_text(tree, tvb, offset, 1, - "Sender wants receiver to handle tab stop at %u", + proto_tree_add_uint_format(tree, hf_telnet_tabstop, tvb, offset, 1, + tabval, "Sender wants receiver to handle tab stop at %u", tabval); break; @@ -528,13 +540,13 @@ dissect_htstops_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i case 252: case 253: case 254: - proto_tree_add_text(tree, tvb, offset, 1, - "Invalid value: %u", tabval); + proto_tree_add_uint_format(tree, hf_telnet_tabstop, tvb, offset, 1, + tabval, "Invalid value: %u", tabval); break; case 255: - proto_tree_add_text(tree, tvb, offset, 1, - "Sender wants receiver to handle tab stops"); + proto_tree_add_uint_format(tree, hf_telnet_tabstop, tvb, offset, 1, + tabval, "Sender wants receiver to handle tab stops"); break; } offset++; @@ -659,10 +671,10 @@ dissect_comport_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i case TNCOMPORT_SIGNATURE: len--; if (len == 0) { - proto_tree_add_text(tree, tvb, offset, 1, "%s Requests Signature",source); + proto_tree_add_string_format(tree, hf_telnet_comport_subopt_signature, tvb, offset, 1, "", "%s Requests Signature", source); } else { guint8 *sig = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 1, len, ENC_ASCII); - proto_tree_add_string_format_value(tree, hf_telnet_comport_subopt_signature, tvb, offset, 1 + len, sig, + proto_tree_add_string_format(tree, hf_telnet_comport_subopt_signature, tvb, offset, 1 + len, sig, "%s Signature: %s",source, sig); } break; @@ -734,6 +746,8 @@ dissect_comport_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i if (len >= 1) { const char *print_pattern = (cmd == TNCOMPORT_SETLINESTATEMASK) ? "%s Set Linestate Mask: %s" : "%s Linestate: %s"; + int hf_line = (cmd == TNCOMPORT_SETLINESTATEMASK) ? + hf_telnet_comport_set_linestate_mask : hf_telnet_comport_linestate; char ls_buffer[512]; guint8 ls = tvb_get_guint8(tvb, offset+1); int print_count = 0; @@ -750,7 +764,7 @@ dissect_comport_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i } ls = ls >> 1; } - proto_tree_add_text(tree, tvb, offset, 2, print_pattern, source, ls_buffer); + proto_tree_add_string_format(tree, hf_line, tvb, offset, 2, ls_buffer, print_pattern, source, ls_buffer); } else { const char *print_pattern = (cmd == TNCOMPORT_SETLINESTATEMASK) ? "%s <Invalid Linestate Mask>" : "%s <Invalid Linestate Packet>"; @@ -764,6 +778,8 @@ dissect_comport_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i if (len >= 1) { const char *print_pattern = (cmd == TNCOMPORT_SETMODEMSTATEMASK) ? "%s Set Modemstate Mask: %s" : "%s Modemstate: %s"; + int hf_modem = (cmd == TNCOMPORT_SETMODEMSTATEMASK) ? + hf_telnet_comport_set_modemstate_mask : hf_telnet_comport_modemstate; char ms_buffer[256]; guint8 ms = tvb_get_guint8(tvb, offset+1); int print_count = 0; @@ -780,7 +796,7 @@ dissect_comport_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i } ms = ms >> 1; } - proto_tree_add_text(tree, tvb, offset, 2, print_pattern, source, ms_buffer); + proto_tree_add_string_format(tree, hf_modem, tvb, offset, 2, ms_buffer, print_pattern, source, ms_buffer); } else { const char *print_pattern = (cmd == TNCOMPORT_SETMODEMSTATEMASK) ? "%s <Invalid Modemstate Mask>" : "%s <Invalid Modemstate Packet>"; @@ -790,12 +806,12 @@ dissect_comport_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i case TNCOMPORT_FLOWCONTROLSUSPEND: len--; - proto_tree_add_text(tree, tvb, offset, 1, "%s Flow Control Suspend",source); + proto_tree_add_none_format(tree, hf_telnet_comport_subopt_flow_control_suspend, tvb, offset, 1, "%s Flow Control Suspend",source); break; case TNCOMPORT_FLOWCONTROLRESUME: len--; - proto_tree_add_text(tree, tvb, offset, 1, "%s Flow Control Resume",source); + proto_tree_add_none_format(tree, hf_telnet_comport_subopt_flow_control_resume, tvb, offset, 1, "%s Flow Control Resume",source); break; case TNCOMPORT_PURGEDATA: @@ -815,7 +831,7 @@ dissect_comport_subopt(packet_info *pinfo, const char *optname, tvbuff_t *tvb, i offset++; len--; if (len > 0) - proto_tree_add_text(tree, tvb, offset, len, "Subcommand data"); + proto_tree_add_item(tree, hf_telnet_subcommand_data, tvb, offset, len, ENC_NA); return; } @@ -1141,7 +1157,7 @@ dissect_encryption_subopt(packet_info *pinfo, const char *optname _U_, tvbuff_t dissect_encryption_type(tvb, offset, tree); offset++; len--; - proto_tree_add_text(tree, tvb, offset, len, "Type-specific data"); + proto_tree_add_item(tree, hf_telnet_enc_type_data, tvb, offset, len, ENC_NA); } break; @@ -1158,7 +1174,7 @@ dissect_encryption_subopt(packet_info *pinfo, const char *optname _U_, tvbuff_t /* keyid ... */ if (len > 0) { key_first_octet = tvb_get_guint8(tvb, offset); - proto_tree_add_text(tree, tvb, offset, len, (key_first_octet == 0) ? "Default key" : "Key ID"); + proto_tree_add_bytes_format(tree, hf_telnet_enc_key_id, tvb, offset, len, NULL, (key_first_octet == 0) ? "Default key" : "Key ID"); } break; @@ -1169,7 +1185,7 @@ dissect_encryption_subopt(packet_info *pinfo, const char *optname _U_, tvbuff_t case TN_ENC_REQUEST_START: /* (optional) keyid */ if (len > 0) - proto_tree_add_text(tree, tvb, offset, len, "Key ID (advisory)"); + proto_tree_add_bytes_format(tree, hf_telnet_enc_key_id, tvb, offset, len, NULL, "Key ID (advisory)"); break; case TN_ENC_REQUEST_END: @@ -1180,7 +1196,7 @@ dissect_encryption_subopt(packet_info *pinfo, const char *optname _U_, tvbuff_t case TN_ENC_DEC_KEYID: /* (optional) keyid - if not supplied, there are no more known keys */ if (len > 0) - proto_tree_add_text(tree, tvb, offset, len, "Key ID"); + proto_tree_add_item(tree, hf_telnet_enc_key_id, tvb, offset, len, ENC_NA); break; default: @@ -1616,11 +1632,9 @@ telnet_sub_option(packet_info *pinfo, proto_tree *option_tree, proto_item *optio if (iac_data > 0) { /* Data is escaped, we have to unescape it. */ unescaped_tvb = unescape_and_tvbuffify_telnet_option(pinfo, tvb, start_offset, subneg_len); - proto_tree_add_text(option_tree, unescaped_tvb, 0, subneg_len - iac_data, - "Option data"); + proto_tree_add_item(option_tree, hf_telnet_option_data, unescaped_tvb, 0, subneg_len - iac_data, ENC_NA); } else { - proto_tree_add_text(option_tree, tvb, start_offset, subneg_len, - "Option data"); + proto_tree_add_item(option_tree, hf_telnet_option_data, tvb, start_offset, subneg_len, ENC_NA); } } } @@ -1931,6 +1945,30 @@ proto_register_telnet(void) { "Control", "telnet.comport_subopt.control", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } }, + { &hf_telnet_comport_linestate, + { "Linestate", "telnet.comport_subopt.linestate", FT_STRING, BASE_NONE, + NULL, 0, NULL, HFILL } + }, + { &hf_telnet_comport_set_linestate_mask, + { "Set Linestate Mask", "telnet.comport_subopt.set_linestate_mask", FT_STRING, BASE_NONE, + NULL, 0, NULL, HFILL } + }, + { &hf_telnet_comport_modemstate, + { "Modemstate", "telnet.comport_subopt.modemstate", FT_STRING, BASE_NONE, + NULL, 0, NULL, HFILL } + }, + { &hf_telnet_comport_set_modemstate_mask, + { "Set Modemstate Mask", "telnet.comport_subopt.set_modemstate_mask", FT_STRING, BASE_NONE, + NULL, 0, NULL, HFILL } + }, + { &hf_telnet_comport_subopt_flow_control_suspend, + { "Flow Control Suspend", "telnet.comport_subopt.flow_control_suspend", FT_NONE, BASE_NONE, + NULL, 0, NULL, HFILL } + }, + { &hf_telnet_comport_subopt_flow_control_resume, + { "Flow Control Resume", "telnet.comport_subopt.flow_control_resume", FT_NONE, BASE_NONE, + NULL, 0, NULL, HFILL } + }, { &hf_telnet_comport_subopt_purge, { "Purge", "telnet.comport_subopt.purge", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } @@ -1939,6 +1977,10 @@ proto_register_telnet(void) { "Command", "telnet.rfc_subopt.cmd", FT_UINT8, BASE_DEC, VALS(rfc_opt_vals), 0, NULL, HFILL } }, + { &hf_telnet_tabstop, + { "Tabstop value", "telnet.tabstop", FT_UINT8, BASE_DEC, + NULL, 0, NULL, HFILL } + }, { &hf_telnet_enc_cmd, { "Enc Cmd", "telnet.enc.cmd", FT_UINT8, BASE_DEC, VALS(enc_cmd_vals), 0, "Encryption command", HFILL } @@ -1947,10 +1989,26 @@ proto_register_telnet(void) { "Enc Type", "telnet.enc.type", FT_UINT8, BASE_DEC, VALS(enc_type_vals), 0, "Encryption type", HFILL } }, + { &hf_telnet_enc_type_data, + { "Type-specific data", "telnet.enc.type_data", FT_BYTES, BASE_NONE, + NULL, 0, NULL, HFILL } + }, + { &hf_telnet_enc_key_id, + { "Key ID", "telnet.enc.key_id", FT_BYTES, BASE_NONE, + NULL, 0, NULL, HFILL } + }, { &hf_telnet_data, { "Data", "telnet.data", FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } }, + { &hf_telnet_option_data, + { "Option data", "telnet.option_data", FT_BYTES, BASE_NONE, + NULL, 0, NULL, HFILL } + }, + { &hf_telnet_subcommand_data, + { "Subcommand data", "telnet.subcommand_data", FT_BYTES, BASE_NONE, + NULL, 0, NULL, HFILL } + }, { &hf_tn3270_subopt, { "Suboption", "telnet.tn3270.subopt", FT_UINT8, BASE_DEC, VALS(tn3270_subopt_vals), 0, NULL, HFILL } @@ -1979,6 +2037,10 @@ proto_register_telnet(void) { "Value", "telnet.tn3270.regime_subopt.value", FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } }, + { &hf_tn3270_regime_cmd, + { "Cmd", "telnet.regime_cmd", FT_UINT8, BASE_DEC, + NULL, 0, NULL, HFILL } + }, }; static gint *ett[] = { &ett_telnet, |