TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / epan / dissectors / packet-gift.c
blobc49cd9ccfba999fd612bf0d31e34b01cb110016a
1 /* packet-gift.c
2 * Routines for giFT Internet File Transfer dissection
3 * Copyright 2000, Jon Oberheide <jon@oberheide.org>
5 * See http://www.giftproject.org/
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "config.h"
16 #include <epan/packet.h>
17 #include <epan/strutil.h>
19 void proto_register_gift(void);
20 void proto_reg_handoff_gift(void);
22 static dissector_handle_t gift_handle;
24 #define TCP_PORT_GIFT 1213 /* Not IANA registered */
26 static int proto_gift;
27 static int hf_gift_response;
28 static int hf_gift_request;
29 static int hf_gift_response_cmd;
30 static int hf_gift_response_arg;
31 static int hf_gift_request_cmd;
32 static int hf_gift_request_arg;
34 static int ett_gift;
35 static int ett_gift_cmd;
37 static int
38 dissect_gift(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
40 proto_item *ti, *hidden_item;
41 proto_tree *gift_tree, *cmd_tree;
42 bool is_request;
43 int offset = 0;
44 const unsigned char *line;
45 int next_offset;
46 int linelen;
47 int tokenlen;
48 const unsigned char *next_token;
50 /* set "Protocol" column text */
51 col_set_str(pinfo->cinfo, COL_PROTOCOL, "giFT");
53 /* determine whether it is a request to or response from the server */
54 if (pinfo->match_uint == pinfo->destport)
55 is_request = true;
56 else
57 is_request = false;
59 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, false);
60 line = tvb_get_ptr(tvb, offset, linelen);
62 /* set "Info" column text */
63 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
64 is_request ? "Request" : "Response",
65 format_text(pinfo->pool, line, linelen));
67 /* if tree != NULL, build protocol tree */
68 if (tree) {
69 ti = proto_tree_add_item(tree, proto_gift, tvb, 0, -1, ENC_NA);
70 gift_tree = proto_item_add_subtree(ti, ett_gift);
72 if (is_request) {
73 hidden_item = proto_tree_add_boolean(gift_tree, hf_gift_request, tvb, 0, 0, true);
74 } else {
75 hidden_item = proto_tree_add_boolean(gift_tree, hf_gift_response, tvb, 0, 0, true);
77 proto_item_set_hidden(hidden_item);
79 ti = proto_tree_add_format_text(gift_tree, tvb, offset, next_offset - offset);
80 cmd_tree = proto_item_add_subtree(ti, ett_gift_cmd);
82 tokenlen = get_token_len(line, line + linelen, &next_token);
83 if (tokenlen != 0) {
84 if (is_request) {
85 proto_tree_add_string(cmd_tree, hf_gift_request_cmd, tvb, offset,
86 tokenlen, format_text(pinfo->pool, line, tokenlen));
87 } else {
88 proto_tree_add_string(cmd_tree, hf_gift_response_cmd, tvb, offset,
89 tokenlen, format_text(pinfo->pool, line, tokenlen));
91 offset += (int) (next_token - line);
92 linelen -= (int) (next_token - line);
93 line = next_token;
96 if (linelen != 0) {
97 if (is_request) {
98 proto_tree_add_string(cmd_tree, hf_gift_request_arg, tvb, offset,
99 linelen, format_text(pinfo->pool, line, linelen));
100 } else {
101 proto_tree_add_string(cmd_tree, hf_gift_response_arg, tvb, offset,
102 linelen, format_text(pinfo->pool, line, linelen));
106 return tvb_captured_length(tvb);
109 void
110 proto_register_gift(void)
112 static hf_register_info hf[] = {
113 { &hf_gift_response,
114 { "Response", "gift.response", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "true if giFT response", HFILL }
116 { &hf_gift_request,
117 { "Request", "gift.request", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "true if giFT request", HFILL }
119 { &hf_gift_response_cmd,
120 { "Response Command", "gift.response_cmd", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
122 { &hf_gift_response_arg,
123 { "Response Arg", "gift.response_arg", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
125 { &hf_gift_request_cmd,
126 { "Request Command", "gift.request_cmd", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
128 { &hf_gift_request_arg,
129 { "Request Arg", "gift.request_arg", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
133 static int *ett[] = {
134 &ett_gift,
135 &ett_gift_cmd,
138 proto_gift = proto_register_protocol("giFT Internet File Transfer",
139 "giFT", "gift");
141 proto_register_field_array(proto_gift, hf, array_length(hf));
142 proto_register_subtree_array(ett, array_length(ett));
144 gift_handle = register_dissector("gift", dissect_gift, proto_gift);
147 void
148 proto_reg_handoff_gift(void)
150 dissector_add_uint_with_preference("tcp.port", TCP_PORT_GIFT, gift_handle);
154 * Editor modelines - https://www.wireshark.org/tools/modelines.html
156 * Local variables:
157 * c-basic-offset: 8
158 * tab-width: 8
159 * indent-tabs-mode: t
160 * End:
162 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
163 * :indentSize=8:tabSize=8:noTabs=false: