Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-ddtp.c
blobe59172f06cd4d5781ec57299a5ace453d57ef3fb
1 /* packet-ddtp.c
2 * Routines for DDTP (Dynamic DNS Tools Protocol) packet disassembly
3 * see http://ddt.sourceforge.net/
4 * Olivier Abad <oabad@noos.fr>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 2000
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #include <epan/expert.h>
18 #define DDTP_VERSION_ERROR 0
19 #define DDTP_VERSION_4 1
20 #define DDTP_VERSION_5 2
22 #define DDTP_ENCRYPT_ERROR 0
23 #define DDTP_ENCRYPT_PLAINTEXT 1
24 #define DDTP_ENCRYPT_BLOWFISH 2
26 #define DDTP_MESSAGE_ERROR 0
27 #define DDTP_UPDATE_QUERY 1
28 #define DDTP_UPDATE_REPLY 2
29 #define DDTP_ALIVE_QUERY 3
30 #define DDTP_ALIVE_REPLY 4
32 #define DDTP_MARK_ONLINE 0
33 #define DDTP_MARK_OFFLINE 1
35 #define DDTP_UPDATE_SUCCEEDED 0
36 #define DDTP_UPDATE_FAILED 1
37 #define DDTP_INVALID_PASSWORD 2
38 #define DDTP_INVALID_ACCOUNT 3
39 #define DDTP_INVALID_OPCODE 4
41 void proto_register_ddtp (void);
42 void proto_reg_handoff_ddtp (void);
44 static dissector_handle_t ddtp_handle;
46 static int proto_ddtp;
47 static int hf_ddtp_version;
48 static int hf_ddtp_encrypt;
49 static int hf_ddtp_hostid;
50 static int hf_ddtp_msgtype;
51 static int hf_ddtp_opcode;
52 static int hf_ddtp_ipaddr;
53 static int hf_ddtp_status;
54 static int hf_ddtp_alive;
56 static int ett_ddtp;
58 static expert_field ei_ddtp_msgtype;
60 #define UDP_PORT_DDTP 1052
63 * XXX - is 0 an invalid value? If so, should we remove it from this
64 * list, so that putative DDNS packets with a version number of 0 are
65 * rejected?
67 static const value_string vals_ddtp_version[] = {
68 { DDTP_VERSION_ERROR, "Protocol Error" },
69 { DDTP_VERSION_4, "4" },
70 { DDTP_VERSION_5, "5" },
71 { 0, NULL}
74 static const value_string vals_ddtp_encrypt[] = {
75 { DDTP_ENCRYPT_ERROR, "Encryption Error" },
76 { DDTP_ENCRYPT_PLAINTEXT, "Plain text" },
77 { DDTP_ENCRYPT_BLOWFISH, "Blowfish" },
78 { 0, NULL}
81 static const value_string vals_ddtp_msgtype[] = {
82 { DDTP_MESSAGE_ERROR, "Message Error" },
83 { DDTP_UPDATE_QUERY, "Update Query" },
84 { DDTP_UPDATE_REPLY, "Update Reply" },
85 { DDTP_ALIVE_QUERY, "Alive Query" },
86 { DDTP_ALIVE_REPLY, "Alive Reply" },
87 { 0, NULL}
90 static const value_string vals_ddtp_opcode[] = {
91 { DDTP_MARK_ONLINE, "Mark online" },
92 { DDTP_MARK_OFFLINE, "Mark offline" },
93 { 0, NULL}
96 static const value_string vals_ddtp_status[] = {
97 { DDTP_UPDATE_SUCCEEDED, "Update succeeded" },
98 { DDTP_UPDATE_FAILED, "Update failed" },
99 { DDTP_INVALID_PASSWORD, "Invalid password" },
100 { DDTP_INVALID_ACCOUNT, "Invalid account" },
101 { DDTP_INVALID_OPCODE, "Invalid opcode" },
102 { 0, NULL}
105 static int
106 dissect_ddtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
108 proto_tree *ddtp_tree;
109 proto_item *ti;
112 * If we don't recognize the version number, don't dissect this.
114 if (tvb_reported_length(tvb) < 4)
115 return 0;
117 if (try_val_to_str(tvb_get_ntohl(tvb, 0), vals_ddtp_version) == NULL)
118 return 0;
120 /* Indicate what kind of message this is. */
121 col_set_str (pinfo->cinfo, COL_PROTOCOL, "DDTP");
122 /* In case we throw an exception below. */
123 col_clear (pinfo->cinfo, COL_INFO);
125 ti = proto_tree_add_item(tree, proto_ddtp, tvb, 0, -1, ENC_NA);
126 ddtp_tree = proto_item_add_subtree(ti, ett_ddtp);
128 proto_tree_add_item(ddtp_tree, hf_ddtp_version, tvb, 0, 4, ENC_BIG_ENDIAN);
129 proto_tree_add_item(ddtp_tree, hf_ddtp_encrypt, tvb, 4, 4, ENC_BIG_ENDIAN);
130 proto_tree_add_item(ddtp_tree, hf_ddtp_hostid, tvb, 8, 4, ENC_BIG_ENDIAN);
132 if (tvb_get_ntohl(tvb, 4) == DDTP_ENCRYPT_PLAINTEXT) {
133 ti = proto_tree_add_item(ddtp_tree, hf_ddtp_msgtype, tvb, 12, 4, ENC_BIG_ENDIAN);
134 switch (tvb_get_ntohl(tvb, 12)) {
135 case DDTP_MESSAGE_ERROR :
136 col_set_str(pinfo->cinfo, COL_INFO, "Message Error");
137 break;
138 case DDTP_UPDATE_QUERY :
139 col_set_str(pinfo->cinfo, COL_INFO, "Update Query");
140 proto_tree_add_item(ddtp_tree, hf_ddtp_opcode, tvb, 16, 4, ENC_BIG_ENDIAN);
141 proto_tree_add_item(ddtp_tree, hf_ddtp_ipaddr, tvb, 20, 4, ENC_BIG_ENDIAN);
142 break;
143 case DDTP_UPDATE_REPLY :
144 col_set_str(pinfo->cinfo, COL_INFO, "Update Reply");
145 proto_tree_add_item(ddtp_tree, hf_ddtp_status, tvb, 16, 4, ENC_BIG_ENDIAN);
146 break;
147 case DDTP_ALIVE_QUERY :
148 col_set_str(pinfo->cinfo, COL_INFO, "Alive Query");
149 proto_tree_add_item(ddtp_tree, hf_ddtp_alive, tvb, 16, 4, ENC_BIG_ENDIAN);
150 break;
151 case DDTP_ALIVE_REPLY :
152 col_set_str(pinfo->cinfo, COL_INFO, "Alive Reply");
153 proto_tree_add_item(ddtp_tree, hf_ddtp_alive, tvb, 16, 4, ENC_BIG_ENDIAN);
154 break;
155 default :
156 col_set_str(pinfo->cinfo, COL_INFO, "Unknown type");
157 expert_add_info(pinfo, ti, &ei_ddtp_msgtype);
159 } else {
160 col_set_str(pinfo->cinfo, COL_INFO, "Encrypted payload");
162 return tvb_reported_length(tvb);
165 void
166 proto_register_ddtp(void)
168 static hf_register_info hf_ddtp[] = {
169 { &hf_ddtp_version,
170 { "Version", "ddtp.version", FT_UINT32, BASE_DEC, VALS(vals_ddtp_version), 0x0,
171 NULL, HFILL }},
172 { &hf_ddtp_encrypt,
173 { "Encryption", "ddtp.encrypt", FT_UINT32, BASE_DEC, VALS(vals_ddtp_encrypt), 0x0,
174 "Encryption type", HFILL }},
175 { &hf_ddtp_hostid,
176 { "Hostid", "ddtp.hostid", FT_UINT32, BASE_DEC, NULL, 0x0,
177 "Host ID", HFILL }},
178 { &hf_ddtp_msgtype,
179 { "Message type", "ddtp.msgtype", FT_UINT32, BASE_DEC, VALS(vals_ddtp_msgtype), 0x0,
180 NULL, HFILL }},
181 { &hf_ddtp_opcode,
182 { "Opcode", "ddtp.opcode", FT_UINT32, BASE_DEC, VALS(vals_ddtp_opcode), 0x0,
183 "Update query opcode", HFILL }},
184 { &hf_ddtp_ipaddr,
185 { "IP address", "ddtp.ipaddr", FT_IPv4, BASE_NONE, NULL, 0x0,
186 NULL, HFILL }},
187 { &hf_ddtp_status,
188 { "Status", "ddtp.status", FT_UINT32, BASE_DEC, VALS(vals_ddtp_status), 0x0,
189 "Update reply status", HFILL }},
190 { &hf_ddtp_alive,
191 { "Dummy", "ddtp.alive", FT_UINT32, BASE_DEC, NULL, 0x0,
192 NULL, HFILL }},
195 static int *ett[] = { &ett_ddtp };
197 static ei_register_info ei[] = {
198 { &ei_ddtp_msgtype, { "ddtp.msgtype.unknown", PI_PROTOCOL, PI_WARN, "Unknown type", EXPFILL }},
201 expert_module_t* expert_ddtp;
203 proto_ddtp = proto_register_protocol("Dynamic DNS Tools Protocol", "DDTP", "ddtp");
204 proto_register_field_array(proto_ddtp, hf_ddtp, array_length(hf_ddtp));
205 proto_register_subtree_array(ett, array_length(ett));
206 expert_ddtp = expert_register_protocol(proto_ddtp);
207 expert_register_field_array(expert_ddtp, ei, array_length(ei));
209 ddtp_handle = register_dissector("ddtp", dissect_ddtp, proto_ddtp);
212 void
213 proto_reg_handoff_ddtp(void)
215 dissector_add_uint_with_preference("udp.port", UDP_PORT_DDTP, ddtp_handle);
219 * Editor modelines - https://www.wireshark.org/tools/modelines.html
221 * Local variables:
222 * c-basic-offset: 4
223 * tab-width: 8
224 * indent-tabs-mode: nil
225 * End:
227 * vi: set shiftwidth=4 tabstop=8 expandtab:
228 * :indentSize=4:tabSize=8:noTabs=true: