Use system's version of AM_PATH_GLIB macro.
[metze/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.16 2001/06/18 02:17:45 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 "packet-ddtp.h"
47
48 static int proto_ddtp = -1;
49 static int hf_ddtp_version = -1;
50 static int hf_ddtp_encrypt = -1;
51 static int hf_ddtp_hostid = -1;
52 static int hf_ddtp_msgtype = -1;
53 static int hf_ddtp_opcode = -1;
54 static int hf_ddtp_ipaddr = -1;
55 static int hf_ddtp_status = -1;
56
57 static int ett_ddtp = -1;
58
59 #define UDP_PORT_DDTP   1052
60
61 static const value_string vals_ddtp_version[] = {
62     { DDTP_VERSION_ERROR, "Protocol Error" },
63     { DDTP_VERSION_4,     "4" },
64     { DDTP_VERSION_5,     "5" },
65     { 0, NULL}
66 };
67
68 static const value_string vals_ddtp_encrypt[] = {
69     { DDTP_ENCRYPT_ERROR,     "Encryption Error" },
70     { DDTP_ENCRYPT_PLAINTEXT, "Plain text" },
71     { DDTP_ENCRYPT_BLOWFISH,  "Blowfish" },
72     { 0, NULL}
73 };
74
75 static const value_string vals_ddtp_msgtype[] = {
76     { DDTP_MESSAGE_ERROR, "Message Error" },
77     { DDTP_UPDATE_QUERY,  "Update Query" },
78     { DDTP_UPDATE_REPLY,  "Update Reply" },
79     { DDTP_ALIVE_QUERY,   "Alive Query" },
80     { DDTP_ALIVE_REPLY,   "Alive Reply" },
81     { 0, NULL}
82 };
83
84 static const value_string vals_ddtp_opcode[] = {
85     { DDTP_MARK_ONLINE,  "Mark online" },
86     { DDTP_MARK_OFFLINE, "Mark offline" },
87     { 0, NULL}
88 };
89
90 static const value_string vals_ddtp_status[] = {
91     { DDTP_UPDATE_SUCCEEDED, "Update succeeded" },
92     { DDTP_UPDATE_FAILED,    "Update failed" },
93     { DDTP_INVALID_PASSWORD, "Invalid password" },
94     { DDTP_INVALID_ACCOUNT,  "Invalid account" },
95     { DDTP_INVALID_OPCODE,   "Invalid opcode" },
96     { 0, NULL}
97 };
98
99 static void
100 dissect_ddtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
101 {
102     proto_tree *ddtp_tree = NULL;
103     proto_item *ti;
104
105     if (check_col(pinfo->fd, COL_PROTOCOL)) {
106         /* Indicate what kind of message this is. */
107         col_set_str (pinfo->fd, COL_PROTOCOL, "DDTP");
108     }
109     if (check_col(pinfo->fd, COL_INFO)) {
110         /* In case we throw an exception below. */
111         col_clear (pinfo->fd, COL_INFO);
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     }
122     if (tvb_get_ntohl(tvb, 4) == DDTP_ENCRYPT_PLAINTEXT) {
123         if (tree)
124             proto_tree_add_item(ddtp_tree, hf_ddtp_msgtype, tvb, 12, 4, FALSE);
125         switch (tvb_get_ntohl(tvb, 12)) {
126         case DDTP_MESSAGE_ERROR :
127             if (check_col(pinfo->fd, COL_INFO))
128                 col_set_str (pinfo->fd, COL_INFO, "Message Error");
129             break;
130         case DDTP_UPDATE_QUERY :
131             if (check_col(pinfo->fd, COL_INFO))
132                 col_set_str (pinfo->fd, COL_INFO, "Update Query");
133             if (tree) {
134                 proto_tree_add_item(ddtp_tree, hf_ddtp_opcode, tvb, 16, 4,
135                         FALSE);
136                 proto_tree_add_item(ddtp_tree, hf_ddtp_ipaddr, tvb, 20, 4,
137                         FALSE);
138             }
139             break;
140         case DDTP_UPDATE_REPLY :
141             if (check_col(pinfo->fd, COL_INFO))
142                 col_set_str (pinfo->fd, COL_INFO, "Update Reply");
143             if (tree) {
144                 proto_tree_add_item(ddtp_tree, hf_ddtp_status, tvb, 16, 4,
145                         FALSE);
146             }
147             break;
148         case DDTP_ALIVE_QUERY :
149             if (check_col(pinfo->fd, COL_INFO))
150                 col_set_str (pinfo->fd, COL_INFO, "Alive Query");
151             if (tree) {
152                 proto_tree_add_text(ddtp_tree, tvb, 16, 4, "Dummy : %u",
153                         tvb_get_ntohl(tvb, 16));
154             }
155             break;
156         case DDTP_ALIVE_REPLY :
157             if (check_col(pinfo->fd, COL_INFO))
158                 col_set_str (pinfo->fd, COL_INFO, "Alive Reply");
159             if (tree) {
160                 proto_tree_add_text(ddtp_tree, tvb, 16, 4, "Dummy : %u",
161                         tvb_get_ntohl(tvb, 16));
162             }
163             break;
164         default :
165             if (check_col(pinfo->fd, COL_INFO))
166                 col_set_str (pinfo->fd, COL_INFO, "Unknown type");
167             if (tree) {
168                 proto_tree_add_text(ddtp_tree, tvb, 12, 4, "Unknown type : %u",
169                         tvb_get_ntohl(tvb, 12));
170             }
171         }
172     } else {
173         if (check_col(pinfo->fd, COL_INFO))
174             col_set_str (pinfo->fd, COL_INFO, "Encrypted payload");
175     }
176 }
177
178 void
179 proto_register_ddtp(void)
180 {
181     static hf_register_info hf_ddtp[] = {
182         { &hf_ddtp_version,
183             { "Version", "ddtp.version", FT_UINT32, BASE_DEC, VALS(vals_ddtp_version), 0x0,
184                 "Version", HFILL }},
185         { &hf_ddtp_encrypt,
186             { "Encryption", "ddtp.encrypt", FT_UINT32, BASE_DEC, VALS(vals_ddtp_encrypt), 0x0,
187                 "Encryption type", HFILL }},
188         { &hf_ddtp_hostid,
189             { "Hostid", "ddtp.hostid", FT_UINT32, BASE_DEC, NULL, 0x0,
190                 "Host ID", HFILL }},
191         { &hf_ddtp_msgtype,
192             { "Message type", "ddtp.msgtype", FT_UINT32, BASE_DEC, VALS(vals_ddtp_msgtype), 0x0,
193                 "Message Type", HFILL }},
194         { &hf_ddtp_opcode,
195             { "Opcode", "ddtp.opcode", FT_UINT32, BASE_DEC, VALS(vals_ddtp_opcode), 0x0,
196                 "Update query opcode", HFILL }},
197         { &hf_ddtp_ipaddr,
198             { "IP address", "ddtp.ipaddr", FT_IPv4, BASE_NONE, NULL, 0x0,
199                 "IP address", HFILL }},
200         { &hf_ddtp_status,
201             { "Status", "ddtp.status", FT_UINT32, BASE_DEC, VALS(vals_ddtp_status), 0x0,
202                 "Update reply status", HFILL }}
203     };
204
205     static gint *ett[] = { &ett_ddtp };
206
207     proto_ddtp = proto_register_protocol("Dynamic DNS Tools Protocol",
208                                          "DDTP", "ddtp");
209     proto_register_field_array(proto_ddtp, hf_ddtp, array_length(hf_ddtp));
210     proto_register_subtree_array(ett, array_length(ett));
211 }
212
213 void
214 proto_reg_handoff_ddtp(void)
215 {
216     dissector_add("udp.port", UDP_PORT_DDTP, dissect_ddtp, proto_ddtp);
217 }