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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
/* packet-atalk.c
* Routines for Appletalk packet disassembly (DDP, currently).
*
* $Id: packet-atalk.c,v 1.27 1999/12/09 04:02:50 nneul Exp $
*
* Simon Wilkinson <sxw@dcs.ed.ac.uk>
*
* 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
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#include <glib.h>
#include "packet.h"
#include "packet-atalk.h"
static int proto_ddp = -1;
static int hf_ddp_hopcount = -1;
static int hf_ddp_len = -1;
static int hf_ddp_checksum = -1;
static int hf_ddp_dst_net = -1;
static int hf_ddp_src_net = -1;
static int hf_ddp_dst_node = -1;
static int hf_ddp_src_node = -1;
static int hf_ddp_dst_socket = -1;
static int hf_ddp_src_socket = -1;
static int hf_ddp_type = -1;
static int proto_nbp = -1;
static int hf_nbp_op = -1;
static int hf_nbp_info = -1;
static int hf_nbp_count = -1;
static int hf_nbp_tid = -1;
static int hf_nbp_node_net;
static int hf_nbp_node_port;
static int hf_nbp_node_node;
static int hf_nbp_node_type;
static int hf_nbp_node_name;
static int hf_nbp_node_label;
static gint ett_nbp = -1;
static gint ett_nbp_info = -1;
static gint ett_nbp_node = -1;
static gint ett_ddp = -1;
static gint ett_pstring = -1;
/* P = Padding, H = Hops, L = Len */
#if BYTE_ORDER == BIG_ENDIAN
/* PPHHHHLL LLLLLLLL */
# define ddp_hops(x) ( ( x >> 10) & 0x3C )
# define ddp_len(x) ( x & 0x03ff )
#else
/* LLLLLLLL PPHHHHLL*/
# define ddp_hops(x) ( x & 0x3C )
# define ddp_len(x) ( ntohs(x) & 0x03ff )
#endif
typedef struct _e_ddp {
guint16 hops_len; /* combines pad, hops, and len */
guint16 sum,dnet,snet;
guint8 dnode,snode;
guint8 dport,sport;
guint8 type;
} e_ddp;
#define DDP_RTMPDATA 0x01
#define DDP_NBP 0x02
#define DDP_ATP 0x03
#define DDP_AEP 0x04
#define DDP_RTMPREQ 0x05
#define DDP_ZIP 0x06
#define DDP_ADSP 0x07
#define DDP_HEADER_SIZE 13
#define NBP_LOOKUP 2
gchar *
atalk_addr_to_str(const struct atalk_ddp_addr *addrp)
{
static gchar str[3][14];
static gchar *cur;
if (cur == &str[0][0]) {
cur = &str[1][0];
} else if (cur == &str[1][0]) {
cur = &str[2][0];
} else {
cur = &str[0][0];
}
sprintf(cur, "%u.%u:%u", addrp->net, addrp->node, addrp->port);
return cur;
}
static const value_string op_vals[] = {
{DDP_RTMPDATA, "AppleTalk Routing Table response or data" },
{DDP_NBP, "AppleTalk Name Binding Protocol packet"},
{DDP_ATP, "AppleTalk Transaction Protocol packet"},
{DDP_AEP, "AppleTalk Echo Protocol packet"},
{DDP_RTMPREQ, "AppleTalk Routing Table request"},
{DDP_ZIP, "AppleTalk Zone Information Protocol packet"},
{DDP_ADSP, "AppleTalk Data Stream Protocol"},
{0, NULL}
};
static const value_string nbp_op_vals[] = {
{NBP_LOOKUP, "lookup"},
{0, NULL}
};
int dissect_pascal_string(const u_char *pd, int offset, frame_data *fd,
proto_tree *tree, int hf_index)
{
int len;
char *tmp;
if ( ! BYTES_ARE_IN_FRAME(offset,1) ) {
dissect_data(pd,offset,fd,tree);
return END_OF_FRAME;
}
len = pd[offset];
if ( ! BYTES_ARE_IN_FRAME(offset,len) ) {
dissect_data(pd,offset,fd,tree);
return END_OF_FRAME;
}
offset++;
if ( tree )
{
char *tmp;
proto_tree *item;
proto_tree *subtree;
tmp = g_malloc( len+1 );
memcpy(tmp, &pd[offset], len);
tmp[len] = 0;
item = proto_tree_add_item(tree, hf_index, offset-1, len+1, tmp);
subtree = proto_item_add_subtree(item, ett_pstring);
proto_tree_add_text(subtree, offset-1, 1, "Length: %d", len);
proto_tree_add_text(subtree, offset, len, "Data: %s", tmp);
g_free(tmp);
}
offset += len;
return offset;
}
static void
dissect_rtmp_request(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
dissect_data(pd, offset, fd, tree);
return;
}
static void
dissect_rtmp_data(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
dissect_data(pd, offset, fd, tree);
return;
}
static void
dissect_nbp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
proto_tree *nbp_tree;
proto_tree *nbp_info_tree;
proto_item *ti, *info_item;
guint op, count;
int i;
if (!BYTES_ARE_IN_FRAME(offset, 2)) {
dissect_data(pd, offset, fd, tree);
return;
}
op = pd[offset] >> 4;
count = pd[offset] & 0x0F;
if (check_col(fd, COL_PROTOCOL))
col_add_str(fd, COL_PROTOCOL, "NBP");
if (check_col(fd, COL_INFO))
col_add_fstr(fd, COL_INFO, "Op: %s Count: %d",
val_to_str(op, nbp_op_vals, "unknown (%1x)"), count);
if (tree) {
ti = proto_tree_add_item(tree, proto_nbp, offset, END_OF_FRAME, NULL);
nbp_tree = proto_item_add_subtree(ti, ett_nbp);
info_item = proto_tree_add_item_format(nbp_tree, hf_nbp_info, offset, 1,
pd[offset],
"Info: 0x%01X Operation: %s Count: %d", pd[offset],
val_to_str(op, nbp_op_vals, "unknown"),
count);
nbp_info_tree = proto_item_add_subtree(info_item, ett_nbp_info);
proto_tree_add_item(nbp_info_tree, hf_nbp_op, offset, 1, pd[offset]);
proto_tree_add_item(nbp_info_tree, hf_nbp_count, offset, 1, pd[offset]);
proto_tree_add_item(nbp_tree, hf_nbp_tid, offset+1, 1, pd[offset+1]);
offset += 2;
for (i=0; i<count; i++) {
struct atalk_ddp_addr addr;
proto_tree *node_item,*node_tree;
if ( !BYTES_ARE_IN_FRAME(offset, 6) ) {
dissect_data(pd,offset,fd,nbp_tree);
return;
}
node_item = proto_tree_add_text(nbp_tree, offset, 4,
"Node %d", i+1);
node_tree = proto_item_add_subtree(node_item, ett_nbp_node);
addr.net = pntohs(&pd[offset]);
addr.node = pd[offset+2];
addr.port = pd[offset+3];
/* note, this is probably wrong, I need to look at my info at work
tomorrow to straighten it out */
proto_tree_add_item(node_tree, hf_nbp_node_net, offset, 2, addr.net);
offset += 2;
proto_tree_add_item(node_tree, hf_nbp_node_node, offset, 1, addr.node);
offset++;
proto_tree_add_item(node_tree, hf_nbp_node_port, offset, 1, addr.port);
offset++;
offset++; /* skip a null */
offset = dissect_pascal_string(pd,offset,fd,node_tree,hf_nbp_node_type);
offset = dissect_pascal_string(pd,offset,fd,node_tree,hf_nbp_node_name);
offset = dissect_pascal_string(pd,offset,fd,node_tree,hf_nbp_node_label);
}
}
return;
}
void
dissect_ddp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
e_ddp ddp;
proto_tree *ddp_tree;
proto_item *ti;
static struct atalk_ddp_addr src, dst;
if (!BYTES_ARE_IN_FRAME(offset, DDP_HEADER_SIZE)) {
dissect_data(pd, offset, fd, tree);
return;
}
memcpy(&ddp, &pd[offset], sizeof(e_ddp));
ddp.dnet=ntohs(ddp.dnet);
ddp.snet=ntohs(ddp.snet);
ddp.sum=ntohs(ddp.sum);
src.net = ddp.snet;
src.node = ddp.snode;
src.port = ddp.sport;
dst.net = ddp.dnet;
dst.node = ddp.dnode;
dst.port = ddp.dport;
SET_ADDRESS(&pi.net_src, AT_ATALK, sizeof src, (guint8 *)&src);
SET_ADDRESS(&pi.src, AT_ATALK, sizeof src, (guint8 *)&src);
SET_ADDRESS(&pi.net_dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
SET_ADDRESS(&pi.dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
if (check_col(fd, COL_PROTOCOL))
col_add_str(fd, COL_PROTOCOL, "DDP");
if (check_col(fd, COL_INFO))
col_add_str(fd, COL_INFO,
val_to_str(ddp.type, op_vals, "Unknown DDP protocol (%02x)"));
if (tree) {
ti = proto_tree_add_item(tree, proto_ddp, offset, DDP_HEADER_SIZE, NULL);
ddp_tree = proto_item_add_subtree(ti, ett_ddp);
proto_tree_add_item(ddp_tree, hf_ddp_hopcount, offset, 1,
ddp_hops(ddp.hops_len));
proto_tree_add_item(ddp_tree, hf_ddp_len, offset, 2,
ddp_len(ddp.hops_len));
proto_tree_add_item(ddp_tree, hf_ddp_checksum, offset + 2, 2, ddp.sum);
proto_tree_add_item(ddp_tree, hf_ddp_dst_net, offset + 4, 2, ddp.dnet);
proto_tree_add_item(ddp_tree, hf_ddp_src_net, offset + 6, 2, ddp.snet);
proto_tree_add_item(ddp_tree, hf_ddp_dst_node, offset + 8, 1, ddp.dnode);
proto_tree_add_item(ddp_tree, hf_ddp_src_node, offset + 9, 1, ddp.snode);
proto_tree_add_item(ddp_tree, hf_ddp_dst_socket, offset + 10, 1, ddp.dport);
proto_tree_add_item(ddp_tree, hf_ddp_src_socket, offset + 11, 1, ddp.sport);
proto_tree_add_item(ddp_tree, hf_ddp_type, offset + 12, 1, ddp.type);
}
offset += DDP_HEADER_SIZE;
switch ( ddp.type ) {
case DDP_NBP:
dissect_nbp(pd, offset, fd, tree);
break;
case DDP_RTMPREQ:
dissect_rtmp_request(pd, offset, fd, tree);
break;
case DDP_RTMPDATA:
dissect_rtmp_data(pd, offset, fd, tree);
break;
default:
dissect_data(pd, offset, fd, tree);
break;
}
}
void
proto_register_atalk(void)
{
static hf_register_info hf_ddp[] = {
{ &hf_ddp_hopcount,
{ "Hop count", "ddp.hopcount", FT_UINT8, BASE_DEC, NULL, 0x0,
"" }},
{ &hf_ddp_len,
{ "Datagram length", "ddp.len", FT_UINT16, BASE_DEC, NULL, 0x0,
"" }},
{ &hf_ddp_checksum,
{ "Checksum", "ddp.checksum", FT_UINT16, BASE_DEC, NULL, 0x0,
"" }},
{ &hf_ddp_dst_net,
{ "Destination Net", "ddp.dst.net", FT_UINT16, BASE_DEC, NULL, 0x0,
"" }},
{ &hf_ddp_src_net,
{ "Source Net", "ddp.src.net", FT_UINT16, BASE_DEC, NULL, 0x0,
"" }},
{ &hf_ddp_dst_node,
{ "Destination Node", "ddp.dst.node", FT_UINT8, BASE_DEC, NULL, 0x0,
"" }},
{ &hf_ddp_src_node,
{ "Source Node", "ddp.src.node", FT_UINT8, BASE_DEC, NULL, 0x0,
"" }},
{ &hf_ddp_dst_socket,
{ "Destination Socket", "ddp.dst.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
"" }},
{ &hf_ddp_src_socket,
{ "Source Socket", "ddp.src.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
"" }},
{ &hf_ddp_type,
{ "Protocol type", "ddp.type", FT_UINT8, BASE_DEC, VALS(op_vals), 0x0,
"" }},
};
static hf_register_info hf_nbp[] = {
{ &hf_nbp_op,
{ "Operation", "nbp.op", FT_UINT8, BASE_DEC,
VALS(nbp_op_vals), 0xF0, "Operation" }},
{ &hf_nbp_info,
{ "Info", "nbp.info", FT_UINT8, BASE_HEX,
NULL, 0x0, "Info" }},
{ &hf_nbp_count,
{ "Count", "nbp.count", FT_UINT8, BASE_DEC,
NULL, 0x0F, "Count" }},
{ &hf_nbp_node_net,
{ "Network", "nbp.net", FT_UINT16, BASE_DEC,
NULL, 0x0, "Network" }},
{ &hf_nbp_node_node,
{ "Node", "nbp.node", FT_UINT8, BASE_DEC,
NULL, 0x0, "Node" }},
{ &hf_nbp_node_port,
{ "Port", "nbp.port", FT_UINT8, BASE_DEC,
NULL, 0x0, "Port" }},
{ &hf_nbp_node_name,
{ "Name", "nbp.name", FT_STRING, BASE_DEC,
NULL, 0x0, "Name" }},
{ &hf_nbp_node_type,
{ "Type", "nbp.type", FT_STRING, BASE_DEC,
NULL, 0x0, "Type" }},
{ &hf_nbp_node_label,
{ "Label", "nbp.label", FT_STRING, BASE_DEC,
NULL, 0x0, "Label" }},
{ &hf_nbp_tid,
{ "Transaction ID", "nbp.tid", FT_UINT8, BASE_DEC,
NULL, 0x0, "Transaction ID" }}
};
static gint *ett[] = {
&ett_ddp,
&ett_nbp,
&ett_nbp_info,
&ett_nbp_node,
&ett_pstring
};
proto_ddp = proto_register_protocol("Datagram Delivery Protocol", "ddp");
proto_register_field_array(proto_ddp, hf_ddp, array_length(hf_ddp));
proto_nbp = proto_register_protocol("Name Binding Protocol", "nbp");
proto_register_field_array(proto_nbp, hf_nbp, array_length(hf_nbp));
proto_register_subtree_array(ett, array_length(ett));
}
|