Use MAC address documentation range in filter examples
[metze/wireshark/wip.git] / epan / dissectors / packet-ddtp.c
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>
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 2000
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #include <epan/packet.h>
28 #include <epan/expert.h>
29
30 #define DDTP_VERSION_ERROR      0
31 #define DDTP_VERSION_4          1
32 #define DDTP_VERSION_5          2
33
34 #define DDTP_ENCRYPT_ERROR      0
35 #define DDTP_ENCRYPT_PLAINTEXT  1
36 #define DDTP_ENCRYPT_BLOWFISH   2
37
38 #define DDTP_MESSAGE_ERROR      0
39 #define DDTP_UPDATE_QUERY       1
40 #define DDTP_UPDATE_REPLY       2
41 #define DDTP_ALIVE_QUERY        3
42 #define DDTP_ALIVE_REPLY        4
43
44 #define DDTP_MARK_ONLINE        0
45 #define DDTP_MARK_OFFLINE       1
46
47 #define DDTP_UPDATE_SUCCEEDED   0
48 #define DDTP_UPDATE_FAILED      1
49 #define DDTP_INVALID_PASSWORD   2
50 #define DDTP_INVALID_ACCOUNT    3
51 #define DDTP_INVALID_OPCODE     4
52
53 void proto_register_ddtp (void);
54 void proto_reg_handoff_ddtp (void);
55
56 static int proto_ddtp = -1;
57 static int hf_ddtp_version = -1;
58 static int hf_ddtp_encrypt = -1;
59 static int hf_ddtp_hostid = -1;
60 static int hf_ddtp_msgtype = -1;
61 static int hf_ddtp_opcode = -1;
62 static int hf_ddtp_ipaddr = -1;
63 static int hf_ddtp_status = -1;
64 static int hf_ddtp_alive = -1;
65
66 static int ett_ddtp = -1;
67
68 static expert_field ei_ddtp_msgtype = EI_INIT;
69
70 #define UDP_PORT_DDTP   1052
71
72 /*
73  * XXX - is 0 an invalid value?  If so, should we remove it from this
74  * list, so that putative DDNS packets with a version number of 0 are
75  * rejected?
76  */
77 static const value_string vals_ddtp_version[] = {
78     { DDTP_VERSION_ERROR, "Protocol Error" },
79     { DDTP_VERSION_4,     "4" },
80     { DDTP_VERSION_5,     "5" },
81     { 0, NULL}
82 };
83
84 static const value_string vals_ddtp_encrypt[] = {
85     { DDTP_ENCRYPT_ERROR,     "Encryption Error" },
86     { DDTP_ENCRYPT_PLAINTEXT, "Plain text" },
87     { DDTP_ENCRYPT_BLOWFISH,  "Blowfish" },
88     { 0, NULL}
89 };
90
91 static const value_string vals_ddtp_msgtype[] = {
92     { DDTP_MESSAGE_ERROR, "Message Error" },
93     { DDTP_UPDATE_QUERY,  "Update Query" },
94     { DDTP_UPDATE_REPLY,  "Update Reply" },
95     { DDTP_ALIVE_QUERY,   "Alive Query" },
96     { DDTP_ALIVE_REPLY,   "Alive Reply" },
97     { 0, NULL}
98 };
99
100 static const value_string vals_ddtp_opcode[] = {
101     { DDTP_MARK_ONLINE,  "Mark online" },
102     { DDTP_MARK_OFFLINE, "Mark offline" },
103     { 0, NULL}
104 };
105
106 static const value_string vals_ddtp_status[] = {
107     { DDTP_UPDATE_SUCCEEDED, "Update succeeded" },
108     { DDTP_UPDATE_FAILED,    "Update failed" },
109     { DDTP_INVALID_PASSWORD, "Invalid password" },
110     { DDTP_INVALID_ACCOUNT,  "Invalid account" },
111     { DDTP_INVALID_OPCODE,   "Invalid opcode" },
112     { 0, NULL}
113 };
114
115 static int
116 dissect_ddtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
117 {
118     proto_tree *ddtp_tree;
119     proto_item *ti;
120
121     /*
122      * If we don't recognize the version number, don't dissect this.
123      */
124     if (tvb_reported_length(tvb) < 4)
125         return 0;
126
127     if (try_val_to_str(tvb_get_ntohl(tvb, 0), vals_ddtp_version) == NULL)
128             return 0;
129
130     /* Indicate what kind of message this is. */
131     col_set_str (pinfo->cinfo, COL_PROTOCOL, "DDTP");
132     /* In case we throw an exception below. */
133     col_clear (pinfo->cinfo, COL_INFO);
134
135         ti = proto_tree_add_item(tree, proto_ddtp, tvb, 0, -1, ENC_NA);
136         ddtp_tree = proto_item_add_subtree(ti, ett_ddtp);
137
138         proto_tree_add_item(ddtp_tree, hf_ddtp_version, tvb, 0, 4, ENC_BIG_ENDIAN);
139         proto_tree_add_item(ddtp_tree, hf_ddtp_encrypt, tvb, 4, 4, ENC_BIG_ENDIAN);
140         proto_tree_add_item(ddtp_tree, hf_ddtp_hostid, tvb, 8, 4, ENC_BIG_ENDIAN);
141
142     if (tvb_get_ntohl(tvb, 4) == DDTP_ENCRYPT_PLAINTEXT) {
143             ti = proto_tree_add_item(ddtp_tree, hf_ddtp_msgtype, tvb, 12, 4, ENC_BIG_ENDIAN);
144         switch (tvb_get_ntohl(tvb, 12)) {
145         case DDTP_MESSAGE_ERROR :
146             col_set_str(pinfo->cinfo, COL_INFO, "Message Error");
147             break;
148         case DDTP_UPDATE_QUERY :
149             col_set_str(pinfo->cinfo, COL_INFO, "Update Query");
150                 proto_tree_add_item(ddtp_tree, hf_ddtp_opcode, tvb, 16, 4, ENC_BIG_ENDIAN);
151                 proto_tree_add_item(ddtp_tree, hf_ddtp_ipaddr, tvb, 20, 4, ENC_BIG_ENDIAN);
152             break;
153         case DDTP_UPDATE_REPLY :
154             col_set_str(pinfo->cinfo, COL_INFO, "Update Reply");
155                 proto_tree_add_item(ddtp_tree, hf_ddtp_status, tvb, 16, 4, ENC_BIG_ENDIAN);
156             break;
157         case DDTP_ALIVE_QUERY :
158             col_set_str(pinfo->cinfo, COL_INFO, "Alive Query");
159                 proto_tree_add_item(ddtp_tree, hf_ddtp_alive, tvb, 16, 4, ENC_BIG_ENDIAN);
160             break;
161         case DDTP_ALIVE_REPLY :
162             col_set_str(pinfo->cinfo, COL_INFO, "Alive Reply");
163                 proto_tree_add_item(ddtp_tree, hf_ddtp_alive, tvb, 16, 4, ENC_BIG_ENDIAN);
164             break;
165         default :
166             col_set_str(pinfo->cinfo, COL_INFO, "Unknown type");
167                 expert_add_info(pinfo, ti, &ei_ddtp_msgtype);
168         }
169     } else {
170         col_set_str(pinfo->cinfo, COL_INFO, "Encrypted payload");
171     }
172     return tvb_reported_length(tvb);
173 }
174
175 void
176 proto_register_ddtp(void)
177 {
178     static hf_register_info hf_ddtp[] = {
179         { &hf_ddtp_version,
180           { "Version", "ddtp.version", FT_UINT32, BASE_DEC, VALS(vals_ddtp_version), 0x0,
181             NULL, HFILL }},
182         { &hf_ddtp_encrypt,
183           { "Encryption", "ddtp.encrypt", FT_UINT32, BASE_DEC, VALS(vals_ddtp_encrypt), 0x0,
184             "Encryption type", HFILL }},
185         { &hf_ddtp_hostid,
186           { "Hostid", "ddtp.hostid", FT_UINT32, BASE_DEC, NULL, 0x0,
187             "Host ID", HFILL }},
188         { &hf_ddtp_msgtype,
189           { "Message type", "ddtp.msgtype", FT_UINT32, BASE_DEC, VALS(vals_ddtp_msgtype), 0x0,
190             NULL, HFILL }},
191         { &hf_ddtp_opcode,
192           { "Opcode", "ddtp.opcode", FT_UINT32, BASE_DEC, VALS(vals_ddtp_opcode), 0x0,
193             "Update query opcode", HFILL }},
194         { &hf_ddtp_ipaddr,
195           { "IP address", "ddtp.ipaddr", FT_IPv4, BASE_NONE, NULL, 0x0,
196             NULL, HFILL }},
197         { &hf_ddtp_status,
198           { "Status", "ddtp.status", FT_UINT32, BASE_DEC, VALS(vals_ddtp_status), 0x0,
199             "Update reply status", HFILL }},
200         { &hf_ddtp_alive,
201           { "Dummy", "ddtp.alive", FT_UINT32, BASE_DEC, NULL, 0x0,
202             NULL, HFILL }},
203     };
204
205     static gint *ett[] = { &ett_ddtp };
206
207     static ei_register_info ei[] = {
208         { &ei_ddtp_msgtype, { "ddtp.msgtype.unknown", PI_PROTOCOL, PI_WARN, "Unknown type", EXPFILL }},
209     };
210
211     expert_module_t* expert_ddtp;
212
213     proto_ddtp = proto_register_protocol("Dynamic DNS Tools Protocol",
214                                          "DDTP", "ddtp");
215     proto_register_field_array(proto_ddtp, hf_ddtp, array_length(hf_ddtp));
216     proto_register_subtree_array(ett, array_length(ett));
217     expert_ddtp = expert_register_protocol(proto_ddtp);
218     expert_register_field_array(expert_ddtp, ei, array_length(ei));
219 }
220
221 void
222 proto_reg_handoff_ddtp(void)
223 {
224     dissector_handle_t ddtp_handle;
225
226     ddtp_handle = new_create_dissector_handle(dissect_ddtp, proto_ddtp);
227     dissector_add_uint("udp.port", UDP_PORT_DDTP, ddtp_handle);
228 }
229
230 /*
231  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
232  *
233  * Local variables:
234  * c-basic-offset: 4
235  * tab-width: 8
236  * indent-tabs-mode: nil
237  * End:
238  *
239  * vi: set shiftwidth=4 tabstop=8 expandtab:
240  * :indentSize=4:tabSize=8:noTabs=true:
241  */