2 * Routines for NetBIOS over IPX packet disassembly
3 * Gilbert Ramirez <gram@xiexie.org>
5 * $Id: packet-nbipx.c,v 1.27 2000/11/16 07:35:38 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"
38 #include "packet-netbios.h"
39 #include "packet-smb.h"
41 static int proto_nbipx = -1;
43 static gint ett_nbipx = -1;
44 static gint ett_nbipx_name_type_flags = -1;
52 dissect_nbipx_ns(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
55 dissect_nbipx_dg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
57 /* There is no RFC or public specification of Netware or Microsoft
58 * NetBIOS over IPX packets. I have had to decode the protocol myself,
59 * so there are holes and perhaps errors in this code. (gram)
61 * A list of "NovelNetBIOS" packet types can be found at
63 * http://www.protocols.com/pbook/novel.htm#NetBIOS
65 * and at least some of those packet types appear to match what's in
68 * Note, however, that the offset of the packet type in an NBIPX packet
69 * *DEPENDS ON THE PACKET TYPE*; "Find name" and "Name recognized" have
70 * it at one offset, "Directed datagram" has it at another. Does the
71 * NBIPX code base it on the length, or what? Non-broadcast directed
72 * datagram packets have an IPX type of "IPX", just as "Find name" and
73 * "Name recognized" do.... For now, we base it on the length.
75 #define NBIPX_FIND_NAME 1
76 #define NBIPX_NAME_RECOGNIZED 2
77 #define NBIPX_CHECK_NAME 3
78 #define NBIPX_NAME_IN_USE 4
79 #define NBIPX_DEREGISTER_NAME 5
80 #define NBIPX_SESSION_DATA 6
81 #define NBIPX_SESSION_END 7
82 #define NBIPX_SESSION_END_ACK 8
83 #define NBIPX_STATUS_QUERY 9
84 #define NBIPX_STATUS_RESPONSE 10
85 #define NBIPX_DIRECTED_DATAGRAM 11
87 static const value_string nbipx_data_stream_type_vals[] = {
88 {NBIPX_FIND_NAME, "Find name"},
89 {NBIPX_NAME_RECOGNIZED, "Name recognized"},
90 {NBIPX_CHECK_NAME, "Check name"},
91 {NBIPX_NAME_IN_USE, "Name in use"},
92 {NBIPX_DEREGISTER_NAME, "Deregister name"},
93 {NBIPX_SESSION_DATA, "Session data"},
94 {NBIPX_SESSION_END, "Session end"},
95 {NBIPX_SESSION_END_ACK, "Session end ACK"},
96 {NBIPX_STATUS_QUERY, "Status query"},
97 {NBIPX_STATUS_RESPONSE, "Status response"},
98 {NBIPX_DIRECTED_DATAGRAM, "Directed datagram"},
102 #define NWLINK_NAME_QUERY 1
104 #define NWLINK_NETBIOS_DATAGRAM 3
106 static const value_string nwlink_data_stream_type_vals[] = {
107 {NWLINK_NAME_QUERY, "Name query"},
109 {NWLINK_NETBIOS_DATAGRAM, "NetBIOS datagram"},
115 dissect_nbipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
117 CHECK_DISPLAY_AS_DATA(proto_nbipx, tvb, pinfo, tree);
119 pinfo->current_proto = "NBIPX";
121 if (check_col(pinfo->fd, COL_PROTOCOL))
122 col_add_str(pinfo->fd, COL_PROTOCOL, "NBIPX");
125 * As said above, we look at the length of the packet to decide
126 * whether to treat it as a name-service packet or a datagram
127 * (the packet type would tell us, but it's at a *DIFFERENT
128 * LOCATION* in different types of packet...).
130 if (tvb_reported_length(tvb) == 50)
131 dissect_nbipx_ns(tvb, pinfo, tree);
133 dissect_nbipx_dg(tvb, pinfo, tree);
137 add_routers(proto_tree *tree, tvbuff_t *tvb, int offset)
143 /* Eight routers are listed */
144 for (i = 0; i < 8; i++) {
145 rtr_offset = offset + (i << 2);
146 tvb_memcpy(tvb, (guint8 *)&router, rtr_offset, 4);
148 proto_tree_add_text(tree, tvb, rtr_offset, 4,
150 ipxnet_to_string((guint8*)&router));
156 dissect_nbipx_ns(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
158 proto_tree *nbipx_tree;
162 guint8 name_type_flag;
163 proto_tree *name_type_flag_tree;
165 char name[(NETBIOS_NAME_LEN - 1)*4 + 1];
168 name_type_flag = tvb_get_guint8(tvb, offset+32);
169 packet_type = tvb_get_guint8(tvb, offset+33);
170 name_type = get_netbios_name(tvb, offset+34, name);
172 if (check_col(pinfo->fd, COL_INFO)) {
173 switch (packet_type) {
174 case NBIPX_FIND_NAME:
175 case NBIPX_NAME_RECOGNIZED:
176 case NBIPX_CHECK_NAME:
177 case NBIPX_NAME_IN_USE:
178 case NBIPX_DEREGISTER_NAME:
179 col_add_fstr(pinfo->fd, COL_INFO, "%s %s<%02x>",
180 val_to_str(packet_type, nbipx_data_stream_type_vals, "Unknown"),
185 col_add_fstr(pinfo->fd, COL_INFO, "%s",
186 val_to_str(packet_type, nbipx_data_stream_type_vals, "Unknown"));
192 ti = proto_tree_add_item(tree, proto_nbipx, tvb, offset, 50,
194 nbipx_tree = proto_item_add_subtree(ti, ett_nbipx);
196 add_routers(nbipx_tree, tvb, offset);
198 tf = proto_tree_add_text(nbipx_tree, tvb, offset+32, 1,
199 "Name type flag: 0x%02x", name_type_flag);
200 name_type_flag_tree = proto_item_add_subtree(tf,
201 ett_nbipx_name_type_flags);
202 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
204 decode_boolean_bitfield(name_type_flag, 0x80, 8,
205 "Group name", "Unique name"));
206 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
208 decode_boolean_bitfield(name_type_flag, 0x40, 8,
209 "Name in use", "Name not used"));
210 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
212 decode_boolean_bitfield(name_type_flag, 0x04, 8,
213 "Name registered", "Name not registered"));
214 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
216 decode_boolean_bitfield(name_type_flag, 0x02, 8,
217 "Name duplicated", "Name not duplicated"));
218 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
220 decode_boolean_bitfield(name_type_flag, 0x01, 8,
221 "Name deregistered", "Name not deregistered"));
223 proto_tree_add_text(nbipx_tree, tvb, offset+33, 1,
224 "Packet Type: %s (%02X)",
225 val_to_str(packet_type, nbipx_data_stream_type_vals, "Unknown"),
228 netbios_add_name("Name", tvb, offset + 34, nbipx_tree);
233 dissect_nbipx_dg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
235 proto_tree *nbipx_tree;
240 const guint8 *next_pd;
243 if (check_col(pinfo->fd, COL_INFO))
244 col_add_fstr(pinfo->fd, COL_INFO, "NetBIOS datagram over NBIPX");
247 ti = proto_tree_add_item(tree, proto_nbipx, tvb, offset,
248 2+NETBIOS_NAME_LEN+NETBIOS_NAME_LEN, FALSE);
249 nbipx_tree = proto_item_add_subtree(ti, ett_nbipx);
251 proto_tree_add_text(nbipx_tree, tvb, offset, 1,
252 "Connection control: 0x%02x", tvb_get_guint8(tvb, offset));
255 packet_type = tvb_get_guint8(tvb, offset);
256 proto_tree_add_text(nbipx_tree, tvb, offset, 1,
257 "Packet Type: %s (%02X)",
258 val_to_str(packet_type, nbipx_data_stream_type_vals, "Unknown"),
262 if (!netbios_add_name("Receiver's Name", tvb, offset,
265 offset += NETBIOS_NAME_LEN;
267 if (!netbios_add_name("Sender's Name", tvb, offset,
270 offset += NETBIOS_NAME_LEN;
272 if (tvb_offset_exists(tvb, offset)) {
273 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
274 tvb_compat(next_tvb, &next_pd, &next_offset);
275 dissect_smb(next_pd, next_offset, pinfo->fd, tree,
276 tvb_length(next_tvb));
282 dissect_nwlink_dg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
284 proto_tree *nbipx_tree;
288 guint8 name_type_flag;
289 proto_tree *name_type_flag_tree;
291 char name[(NETBIOS_NAME_LEN - 1)*4 + 1];
293 char node_name[(NETBIOS_NAME_LEN - 1)*4 + 1];
294 int node_name_type = 0;
296 const guint8 *next_pd;
299 name_type_flag = tvb_get_guint8(tvb, offset+32);
300 packet_type = tvb_get_guint8(tvb, offset+33);
301 name_type = get_netbios_name(tvb, offset+36, name);
302 node_name_type = get_netbios_name(tvb, offset+52, node_name);
304 if (check_col(pinfo->fd, COL_PROTOCOL))
305 col_add_str(pinfo->fd, COL_PROTOCOL, "NWLink");
307 if (check_col(pinfo->fd, COL_INFO)) {
309 * XXX - Microsoft Network Monitor thinks that the octet
310 * at 32 is a packet type, e.g. "mailslot write" for
311 * browser announcements, and that the octet at 33 is a
312 * name type, in the sense of the 16th byte of a
315 * A name type of 2 shows up in a "host announcement",
316 * and a name type of 3 shows up in a "local master
317 * annoumcement", so maybe that field really *is* a
318 * name type - the fact that it's not associated with
319 * any of the NetBIOS names in the packet nonwithstanding.
321 * I haven't seen any packets with the name type octet
322 * being anything other than 2 or 3, so I don't know
323 * whether those are name service operations; however,
324 * given that NWLink, unlike socket-0x0455 NBIPX,
325 * has separate sockets for name queries and datagrams,
326 * it may be that this really is a name type, and that
327 * these are all datagrams, not name queries.
329 switch (packet_type) {
330 case NWLINK_NAME_QUERY:
331 col_add_fstr(pinfo->fd, COL_INFO, "Name Query for %s<%02x>",
337 col_add_fstr(pinfo->fd, COL_INFO, "SMB over NBIPX");
340 case NWLINK_NETBIOS_DATAGRAM:
341 /* Datagram? (Where did we see this?) */
342 col_add_fstr(pinfo->fd, COL_INFO, "NetBIOS datagram over NBIPX");
346 col_add_str(pinfo->fd, COL_INFO, "NetBIOS over IPX (NWLink)");
352 ti = proto_tree_add_item(tree, proto_nbipx, tvb, offset, 68, FALSE);
353 nbipx_tree = proto_item_add_subtree(ti, ett_nbipx);
355 add_routers(nbipx_tree, tvb, offset);
358 * XXX - is "packet_type" really a packet type? See
361 if (packet_type != NWLINK_SMB &&
362 packet_type != NWLINK_NETBIOS_DATAGRAM) {
363 tf = proto_tree_add_text(nbipx_tree, tvb, offset+32, 1,
364 "Name type flag: 0x%02x",
366 name_type_flag_tree = proto_item_add_subtree(tf,
367 ett_nbipx_name_type_flags);
368 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
370 decode_boolean_bitfield(name_type_flag, 0x80, 8,
371 "Group name", "Unique name"));
372 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
374 decode_boolean_bitfield(name_type_flag, 0x40, 8,
375 "Name in use", "Name not used"));
376 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
378 decode_boolean_bitfield(name_type_flag, 0x04, 8,
379 "Name registered", "Name not registered"));
380 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
382 decode_boolean_bitfield(name_type_flag, 0x02, 8,
383 "Name duplicated", "Name not duplicated"));
384 proto_tree_add_text(name_type_flag_tree, tvb, offset+32,
386 decode_boolean_bitfield(name_type_flag, 0x01, 8,
387 "Name deregistered", "Name not deregistered"));
389 if (!netbios_add_name("Group name", tvb, offset+36,
392 if (!netbios_add_name("Node name", tvb, offset+52,
395 proto_tree_add_text(nbipx_tree, tvb, offset+33, 1,
396 "Packet Type: %s (%02X)",
397 val_to_str(packet_type, nwlink_data_stream_type_vals, "Unknown"),
400 proto_tree_add_text(nbipx_tree, tvb, offset+32, 1,
401 "Packet type: 0x%02x", name_type_flag);
402 proto_tree_add_text(nbipx_tree, tvb, offset+33, 1,
403 "Name Type: %s (0x%02x)",
404 netbios_name_type_descr(packet_type),
406 proto_tree_add_text(nbipx_tree, tvb, offset+34, 2,
407 "Message ID: 0x%04x",
408 tvb_get_letohs(tvb, offset+34));
409 if (!netbios_add_name("Requested name", tvb, offset+36,
412 if (!netbios_add_name("Source name", tvb, offset+52,
420 if (tvb_offset_exists(tvb, offset)) {
421 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
423 switch (packet_type) {
425 case NWLINK_NETBIOS_DATAGRAM:
426 tvb_compat(next_tvb, &next_pd, &next_offset);
427 dissect_smb(next_pd, next_offset, pinfo->fd, tree,
428 tvb_length(next_tvb));
432 dissect_data(next_tvb, 0, pinfo, tree);
439 proto_register_nbipx(void)
441 /* static hf_register_info hf[] = {
443 { "Name", "nbipx.abbreviation", TYPE, VALS_POINTER }},
445 static gint *ett[] = {
447 &ett_nbipx_name_type_flags,
450 proto_nbipx = proto_register_protocol("NetBIOS over IPX", "nbipx");
451 /* proto_register_field_array(proto_nbipx, hf, array_length(hf));*/
452 proto_register_subtree_array(ett, array_length(ett));
456 proto_reg_handoff_nbipx(void)
458 dissector_add("ipx.socket", IPX_SOCKET_NWLINK_SMB_DGRAM, dissect_nwlink_dg);