2 * Routines for Appletalk packet disassembly (DDP, currently).
4 * $Id: packet-atalk.c,v 1.22 1999/11/16 11:42:25 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>
31 #ifdef HAVE_NETINET_IN_H
32 # include <netinet/in.h>
38 #include "packet-atalk.h"
40 static int proto_ddp = -1;
41 static int hf_ddp_hopcount = -1;
42 static int hf_ddp_len = -1;
43 static int hf_ddp_checksum = -1;
44 static int hf_ddp_dst_net = -1;
45 static int hf_ddp_src_net = -1;
46 static int hf_ddp_dst_node = -1;
47 static int hf_ddp_src_node = -1;
48 static int hf_ddp_dst_socket = -1;
49 static int hf_ddp_src_socket = -1;
50 static int hf_ddp_type = -1;
52 static gint ett_ddp = -1;
54 /* P = Padding, H = Hops, L = Len */
55 #if BYTE_ORDER == BIG_ENDIAN
56 /* PPHHHHLL LLLLLLLL */
57 # define ddp_hops(x) ( ( x >> 10) & 0x3C )
58 # define ddp_len(x) ( x & 0x03ff )
60 /* LLLLLLLL PPHHHHLL*/
61 # define ddp_hops(x) ( x & 0x3C )
62 # define ddp_len(x) ( ntohs(x) & 0x03ff )
64 typedef struct _e_ddp {
65 guint16 hops_len; /* combines pad, hops, and len */
66 guint16 sum,dnet,snet;
72 #define DDP_RTMPDATA 0x01
76 #define DDP_RTMPREQ 0x05
79 #define DDP_HEADER_SIZE 13
82 atalk_addr_to_str(const struct atalk_ddp_addr *addrp)
84 static gchar str[3][14];
87 if (cur == &str[0][0]) {
89 } else if (cur == &str[1][0]) {
95 sprintf(cur, "%u.%u:%u", addrp->net, addrp->node, addrp->port);
99 static const value_string op_vals[] = {
100 {DDP_RTMPDATA, "AppleTalk Routing Table response or data" },
101 {DDP_NBP, "AppleTalk Name Binding Protocol packet"},
102 {DDP_ATP, "AppleTalk Transaction Protocol packet"},
103 {DDP_AEP, "AppleTalk Echo Protocol packet"},
104 {DDP_RTMPREQ, "AppleTalk Routing Table request"},
105 {DDP_ZIP, "AppleTalk Zone Information Protocol packet"},
106 {DDP_ADSP, "AppleTalk Data Stream Protocol"},
111 dissect_ddp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
113 proto_tree *ddp_tree;
115 static struct atalk_ddp_addr src, dst;
117 if (!BYTES_ARE_IN_FRAME(offset, DDP_HEADER_SIZE)) {
118 dissect_data(pd, offset, fd, tree);
122 memcpy(&ddp, &pd[offset], sizeof(e_ddp));
123 ddp.dnet=ntohs(ddp.dnet);
124 ddp.snet=ntohs(ddp.snet);
125 ddp.sum=ntohs(ddp.sum);
128 src.node = ddp.snode;
129 src.port = ddp.sport;
131 dst.node = ddp.dnode;
132 dst.port = ddp.dport;
133 SET_ADDRESS(&pi.net_src, AT_ATALK, sizeof src, (guint8 *)&src);
134 SET_ADDRESS(&pi.src, AT_ATALK, sizeof src, (guint8 *)&src);
135 SET_ADDRESS(&pi.net_dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
136 SET_ADDRESS(&pi.dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
138 if (check_col(fd, COL_PROTOCOL))
139 col_add_str(fd, COL_PROTOCOL, "DDP");
140 if (check_col(fd, COL_INFO))
141 col_add_str(fd, COL_INFO,
142 val_to_str(ddp.type, op_vals, "Unknown DDP protocol (%02x)"));
145 ti = proto_tree_add_item(tree, proto_ddp, offset, DDP_HEADER_SIZE, NULL);
146 ddp_tree = proto_item_add_subtree(ti, ett_ddp);
147 proto_tree_add_item(ddp_tree, hf_ddp_hopcount, offset, 1,
148 ddp_hops(ddp.hops_len));
149 proto_tree_add_item(ddp_tree, hf_ddp_len, offset, 2,
150 ddp_len(ddp.hops_len));
151 proto_tree_add_item(ddp_tree, hf_ddp_checksum, offset + 2, 2, ddp.sum);
152 proto_tree_add_item(ddp_tree, hf_ddp_dst_net, offset + 4, 2, ddp.dnet);
153 proto_tree_add_item(ddp_tree, hf_ddp_src_net, offset + 6, 2, ddp.snet);
154 proto_tree_add_item(ddp_tree, hf_ddp_dst_node, offset + 8, 1, ddp.dnode);
155 proto_tree_add_item(ddp_tree, hf_ddp_src_node, offset + 9, 1, ddp.snode);
156 proto_tree_add_item(ddp_tree, hf_ddp_dst_socket, offset + 10, 1, ddp.dport);
157 proto_tree_add_item(ddp_tree, hf_ddp_src_socket, offset + 11, 1, ddp.sport);
158 proto_tree_add_item(ddp_tree, hf_ddp_type, offset + 12, 1, ddp.type);
161 offset += DDP_HEADER_SIZE;
163 dissect_data(pd, offset, fd, tree);
167 proto_register_atalk(void)
169 static hf_register_info hf[] = {
171 { "Hop count", "ddp.hopcount", FT_UINT8, BASE_DEC, NULL, 0x0,
175 { "Datagram length", "ddp.len", FT_UINT16, BASE_DEC, NULL, 0x0,
179 { "Checksum", "ddp.checksum", FT_UINT16, BASE_DEC, NULL, 0x0,
183 { "Destination Net", "ddp.dst.net", FT_UINT16, BASE_DEC, NULL, 0x0,
187 { "Source Net", "ddp.src.net", FT_UINT16, BASE_DEC, NULL, 0x0,
191 { "Destination Node", "ddp.dst.node", FT_UINT8, BASE_DEC, NULL, 0x0,
195 { "Source Node", "ddp.src.node", FT_UINT8, BASE_DEC, NULL, 0x0,
198 { &hf_ddp_dst_socket,
199 { "Destination Socket", "ddp.dst.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
202 { &hf_ddp_src_socket,
203 { "Source Socket", "ddp.src.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
207 { "Protocol type", "ddp.type", FT_UINT8, BASE_DEC, VALS(op_vals), 0x0,
210 static gint *ett[] = {
214 proto_ddp = proto_register_protocol("Datagram Delivery Protocol", "ddp");
215 proto_register_field_array(proto_ddp, hf, array_length(hf));
216 proto_register_subtree_array(ett, array_length(ett));