2 * Routines for Appletalk packet disassembly (DDP, currently).
4 * $Id: packet-atalk.c,v 1.19 1999/11/03 06:18:50 guy Exp $
6 * Simon Wilkinson <sxw@dcs.ed.ac.uk>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #ifdef HAVE_SYS_TYPES_H
28 # include <sys/types.h>
34 #include "packet-atalk.h"
36 static int proto_ddp = -1;
37 static int hf_ddp_hopcount = -1;
38 static int hf_ddp_len = -1;
39 static int hf_ddp_checksum = -1;
40 static int hf_ddp_dst_net = -1;
41 static int hf_ddp_src_net = -1;
42 static int hf_ddp_dst_node = -1;
43 static int hf_ddp_src_node = -1;
44 static int hf_ddp_dst_socket = -1;
45 static int hf_ddp_src_socket = -1;
46 static int hf_ddp_type = -1;
48 /* P = Padding, H = Hops, L = Len */
49 #if BYTE_ORDER == BIG_ENDIAN
50 /* PPHHHHLL LLLLLLLL */
51 # define ddp_hops(x) ( ( x >> 10) & 0x3C )
52 # define ddp_len(x) ( x & 0x03ff )
54 /* LLLLLLLL PPHHHHLL*/
55 # define ddp_hops(x) ( x & 0x3C )
56 # define ddp_len(x) ( ntohs(x) & 0x03ff )
58 typedef struct _e_ddp {
59 guint16 hops_len; /* combines pad, hops, and len */
60 guint16 sum,dnet,snet;
66 #define DDP_RTMPDATA 0x01
70 #define DDP_RTMPREQ 0x05
73 #define DDP_HEADER_SIZE 13
76 atalk_addr_to_str(const struct atalk_ddp_addr *addrp)
78 static gchar str[3][14];
81 if (cur == &str[0][0]) {
83 } else if (cur == &str[1][0]) {
89 sprintf(cur, "%u.%u:%u", addrp->net, addrp->node, addrp->port);
93 static const value_string op_vals[] = {
94 {DDP_RTMPDATA, "AppleTalk Routing Table response or data" },
95 {DDP_NBP, "AppleTalk Name Binding Protocol packet"},
96 {DDP_ATP, "AppleTalk Transaction Protocol packet"},
97 {DDP_AEP, "AppleTalk Echo Protocol packet"},
98 {DDP_RTMPREQ, "AppleTalk Routing Table request"},
99 {DDP_ZIP, "AppleTalk Zone Information Protocol packet"},
100 {DDP_ADSP, "AppleTalk Data Stream Protocol"},
105 dissect_ddp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
107 proto_tree *ddp_tree;
109 static struct atalk_ddp_addr src, dst;
111 if (!BYTES_ARE_IN_FRAME(offset, DDP_HEADER_SIZE)) {
112 dissect_data(pd, offset, fd, tree);
116 memcpy(&ddp, &pd[offset], sizeof(e_ddp));
117 ddp.dnet=ntohs(ddp.dnet);
118 ddp.snet=ntohs(ddp.snet);
119 ddp.sum=ntohs(ddp.sum);
122 src.node = ddp.snode;
123 src.port = ddp.sport;
125 dst.node = ddp.dnode;
126 dst.port = ddp.dport;
127 SET_ADDRESS(&pi.net_src, AT_ATALK, sizeof src, (guint8 *)&src);
128 SET_ADDRESS(&pi.src, AT_ATALK, sizeof src, (guint8 *)&src);
129 SET_ADDRESS(&pi.net_dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
130 SET_ADDRESS(&pi.dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
132 if (check_col(fd, COL_PROTOCOL))
133 col_add_str(fd, COL_PROTOCOL, "DDP");
134 if (check_col(fd, COL_INFO))
135 col_add_str(fd, COL_INFO,
136 val_to_str(ddp.type, op_vals, "Unknown DDP protocol (%02x)"));
139 ti = proto_tree_add_item(tree, proto_ddp, offset, DDP_HEADER_SIZE, NULL);
140 ddp_tree = proto_item_add_subtree(ti, ETT_DDP);
141 proto_tree_add_item(ddp_tree, hf_ddp_hopcount, offset, 1,
142 ddp_hops(ddp.hops_len));
143 proto_tree_add_item(ddp_tree, hf_ddp_len, offset, 2,
144 ddp_len(ddp.hops_len));
145 proto_tree_add_item(ddp_tree, hf_ddp_checksum, offset + 2, 2, ddp.sum);
146 proto_tree_add_item(ddp_tree, hf_ddp_dst_net, offset + 4, 2, ddp.dnet);
147 proto_tree_add_item(ddp_tree, hf_ddp_src_net, offset + 6, 2, ddp.snet);
148 proto_tree_add_item(ddp_tree, hf_ddp_dst_node, offset + 8, 1, ddp.dnode);
149 proto_tree_add_item(ddp_tree, hf_ddp_src_node, offset + 9, 1, ddp.snode);
150 proto_tree_add_item(ddp_tree, hf_ddp_dst_socket, offset + 10, 1, ddp.dport);
151 proto_tree_add_item(ddp_tree, hf_ddp_src_socket, offset + 11, 1, ddp.sport);
152 proto_tree_add_item(ddp_tree, hf_ddp_type, offset + 12, 1, ddp.type);
155 offset += DDP_HEADER_SIZE;
157 dissect_data(pd, offset, fd, tree);
161 proto_register_atalk(void)
163 static hf_register_info hf[] = {
165 { "Hop count", "ddp.hopcount", FT_UINT8, BASE_DEC, NULL, 0x0,
169 { "Datagram length", "ddp.len", FT_UINT16, BASE_DEC, NULL, 0x0,
173 { "Checksum", "ddp.checksum", FT_UINT16, BASE_DEC, NULL, 0x0,
177 { "Destination Net", "ddp.dst.net", FT_UINT16, BASE_DEC, NULL, 0x0,
181 { "Source Net", "ddp.src.net", FT_UINT16, BASE_DEC, NULL, 0x0,
185 { "Destination Node", "ddp.dst.node", FT_UINT8, BASE_DEC, NULL, 0x0,
189 { "Source Node", "ddp.src.node", FT_UINT8, BASE_DEC, NULL, 0x0,
192 { &hf_ddp_dst_socket,
193 { "Destination Socket", "ddp.dst.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
196 { &hf_ddp_src_socket,
197 { "Source Socket", "ddp.src.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
201 { "Protocol type", "ddp.type", FT_UINT8, BASE_DEC, VALS(op_vals), 0x0,
205 proto_ddp = proto_register_protocol("Datagram Delivery Protocol", "ddp");
206 proto_register_field_array(proto_ddp, hf, array_length(hf));