2 * Routines for NetBIOS over IPX packet disassembly
3 * Gilbert Ramirez <gram@verdict.uthscsa.edu>
5 * $Id: packet-nbipx.c,v 1.12 1999/09/03 00:24:40 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
37 #include "packet-ipx.h" /* for ipxnet_to_string() */
38 #include "packet-netbios.h"
40 static int proto_nbipx = -1;
48 nbipx_ns(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
49 enum nbipx_protocol nbipx, int max_data);
51 dissect_nbipx_dg(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
54 /* There is no RFC or public specification of Netware or Microsoft
55 * NetBIOS over IPX packets. I have had to decode the protocol myself,
56 * so there are holes and perhaps errors in this code. (gram)
58 * A list of "NovelNetBIOS" packet types can be found at
60 * http://www.protocols.com/pbook/novel.htm#NetBIOS
62 * and at least some of those packet types appear to match what's in
65 * Note, however, that the offset of the packet type in an NBIPX packet
66 * *DEPENDS ON THE PACKET TYPE*; "Find name" and "Name recognized" have
67 * it at one offset, "Directed datagram" has it at another. Does the
68 * NBIPX code base it on the length, or what? Non-broadcast directed
69 * datagram packets have an IPX type of "IPX", just as "Find name" and
70 * "Name recognized" do.... For now, we base it on the length.
72 #define NBIPX_FIND_NAME 1
73 #define NBIPX_NAME_RECOGNIZED 2
74 #define NBIPX_CHECK_NAME 3
75 #define NBIPX_NAME_IN_USE 4
76 #define NBIPX_DEREGISTER_NAME 5
77 #define NBIPX_SESSION_DATA 6
78 #define NBIPX_SESSION_END 7
79 #define NBIPX_SESSION_END_ACK 8
80 #define NBIPX_STATUS_QUERY 9
81 #define NBIPX_STATUS_RESPONSE 10
82 #define NBIPX_DIRECTED_DATAGRAM 11
84 static const value_string nbipx_data_stream_type_vals[] = {
85 {NBIPX_FIND_NAME, "Find name"},
86 {NBIPX_NAME_RECOGNIZED, "Name recognized"},
87 {NBIPX_CHECK_NAME, "Check name"},
88 {NBIPX_NAME_IN_USE, "Name in use"},
89 {NBIPX_DEREGISTER_NAME, "Deregister name"},
90 {NBIPX_SESSION_DATA, "Session data"},
91 {NBIPX_SESSION_END, "Session end"},
92 {NBIPX_SESSION_END_ACK, "Session end ACK"},
93 {NBIPX_STATUS_QUERY, "Status query"},
94 {NBIPX_STATUS_RESPONSE, "Status response"},
95 {NBIPX_DIRECTED_DATAGRAM, "Directed datagram"},
99 #define NWLINK_NAME_QUERY 1
101 #define NWLINK_NETBIOS_DATAGRAM 3
103 static const value_string nwlink_data_stream_type_vals[] = {
104 {NWLINK_NAME_QUERY, "Name query"},
106 {NWLINK_NETBIOS_DATAGRAM, "NetBIOS datagram"},
112 dissect_nbipx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
114 int max_data = pi.captured_len - offset;
117 * As said above, we look at the length of the packet to decide
118 * whether to treat it as a name-service packet or a datagram
119 * (the packet type would tell us, but it's at a *DIFFERENT
120 * LOCATION* in different types of packet...).
122 if (END_OF_FRAME == 50)
123 nbipx_ns(pd, offset, fd, tree, NETBIOS_NETWARE, max_data);
125 dissect_nbipx_dg(pd, offset, fd, tree, max_data);
129 dissect_nwlink_dg(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
131 int max_data = pi.captured_len - offset;
133 nbipx_ns(pd, offset, fd, tree, NETBIOS_NWLINK, max_data);
138 nbipx_ns(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
139 enum nbipx_protocol nbipx, int max_data)
141 proto_tree *nbipx_tree;
147 char name[(NETBIOS_NAME_LEN - 1)*4 + 1];
149 char node_name[(NETBIOS_NAME_LEN - 1)*4 + 1];
150 int node_name_type = 0;
154 if (nbipx == NETBIOS_NETWARE) {
162 name_flags = pd[offset+32];
163 packet_type = pd[offset+33];
164 name_type = get_netbios_name(pd, offset+name_offset, name);
166 if (nbipx == NETBIOS_NWLINK)
167 node_name_type = get_netbios_name(pd, offset+52, node_name);
169 if (check_col(fd, COL_PROTOCOL)) {
170 if (nbipx == NETBIOS_NETWARE) {
171 col_add_str(fd, COL_PROTOCOL, "NBIPX");
174 col_add_str(fd, COL_PROTOCOL, "NWLink");
178 if (check_col(fd, COL_INFO)) {
179 if (nbipx == NETBIOS_NETWARE) {
180 switch (packet_type) {
181 case NBIPX_FIND_NAME:
182 case NBIPX_NAME_RECOGNIZED:
183 case NBIPX_CHECK_NAME:
184 case NBIPX_NAME_IN_USE:
185 case NBIPX_DEREGISTER_NAME:
186 col_add_fstr(fd, COL_INFO, "%s %s<%02x>",
187 val_to_str(packet_type, nbipx_data_stream_type_vals, "Unknown"),
192 col_add_fstr(fd, COL_INFO, "%s",
193 val_to_str(packet_type, nbipx_data_stream_type_vals, "Unknown"));
198 switch (packet_type) {
199 case NWLINK_NAME_QUERY:
200 col_add_fstr(fd, COL_INFO, "Name Query for %s<%02x>",
206 col_add_fstr(fd, COL_INFO, "SMB over NBIPX");
209 case NWLINK_NETBIOS_DATAGRAM:
210 /* Datagram? (Where did we see this?) */
211 col_add_fstr(fd, COL_INFO, "NetBIOS datagram over NBIPX");
215 col_add_str(fd, COL_INFO, "NetBIOS over IPX (NWLink)");
222 ti = proto_tree_add_item(tree, proto_nbipx, offset, 68, NULL);
223 nbipx_tree = proto_item_add_subtree(ti, ETT_NBIPX);
225 if (nbipx == NETBIOS_NETWARE) {
226 proto_tree_add_text(nbipx_tree, offset+33, 1,
227 "Packet Type: %s (%02X)",
228 val_to_str(packet_type, nbipx_data_stream_type_vals, "Unknown"),
231 proto_tree_add_text(nbipx_tree, offset+33, 1,
232 "Packet Type: %s (%02X)",
233 val_to_str(packet_type, nwlink_data_stream_type_vals, "Unknown"),
237 /* Eight routers are listed */
238 for (i = 0; i < 8; i++) {
239 rtr_offset = offset + (i << 2);
240 memcpy(&router[i], &pd[rtr_offset], 4);
241 if (router[i] != 0) {
242 proto_tree_add_text(nbipx_tree, rtr_offset, 4, "IPX Network: %s",
243 ipxnet_to_string((guint8*)&router[i]));
247 proto_tree_add_text(nbipx_tree, offset+32, 1, "Name Type: %02X",
250 if (nbipx == NETBIOS_NETWARE) {
251 netbios_add_name("Name", &pd[offset], offset,
252 name_offset, nbipx_tree);
255 netbios_add_name("Group name", &pd[offset], offset,
256 name_offset, nbipx_tree);
257 netbios_add_name("Node name", &pd[offset], offset,
262 if (nbipx == NETBIOS_NWLINK) {
263 switch (packet_type) {
265 case NWLINK_NETBIOS_DATAGRAM:
266 dissect_smb(pd, offset + 68, fd, tree, max_data - 68);
270 dissect_data(pd, offset + 68, fd, tree);
277 dissect_nbipx_dg(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
280 proto_tree *nbipx_tree;
283 if (check_col(fd, COL_PROTOCOL))
284 col_add_str(fd, COL_PROTOCOL, "NetBIOS");
286 if (check_col(fd, COL_INFO))
287 col_add_fstr(fd, COL_INFO, "NetBIOS datagram over NBIPX");
290 ti = proto_tree_add_item(tree, proto_nbipx, offset, 68, NULL);
291 nbipx_tree = proto_item_add_subtree(ti, ETT_NBIPX);
293 proto_tree_add_text(nbipx_tree, offset+1, 1,
294 "Packet Type: %s (%02X)",
295 val_to_str(pd[offset+1], nbipx_data_stream_type_vals, "Unknown"),
297 proto_tree_add_text(nbipx_tree, offset, 1,
298 "Connection control: 0x%02x", pd[offset]);
299 netbios_add_name("Receiver's Name", &pd[offset],
300 offset, 2, nbipx_tree);
301 netbios_add_name("Sender's Name", &pd[offset],
302 offset, 2+16, nbipx_tree);
304 dissect_smb(pd, offset+2+16+16, fd, tree, max_data - 2+16+16);
309 proto_register_nbipx(void)
311 /* static hf_register_info hf[] = {
313 { "Name", "nbipx.abbreviation", TYPE, VALS_POINTER }},
316 proto_nbipx = proto_register_protocol("NetBIOS over IPX", "nbipx");
317 /* proto_register_field_array(proto_nbipx, hf, array_length(hf));*/