From Ronald Henderson: make "format_text()", on Windows, escape all
[obnox/wireshark/wip.git] / 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  * $Id: packet-ddtp.c,v 1.23 2002/09/01 14:30:30 oabad Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 2000
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  *
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 /*#include <string.h>
33 #include <ctype.h>
34 #include <time.h>*/
35
36 #include <glib.h>
37 #include <epan/packet.h>
38 #include "packet-ddtp.h"
39
40 static int proto_ddtp = -1;
41 static int hf_ddtp_version = -1;
42 static int hf_ddtp_encrypt = -1;
43 static int hf_ddtp_hostid = -1;
44 static int hf_ddtp_msgtype = -1;
45 static int hf_ddtp_opcode = -1;
46 static int hf_ddtp_ipaddr = -1;
47 static int hf_ddtp_status = -1;
48
49 static int ett_ddtp = -1;
50
51 #define UDP_PORT_DDTP   1052
52
53 static const value_string vals_ddtp_version[] = {
54     { DDTP_VERSION_ERROR, "Protocol Error" },
55     { DDTP_VERSION_4,     "4" },
56     { DDTP_VERSION_5,     "5" },
57     { 0, NULL}
58 };
59
60 static const value_string vals_ddtp_encrypt[] = {
61     { DDTP_ENCRYPT_ERROR,     "Encryption Error" },
62     { DDTP_ENCRYPT_PLAINTEXT, "Plain text" },
63     { DDTP_ENCRYPT_BLOWFISH,  "Blowfish" },
64     { 0, NULL}
65 };
66
67 static const value_string vals_ddtp_msgtype[] = {
68     { DDTP_MESSAGE_ERROR, "Message Error" },
69     { DDTP_UPDATE_QUERY,  "Update Query" },
70     { DDTP_UPDATE_REPLY,  "Update Reply" },
71     { DDTP_ALIVE_QUERY,   "Alive Query" },
72     { DDTP_ALIVE_REPLY,   "Alive Reply" },
73     { 0, NULL}
74 };
75
76 static const value_string vals_ddtp_opcode[] = {
77     { DDTP_MARK_ONLINE,  "Mark online" },
78     { DDTP_MARK_OFFLINE, "Mark offline" },
79     { 0, NULL}
80 };
81
82 static const value_string vals_ddtp_status[] = {
83     { DDTP_UPDATE_SUCCEEDED, "Update succeeded" },
84     { DDTP_UPDATE_FAILED,    "Update failed" },
85     { DDTP_INVALID_PASSWORD, "Invalid password" },
86     { DDTP_INVALID_ACCOUNT,  "Invalid account" },
87     { DDTP_INVALID_OPCODE,   "Invalid opcode" },
88     { 0, NULL}
89 };
90
91 static void
92 dissect_ddtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
93 {
94     proto_tree *ddtp_tree = NULL;
95     proto_item *ti;
96
97     if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
98         /* Indicate what kind of message this is. */
99         col_set_str (pinfo->cinfo, COL_PROTOCOL, "DDTP");
100     }
101     if (check_col(pinfo->cinfo, COL_INFO)) {
102         /* In case we throw an exception below. */
103         col_clear (pinfo->cinfo, COL_INFO);
104     }
105     if (tree) {
106         ti = proto_tree_add_item(tree, proto_ddtp, tvb, 0, -1, FALSE);
107         ddtp_tree = proto_item_add_subtree(ti, ett_ddtp);
108
109         proto_tree_add_item(ddtp_tree, hf_ddtp_version, tvb, 0, 4, FALSE);
110         proto_tree_add_item(ddtp_tree, hf_ddtp_encrypt, tvb, 4, 4, FALSE);
111         proto_tree_add_item(ddtp_tree, hf_ddtp_hostid, tvb, 8, 4, FALSE);
112     }
113     if (tvb_get_ntohl(tvb, 4) == DDTP_ENCRYPT_PLAINTEXT) {
114         if (tree)
115             proto_tree_add_item(ddtp_tree, hf_ddtp_msgtype, tvb, 12, 4, FALSE);
116         switch (tvb_get_ntohl(tvb, 12)) {
117         case DDTP_MESSAGE_ERROR :
118             if (check_col(pinfo->cinfo, COL_INFO))
119                 col_set_str (pinfo->cinfo, COL_INFO, "Message Error");
120             break;
121         case DDTP_UPDATE_QUERY :
122             if (check_col(pinfo->cinfo, COL_INFO))
123                 col_set_str (pinfo->cinfo, COL_INFO, "Update Query");
124             if (tree) {
125                 proto_tree_add_item(ddtp_tree, hf_ddtp_opcode, tvb, 16, 4,
126                         FALSE);
127                 proto_tree_add_item(ddtp_tree, hf_ddtp_ipaddr, tvb, 20, 4,
128                         FALSE);
129             }
130             break;
131         case DDTP_UPDATE_REPLY :
132             if (check_col(pinfo->cinfo, COL_INFO))
133                 col_set_str (pinfo->cinfo, COL_INFO, "Update Reply");
134             if (tree) {
135                 proto_tree_add_item(ddtp_tree, hf_ddtp_status, tvb, 16, 4,
136                         FALSE);
137             }
138             break;
139         case DDTP_ALIVE_QUERY :
140             if (check_col(pinfo->cinfo, COL_INFO))
141                 col_set_str (pinfo->cinfo, COL_INFO, "Alive Query");
142             if (tree) {
143                 proto_tree_add_text(ddtp_tree, tvb, 16, 4, "Dummy : %u",
144                         tvb_get_ntohl(tvb, 16));
145             }
146             break;
147         case DDTP_ALIVE_REPLY :
148             if (check_col(pinfo->cinfo, COL_INFO))
149                 col_set_str (pinfo->cinfo, COL_INFO, "Alive Reply");
150             if (tree) {
151                 proto_tree_add_text(ddtp_tree, tvb, 16, 4, "Dummy : %u",
152                         tvb_get_ntohl(tvb, 16));
153             }
154             break;
155         default :
156             if (check_col(pinfo->cinfo, COL_INFO))
157                 col_set_str (pinfo->cinfo, COL_INFO, "Unknown type");
158             if (tree) {
159                 proto_tree_add_text(ddtp_tree, tvb, 12, 4, "Unknown type : %u",
160                         tvb_get_ntohl(tvb, 12));
161             }
162         }
163     } else {
164         if (check_col(pinfo->cinfo, COL_INFO))
165             col_set_str (pinfo->cinfo, COL_INFO, "Encrypted payload");
166     }
167 }
168
169 void
170 proto_register_ddtp(void)
171 {
172     static hf_register_info hf_ddtp[] = {
173         { &hf_ddtp_version,
174             { "Version", "ddtp.version", FT_UINT32, BASE_DEC, VALS(vals_ddtp_version), 0x0,
175                 "Version", HFILL }},
176         { &hf_ddtp_encrypt,
177             { "Encryption", "ddtp.encrypt", FT_UINT32, BASE_DEC, VALS(vals_ddtp_encrypt), 0x0,
178                 "Encryption type", HFILL }},
179         { &hf_ddtp_hostid,
180             { "Hostid", "ddtp.hostid", FT_UINT32, BASE_DEC, NULL, 0x0,
181                 "Host ID", HFILL }},
182         { &hf_ddtp_msgtype,
183             { "Message type", "ddtp.msgtype", FT_UINT32, BASE_DEC, VALS(vals_ddtp_msgtype), 0x0,
184                 "Message Type", HFILL }},
185         { &hf_ddtp_opcode,
186             { "Opcode", "ddtp.opcode", FT_UINT32, BASE_DEC, VALS(vals_ddtp_opcode), 0x0,
187                 "Update query opcode", HFILL }},
188         { &hf_ddtp_ipaddr,
189             { "IP address", "ddtp.ipaddr", FT_IPv4, BASE_NONE, NULL, 0x0,
190                 "IP address", HFILL }},
191         { &hf_ddtp_status,
192             { "Status", "ddtp.status", FT_UINT32, BASE_DEC, VALS(vals_ddtp_status), 0x0,
193                 "Update reply status", HFILL }}
194     };
195
196     static gint *ett[] = { &ett_ddtp };
197
198     proto_ddtp = proto_register_protocol("Dynamic DNS Tools Protocol",
199                                          "DDTP", "ddtp");
200     proto_register_field_array(proto_ddtp, hf_ddtp, array_length(hf_ddtp));
201     proto_register_subtree_array(ett, array_length(ett));
202 }
203
204 void
205 proto_reg_handoff_ddtp(void)
206 {
207     dissector_handle_t ddtp_handle;
208
209     ddtp_handle = create_dissector_handle(dissect_ddtp, proto_ddtp);
210     dissector_add("udp.port", UDP_PORT_DDTP, ddtp_handle);
211 }