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