aboutsummaryrefslogtreecommitdiffstats
path: root/packet-dhis.c
blob: f746bbeae7af91aa9b6ba9df1b2e54e4a27e698a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* packet-dhis.c
 * Routines for DHIS (Dynamic Host Information Services) packet disassembly
 * see http://dhis.sourceforge.net/
 * Olivier Abad <abad@daba.dhis.net>
 *
 * $Id: packet-dhis.c,v 1.2 2000/02/23 22:41:15 oabad Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@zing.org>
 * Copyright 2000
 *
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

/*#include <string.h>
#include <ctype.h>
#include <time.h>*/

#include <glib.h>
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#include "packet.h"
#include "dfilter.h"
#include "packet-dhis.h"

static int proto_dhis = -1;
static int hf_dhis_version = -1;
static int hf_dhis_encrypt = -1;
static int hf_dhis_hostid = -1;
static int hf_dhis_msgtype = -1;
static int hf_dhis_opcode = -1;
static int hf_dhis_ipaddr = -1;
static int hf_dhis_status = -1;

static int ett_dhis = -1;

static const value_string vals_dhis_version[] = {
    { DHIS_VERSION_ERROR, "Protocol Error" },
    { DHIS_VERSION_4,     "4" },
    { DHIS_VERSION_5,     "5" },
    { 0, NULL}
};

static const value_string vals_dhis_encrypt[] = {
    { DHIS_ENCRYPT_ERROR,     "Encryption Error" },
    { DHIS_ENCRYPT_PLAINTEXT, "Plain text" },
    { DHIS_ENCRYPT_BLOWFISH,  "Blowfish" },
    { 0, NULL}
};

static const value_string vals_dhis_msgtype[] = {
    { DHIS_MESSAGE_ERROR, "Message Error" },
    { DHIS_UPDATE_QUERY,  "Update Query" },
    { DHIS_UPDATE_REPLY,  "Update Reply" },
    { DHIS_ALIVE_QUERY,   "Alive Query" },
    { DHIS_ALIVE_REPLY,   "Alive Reply" },
    { 0, NULL}
};

static const value_string vals_dhis_opcode[] = {
    { DHIS_MARK_ONLINE,  "Mark online" },
    { DHIS_MARK_OFFLINE, "Mark offline" },
    { 0, NULL}
};

static const value_string vals_dhis_status[] = {
    { DHIS_UPDATE_SUCCEEDED, "Update succeeded" },
    { DHIS_UPDATE_FAILED,    "Update failed" },
    { DHIS_INVALID_PASSWORD, "Invalid password" },
    { DHIS_INVALID_ACCOUNT,  "Invalid account" },
    { DHIS_INVALID_OPCODE,   "Invalid opcode" },
    { 0, NULL}
};

void
dissect_dhis(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
{

    proto_tree	    *dhis_tree;
    proto_item	    *ti;

    if (check_col(fd, COL_PROTOCOL)) {
	/*
	 * Indicate what kind of message this is.
	 */
    	col_add_str (fd, COL_PROTOCOL, "DHIS");
    }
    if (tree) {
	ti = proto_tree_add_item(tree, proto_dhis, offset,
		END_OF_FRAME - offset, NULL);
	dhis_tree = proto_item_add_subtree(ti, ett_dhis);

	if (!BYTES_ARE_IN_FRAME(offset, 4)) {
	    proto_tree_add_text(dhis_tree, offset, END_OF_FRAME-offset, "Frame too short");
	    return;
	}
	proto_tree_add_item(dhis_tree, hf_dhis_version, offset, 4, pntohl(pd+offset));
	offset += 4;
	if (!BYTES_ARE_IN_FRAME(offset, 4)) {
	    proto_tree_add_text(dhis_tree, offset, END_OF_FRAME-offset, "Frame too short");
	    return;
	}
	proto_tree_add_item(dhis_tree, hf_dhis_encrypt, offset, 4, pntohl(pd+offset));
	if (!BYTES_ARE_IN_FRAME(offset+4, 4)) {
	    proto_tree_add_text(dhis_tree, offset+4, END_OF_FRAME-offset-4, "Frame too short");
	    return;
	}
	proto_tree_add_item(dhis_tree, hf_dhis_hostid, offset+4, 4, pntohl(pd+offset+4));
	if (pntohl(pd+offset) == DHIS_ENCRYPT_PLAINTEXT) {
	    offset += 8;
	    if (!BYTES_ARE_IN_FRAME(offset, 4)) {
		proto_tree_add_text(dhis_tree, offset, END_OF_FRAME-offset, "Frame too short");
		return;
	    }
	    proto_tree_add_item(dhis_tree, hf_dhis_msgtype, offset, 4, pntohl(pd+offset));
	    switch (pntohl(pd+offset)) {
	    case DHIS_MESSAGE_ERROR :
		offset += 4;
		if (check_col(fd, COL_INFO)) col_add_str (fd, COL_INFO, "Message Error");
		break;
	    case DHIS_UPDATE_QUERY :
		offset += 4;
		if (check_col(fd, COL_INFO)) col_add_str (fd, COL_INFO, "Update Query");
		if (!BYTES_ARE_IN_FRAME(offset, 4)) {
		    proto_tree_add_text(dhis_tree, offset, END_OF_FRAME-offset, "Frame too short");
		    return;
		}
		proto_tree_add_item(dhis_tree, hf_dhis_opcode, offset, 4, pntohl(pd+offset));
		offset += 4;
		if (!BYTES_ARE_IN_FRAME(offset, 4)) {
		    proto_tree_add_text(dhis_tree, offset, END_OF_FRAME-offset, "Frame too short");
		    return;
		}
		proto_tree_add_item(dhis_tree, hf_dhis_ipaddr, offset, 4, pntohl(pd+offset));
		break;
	    case DHIS_UPDATE_REPLY :
		offset += 4;
		if (check_col(fd, COL_INFO)) col_add_str (fd, COL_INFO, "Update Reply");
		if (!BYTES_ARE_IN_FRAME(offset, 4)) {
		    proto_tree_add_text(dhis_tree, offset, END_OF_FRAME-offset, "Frame too short");
		    return;
		}
		proto_tree_add_item(dhis_tree, hf_dhis_status, offset, 4, pntohl(pd+offset));
		break;
	    case DHIS_ALIVE_QUERY :
		offset += 4;
		if (check_col(fd, COL_INFO)) col_add_str (fd, COL_INFO, "Alive Query");
		if (!BYTES_ARE_IN_FRAME(offset, 4)) {
		    proto_tree_add_text(dhis_tree, offset, END_OF_FRAME-offset, "Frame too short");
		    return;
		}
		proto_tree_add_text(dhis_tree, offset, 4, "Dummy : %u", pntohl(pd+offset));
		break;
	    case DHIS_ALIVE_REPLY :
		offset += 4;
		if (check_col(fd, COL_INFO)) col_add_str (fd, COL_INFO, "Alive Reply");
		if (!BYTES_ARE_IN_FRAME(offset, 4)) {
		    proto_tree_add_text(dhis_tree, offset, END_OF_FRAME-offset, "Frame too short");
		    return;
		}
		proto_tree_add_text(dhis_tree, offset, 4, "Dummy : %u", pntohl(pd+offset));
		break;
	    default :
		if (check_col(fd, COL_INFO)) col_add_str (fd, COL_INFO, "Unknwon type");
		if (!BYTES_ARE_IN_FRAME(offset, 4)) {
		    proto_tree_add_text(dhis_tree, offset, END_OF_FRAME-offset, "Frame too short");
		    return;
		}
		proto_tree_add_text(dhis_tree, offset, 4, "Unknown type : %u", pntohl(pd+offset));
	    }
	}
   }
}

void
proto_register_dhis(void)
{
    static hf_register_info hf_dhis[] = {
	{ &hf_dhis_version,
	    { "Version", "dhis.version", FT_UINT32, BASE_DEC, VALS(vals_dhis_version), 0x0,
		"Version" } },
	{ &hf_dhis_encrypt,
	    { "Encryption", "dhis.encrypt", FT_UINT32, BASE_DEC, VALS(vals_dhis_encrypt), 0x0,
		"Encryption type" } },
	{ &hf_dhis_hostid,
	    { "Hostid", "dhis.hostid", FT_UINT32, BASE_DEC, NULL, 0x0,
		"Host ID" } },
	{ &hf_dhis_msgtype,
	    { "Message type", "dhis.msgtype", FT_UINT32, BASE_DEC, VALS(vals_dhis_msgtype), 0x0,
		"Message Type" } },
	{ &hf_dhis_opcode,
	    { "Opcode", "dhis.opcode", FT_UINT32, BASE_DEC, VALS(vals_dhis_opcode), 0x0,
		"Update query opcode" } },
	{ &hf_dhis_ipaddr,
	    { "IP addres", "dhis.ipaddr", FT_IPv4, BASE_NONE, NULL, 0x0,
		"IP address" } },
	{ &hf_dhis_status,
	    { "Status", "dhis.status", FT_UINT32, BASE_DEC, VALS(vals_dhis_status), 0x0,
		"Update reply status" } }
    };

    static gint *ett[] = { &ett_dhis };

    proto_dhis = proto_register_protocol("Dynamic Host Information Service", "dhis");
    proto_register_field_array(proto_dhis, hf_dhis, array_length(hf_dhis));
    proto_register_subtree_array(ett, array_length(ett));
}