2 * Routines for NetBIOS-over-TCP packet disassembly (the name dates back
3 * to when it had only NBNS)
4 * Guy Harris <guy@alum.mit.edu>
6 * $Id: packet-nbns.c,v 1.69 2002/01/07 00:57:46 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * 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>
40 #include "packet-dns.h"
41 #include "packet-netbios.h"
42 #include "packet-tcp.h"
43 #include "packet-frame.h"
46 static int proto_nbns = -1;
47 static int hf_nbns_response = -1;
48 static int hf_nbns_query = -1;
49 static int hf_nbns_transaction_id = -1;
50 static int hf_nbns_count_questions = -1;
51 static int hf_nbns_count_answers = -1;
52 static int hf_nbns_count_auth_rr = -1;
53 static int hf_nbns_count_add_rr = -1;
55 static gint ett_nbns = -1;
56 static gint ett_nbns_qd = -1;
57 static gint ett_nbns_flags = -1;
58 static gint ett_nbns_nb_flags = -1;
59 static gint ett_nbns_name_flags = -1;
60 static gint ett_nbns_rr = -1;
61 static gint ett_nbns_qry = -1;
62 static gint ett_nbns_ans = -1;
64 static int proto_nbdgm = -1;
65 static int hf_nbdgm_type = -1;
66 static int hf_nbdgm_fragment = -1;
67 static int hf_nbdgm_first = -1;
68 static int hf_nbdgm_node_type = -1;
69 static int hf_nbdgm_datagram_id = -1;
70 static int hf_nbdgm_src_ip = -1;
71 static int hf_nbdgm_src_port = -1;
73 static gint ett_nbdgm = -1;
75 static int proto_nbss = -1;
76 static int hf_nbss_type = -1;
77 static int hf_nbss_flags = -1;
79 static gint ett_nbss = -1;
80 static gint ett_nbss_flags = -1;
82 /* desegmentation of NBSS over TCP */
83 static gboolean nbss_desegment = TRUE;
85 /* See RFC 1001 and 1002 for information on the first three, and see
87 http://www.cifs.com/specs/draft-leach-cifs-v1-spec-01.txt
89 Appendix B, and various messages on the CIFS mailing list such as
91 http://discuss.microsoft.com/SCRIPTS/WA-MSD.EXE?A2=ind9811A&L=cifs&P=R386
93 for information on the fourth. */
94 #define UDP_PORT_NBNS 137
95 #define UDP_PORT_NBDGM 138
96 #define TCP_PORT_NBSS 139
97 #define TCP_PORT_CIFS 445
99 /* Packet structure taken from RFC 1002. See also RFC 1001.
100 * Opcode, flags, and rcode treated as "flags", similarly to DNS,
101 * to make it easier to lift the dissection code from "packet-dns.c". */
103 /* Offsets of fields in the NBNS header. */
111 /* Length of NBNS header. */
112 #define NBNS_HDRLEN 12
115 #define T_NB 32 /* NetBIOS name service RR */
116 #define T_NBSTAT 33 /* NetBIOS node status RR */
118 /* Bit fields in the flags */
119 #define F_RESPONSE (1<<15) /* packet is response */
120 #define F_OPCODE (0xF<<11) /* query opcode */
121 #define F_AUTHORITATIVE (1<<10) /* response is authoritative */
122 #define F_TRUNCATED (1<<9) /* response is truncated */
123 #define F_RECDESIRED (1<<8) /* recursion desired */
124 #define F_RECAVAIL (1<<7) /* recursion available */
125 #define F_BROADCAST (1<<4) /* broadcast/multicast packet */
126 #define F_RCODE (0xF<<0) /* reply code */
129 #define OPCODE_QUERY (0<<11) /* standard query */
130 #define OPCODE_REGISTRATION (5<<11) /* registration */
131 #define OPCODE_RELEASE (6<<11) /* release name */
132 #define OPCODE_WACK (7<<11) /* wait for acknowledgement */
133 #define OPCODE_REFRESH (8<<11) /* refresh registration */
134 #define OPCODE_REFRESHALT (9<<11) /* refresh registration (alternate opcode) */
135 #define OPCODE_MHREGISTRATION (15<<11) /* multi-homed registration */
138 #define RCODE_NOERROR (0<<0)
139 #define RCODE_FMTERROR (1<<0)
140 #define RCODE_SERVFAIL (2<<0)
141 #define RCODE_NAMEERROR (3<<0)
142 #define RCODE_NOTIMPL (4<<0)
143 #define RCODE_REFUSED (5<<0)
144 #define RCODE_ACTIVE (6<<0)
145 #define RCODE_CONFLICT (7<<0)
147 /* Values for the "NB_FLAGS" field of RR data. From RFC 1001 and 1002,
148 * except for NB_FLAGS_ONT_H_NODE, which was discovered by looking at
150 #define NB_FLAGS_ONT (3<<(15-2)) /* bits for node type */
151 #define NB_FLAGS_ONT_B_NODE (0<<(15-2)) /* B-mode node */
152 #define NB_FLAGS_ONT_P_NODE (1<<(15-2)) /* P-mode node */
153 #define NB_FLAGS_ONT_M_NODE (2<<(15-2)) /* M-mode node */
154 #define NB_FLAGS_ONT_H_NODE (3<<(15-2)) /* H-mode node */
156 #define NB_FLAGS_G (1<<(15-0)) /* group name */
158 /* Values for the "NAME_FLAGS" field of a NODE_NAME entry in T_NBSTAT
159 * RR data. From RFC 1001 and 1002, except for NAME_FLAGS_ONT_H_NODE,
160 * which was discovered by looking at packet traces. */
161 #define NAME_FLAGS_PRM (1<<(15-6)) /* name is permanent node name */
163 #define NAME_FLAGS_ACT (1<<(15-5)) /* name is active */
165 #define NAME_FLAGS_CNF (1<<(15-4)) /* name is in conflict */
167 #define NAME_FLAGS_DRG (1<<(15-3)) /* name is being deregistered */
169 #define NAME_FLAGS_ONT (3<<(15-2)) /* bits for node type */
170 #define NAME_FLAGS_ONT_B_NODE (0<<(15-2)) /* B-mode node */
171 #define NAME_FLAGS_ONT_P_NODE (1<<(15-2)) /* P-mode node */
172 #define NAME_FLAGS_ONT_M_NODE (2<<(15-2)) /* M-mode node */
174 #define NAME_FLAGS_G (1<<(15-0)) /* group name */
176 static const value_string opcode_vals[] = {
177 { OPCODE_QUERY, "Name query" },
178 { OPCODE_REGISTRATION, "Registration" },
179 { OPCODE_RELEASE, "Release" },
180 { OPCODE_WACK, "Wait for acknowledgment" },
181 { OPCODE_REFRESH, "Refresh" },
182 { OPCODE_REFRESHALT, "Refresh (alternate opcode)" },
183 { OPCODE_MHREGISTRATION, "Multi-homed registration" },
188 nbns_type_name (int type)
200 #define NBNAME_BUF_LEN 128
203 get_nbns_name(tvbuff_t *tvb, int offset, int nbns_data_offset,
204 char *name_ret, int *name_type_ret)
208 char nbname[NBNAME_BUF_LEN];
209 char *pname, *pnbname, cname, cnbname;
212 name_len = get_dns_name(tvb, offset, nbns_data_offset, name,
215 /* OK, now undo the first-level encoding. */
217 pnbname = &nbname[0];
219 /* Every two characters of the first level-encoded name
220 * turn into one character in the decoded name. */
223 break; /* no more characters */
225 break; /* scope ID follows */
226 if (cname < 'A' || cname > 'Z') {
229 "Illegal NetBIOS name (character not between A and Z in first-level encoding)");
233 cnbname = cname << 4;
237 if (cname == '\0' || cname == '.') {
238 /* No more characters in the name - but we're in
239 * the middle of a pair. Not legal. */
241 "Illegal NetBIOS name (odd number of bytes)");
244 if (cname < 'A' || cname > 'Z') {
247 "Illegal NetBIOS name (character not between A and Z in first-level encoding)");
254 /* Do we have room to store the character? */
255 if (pnbname < &nbname[NETBIOS_NAME_LEN]) {
256 /* Yes - store the character. */
260 /* We bump the pointer even if it's past the end of the
261 name, so we keep track of how long the name is. */
265 /* NetBIOS names are supposed to be exactly 16 bytes long. */
266 if (pnbname - nbname != NETBIOS_NAME_LEN) {
268 sprintf(nbname, "Illegal NetBIOS name (%ld bytes long)",
269 (long)(pnbname - nbname));
273 /* This one is; make its name printable. */
274 name_type = process_netbios_name(nbname, name_ret);
275 name_ret += strlen(name_ret);
276 sprintf(name_ret, "<%02x>", name_type);
279 /* We have a scope ID, starting at "pname"; append that to
280 * the decoded host name. */
281 strcpy(name_ret, pname);
283 if (name_type_ret != NULL)
284 *name_type_ret = name_type;
288 if (name_type_ret != NULL)
290 strcpy (name_ret, nbname);
296 get_nbns_name_type_class(tvbuff_t *tvb, int offset, int nbns_data_offset,
297 char *name_ret, int *name_len_ret, int *name_type_ret, int *type_ret,
304 name_len = get_nbns_name(tvb, offset, nbns_data_offset, name_ret,
308 type = tvb_get_ntohs(tvb, offset);
311 class = tvb_get_ntohs(tvb, offset);
315 *name_len_ret = name_len;
321 add_name_and_type(proto_tree *tree, tvbuff_t *tvb, int offset, int len,
322 char *tag, char *name, int name_type)
324 if (name_type != -1) {
325 proto_tree_add_text(tree, tvb, offset, len, "%s: %s (%s)",
326 tag, name, netbios_name_type_descr(name_type));
328 proto_tree_add_text(tree, tvb, offset, len, "%s: %s",
334 dissect_nbns_query(tvbuff_t *tvb, int offset, int nbns_data_offset,
335 column_info *cinfo, proto_tree *nbns_tree)
338 char name[(NETBIOS_NAME_LEN - 1)*4 + MAXDNAME];
350 data_start = data_offset = offset;
352 len = get_nbns_name_type_class(tvb, offset, nbns_data_offset, name,
353 &name_len, &name_type, &type, &class);
356 type_name = nbns_type_name(type);
357 class_name = dns_class_name(class);
360 col_append_fstr(cinfo, COL_INFO, " %s %s", type_name, name);
361 if (nbns_tree != NULL) {
362 tq = proto_tree_add_text(nbns_tree, tvb, offset, len,
363 "%s: type %s, class %s", name, type_name, class_name);
364 q_tree = proto_item_add_subtree(tq, ett_nbns_qd);
366 add_name_and_type(q_tree, tvb, offset, name_len, "Name", name,
370 proto_tree_add_text(q_tree, tvb, offset, 2, "Type: %s", type_name);
373 proto_tree_add_text(q_tree, tvb, offset, 2, "Class: %s", class_name);
377 return data_offset - data_start;
381 nbns_add_nbns_flags(proto_tree *nbns_tree, tvbuff_t *tvb, int offset,
382 u_short flags, int is_wack)
385 proto_tree *field_tree;
387 static const value_string rcode_vals[] = {
388 { RCODE_NOERROR, "No error" },
389 { RCODE_FMTERROR, "Request was invalidly formatted" },
390 { RCODE_SERVFAIL, "Server failure" },
391 { RCODE_NAMEERROR, "Requested name does not exist" },
392 { RCODE_NOTIMPL, "Request is not implemented" },
393 { RCODE_REFUSED, "Request was refused" },
394 { RCODE_ACTIVE, "Name is owned by another node" },
395 { RCODE_CONFLICT, "Name is in conflict" },
399 strcpy(buf, val_to_str(flags & F_OPCODE, opcode_vals,
400 "Unknown operation"));
401 if (flags & F_RESPONSE && !is_wack) {
402 strcat(buf, " response");
404 strcat(buf, val_to_str(flags & F_RCODE, rcode_vals,
407 tf = proto_tree_add_text(nbns_tree, tvb, offset, 2,
408 "Flags: 0x%04x (%s)", flags, buf);
409 field_tree = proto_item_add_subtree(tf, ett_nbns_flags);
410 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
411 decode_boolean_bitfield(flags, F_RESPONSE,
412 2*8, "Response", "Query"));
413 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
414 decode_enumerated_bitfield(flags, F_OPCODE,
415 2*8, opcode_vals, "%s"));
416 if (flags & F_RESPONSE) {
417 proto_tree_add_text(field_tree, tvb, offset, 2,
419 decode_boolean_bitfield(flags, F_AUTHORITATIVE,
421 "Server is an authority for domain",
422 "Server isn't an authority for domain"));
424 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
425 decode_boolean_bitfield(flags, F_TRUNCATED,
427 "Message is truncated",
428 "Message is not truncated"));
429 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
430 decode_boolean_bitfield(flags, F_RECDESIRED,
432 "Do query recursively",
433 "Don't do query recursively"));
434 if (flags & F_RESPONSE) {
435 proto_tree_add_text(field_tree, tvb, offset, 2,
437 decode_boolean_bitfield(flags, F_RECAVAIL,
439 "Server can do recursive queries",
440 "Server can't do recursive queries"));
442 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
443 decode_boolean_bitfield(flags, F_BROADCAST,
446 "Not a broadcast packet"));
447 if (flags & F_RESPONSE && !is_wack) {
448 proto_tree_add_text(field_tree, tvb, offset, 2,
450 decode_enumerated_bitfield(flags, F_RCODE,
457 nbns_add_nb_flags(proto_tree *rr_tree, tvbuff_t *tvb, int offset, u_short flags)
460 proto_tree *field_tree;
462 static const value_string nb_flags_ont_vals[] = {
463 { NB_FLAGS_ONT_B_NODE, "B-node" },
464 { NB_FLAGS_ONT_P_NODE, "P-node" },
465 { NB_FLAGS_ONT_M_NODE, "M-node" },
466 { NB_FLAGS_ONT_H_NODE, "H-node" },
470 strcpy(buf, val_to_str(flags & NB_FLAGS_ONT, nb_flags_ont_vals,
473 if (flags & NB_FLAGS_G)
474 strcat(buf, "group");
476 strcat(buf, "unique");
477 tf = proto_tree_add_text(rr_tree, tvb, offset, 2, "Flags: 0x%x (%s)", flags,
479 field_tree = proto_item_add_subtree(tf, ett_nbns_nb_flags);
480 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
481 decode_boolean_bitfield(flags, NB_FLAGS_G,
485 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
486 decode_enumerated_bitfield(flags, NB_FLAGS_ONT,
487 2*8, nb_flags_ont_vals, "%s"));
491 nbns_add_name_flags(proto_tree *rr_tree, tvbuff_t *tvb, int offset,
495 proto_item *field_tree;
497 static const value_string name_flags_ont_vals[] = {
498 { NAME_FLAGS_ONT_B_NODE, "B-node" },
499 { NAME_FLAGS_ONT_P_NODE, "P-node" },
500 { NAME_FLAGS_ONT_M_NODE, "M-node" },
504 strcpy(buf, val_to_str(flags & NAME_FLAGS_ONT, name_flags_ont_vals,
507 if (flags & NAME_FLAGS_G)
508 strcat(buf, "group");
510 strcat(buf, "unique");
511 if (flags & NAME_FLAGS_DRG)
512 strcat(buf, ", being deregistered");
513 if (flags & NAME_FLAGS_CNF)
514 strcat(buf, ", in conflict");
515 if (flags & NAME_FLAGS_ACT)
516 strcat(buf, ", active");
517 if (flags & NAME_FLAGS_PRM)
518 strcat(buf, ", permanent node name");
519 tf = proto_tree_add_text(rr_tree, tvb, offset, 2, "Name flags: 0x%x (%s)",
521 field_tree = proto_item_add_subtree(tf, ett_nbns_name_flags);
522 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
523 decode_boolean_bitfield(flags, NAME_FLAGS_G,
527 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
528 decode_enumerated_bitfield(flags, NAME_FLAGS_ONT,
529 2*8, name_flags_ont_vals, "%s"));
530 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
531 decode_boolean_bitfield(flags, NAME_FLAGS_DRG,
533 "Name is being deregistered",
534 "Name is not being deregistered"));
535 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
536 decode_boolean_bitfield(flags, NAME_FLAGS_CNF,
538 "Name is in conflict",
539 "Name is not in conflict"));
540 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
541 decode_boolean_bitfield(flags, NAME_FLAGS_ACT,
544 "Name is not active"));
545 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
546 decode_boolean_bitfield(flags, NAME_FLAGS_PRM,
548 "Permanent node name",
549 "Not permanent node name"));
553 dissect_nbns_answer(tvbuff_t *tvb, int offset, int nbns_data_offset,
554 column_info *cinfo, proto_tree *nbns_tree, int opcode)
557 char name[(NETBIOS_NAME_LEN - 1)*4 + MAXDNAME + 64];
572 char name_str[(NETBIOS_NAME_LEN - 1)*4 + 1];
574 char nbname[16+4+1]; /* 4 for [<last char>] */
577 data_start = data_offset = offset;
580 len = get_nbns_name_type_class(tvb, offset, nbns_data_offset, name,
581 &name_len, &name_type, &type, &class);
585 type_name = nbns_type_name(type);
586 class_name = dns_class_name(class);
588 ttl = tvb_get_ntohl(tvb, data_offset);
592 data_len = tvb_get_ntohs(tvb, data_offset);
597 case T_NB: /* "NB" record */
599 if (opcode != OPCODE_WACK) {
600 col_append_fstr(cinfo, COL_INFO, " %s %s",
602 ip_to_str(tvb_get_ptr(tvb, data_offset+2, 4)));
605 if (nbns_tree == NULL)
607 trr = proto_tree_add_text(nbns_tree, tvb, offset,
608 (data_offset - data_start) + data_len,
609 "%s: type %s, class %s",
610 name, type_name, class_name);
612 strcat(name, netbios_name_type_descr(name_type));
614 rr_tree = add_rr_to_tree(trr, ett_nbns_rr, tvb, offset, name,
615 name_len, type_name, class_name, ttl, data_len);
616 while (data_len > 0) {
617 if (opcode == OPCODE_WACK) {
618 /* WACK response. This doesn't contain the
619 * same type of RR data as other T_NB
622 proto_tree_add_text(rr_tree, tvb, cur_offset,
623 data_len, "(incomplete entry)");
626 flags = tvb_get_ntohs(tvb, cur_offset);
627 nbns_add_nbns_flags(rr_tree, tvb, cur_offset,
633 proto_tree_add_text(rr_tree, tvb, cur_offset,
634 data_len, "(incomplete entry)");
637 flags = tvb_get_ntohs(tvb, cur_offset);
638 nbns_add_nb_flags(rr_tree, tvb, cur_offset,
644 proto_tree_add_text(rr_tree, tvb, cur_offset,
645 data_len, "(incomplete entry)");
648 proto_tree_add_text(rr_tree, tvb, cur_offset, 4,
650 ip_to_str(tvb_get_ptr(tvb, cur_offset, 4)));
657 case T_NBSTAT: /* "NBSTAT" record */
659 col_append_fstr(cinfo, COL_INFO, " %s", type_name);
660 if (nbns_tree == NULL)
662 trr = proto_tree_add_text(nbns_tree, tvb, offset,
663 (data_offset - data_start) + data_len,
664 "%s: type %s, class %s",
665 name, type_name, class_name);
666 rr_tree = add_rr_to_tree(trr, ett_nbns_rr, tvb, offset, name,
667 name_len, type_name, class_name, ttl, data_len);
669 proto_tree_add_text(rr_tree, tvb, cur_offset,
670 data_len, "(incomplete entry)");
673 num_names = tvb_get_guint8(tvb, cur_offset);
674 proto_tree_add_text(rr_tree, tvb, cur_offset, 1,
675 "Number of names: %u", num_names);
678 while (num_names != 0) {
679 if (data_len < NETBIOS_NAME_LEN) {
680 proto_tree_add_text(rr_tree, tvb, cur_offset,
681 data_len, "(incomplete entry)");
684 tvb_memcpy(tvb, (guint8 *)nbname, cur_offset,
686 name_type = process_netbios_name(nbname,
688 proto_tree_add_text(rr_tree, tvb, cur_offset,
689 NETBIOS_NAME_LEN, "Name: %s<%02x> (%s)",
691 netbios_name_type_descr(name_type));
692 cur_offset += NETBIOS_NAME_LEN;
693 data_len -= NETBIOS_NAME_LEN;
696 proto_tree_add_text(rr_tree, tvb, cur_offset,
697 data_len, "(incomplete entry)");
700 name_flags = tvb_get_ntohs(tvb, cur_offset);
701 nbns_add_name_flags(rr_tree, tvb, cur_offset,
710 proto_tree_add_text(rr_tree, tvb, cur_offset,
711 data_len, "(incomplete entry)");
714 proto_tree_add_text(rr_tree, tvb, cur_offset, 6,
716 ether_to_str(tvb_get_ptr(tvb, cur_offset, 6)));
721 proto_tree_add_text(rr_tree, tvb, cur_offset,
722 data_len, "(incomplete entry)");
725 proto_tree_add_text(rr_tree, tvb, cur_offset, 1,
726 "Jumpers: 0x%x", tvb_get_guint8(tvb, cur_offset));
731 proto_tree_add_text(rr_tree, tvb, cur_offset,
732 data_len, "(incomplete entry)");
735 proto_tree_add_text(rr_tree, tvb, cur_offset, 1,
736 "Test result: 0x%x", tvb_get_guint8(tvb, cur_offset));
741 proto_tree_add_text(rr_tree, tvb, cur_offset,
742 data_len, "(incomplete entry)");
745 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
746 "Version number: 0x%x", tvb_get_ntohs(tvb, cur_offset));
751 proto_tree_add_text(rr_tree, tvb, cur_offset,
752 data_len, "(incomplete entry)");
755 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
756 "Period of statistics: 0x%x",
757 tvb_get_ntohs(tvb, cur_offset));
762 proto_tree_add_text(rr_tree, tvb, cur_offset,
763 data_len, "(incomplete entry)");
766 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
767 "Number of CRCs: %u", tvb_get_ntohs(tvb, cur_offset));
772 proto_tree_add_text(rr_tree, tvb, cur_offset,
773 data_len, "(incomplete entry)");
776 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
777 "Number of alignment errors: %u",
778 tvb_get_ntohs(tvb, cur_offset));
783 proto_tree_add_text(rr_tree, tvb, cur_offset,
784 data_len, "(incomplete entry)");
787 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
788 "Number of collisions: %u", tvb_get_ntohs(tvb, cur_offset));
793 proto_tree_add_text(rr_tree, tvb, cur_offset,
794 data_len, "(incomplete entry)");
797 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
798 "Number of send aborts: %u", tvb_get_ntohs(tvb, cur_offset));
803 proto_tree_add_text(rr_tree, tvb, cur_offset,
804 data_len, "(incomplete entry)");
807 proto_tree_add_text(rr_tree, tvb, cur_offset, 4,
808 "Number of good sends: %u", tvb_get_ntohl(tvb, cur_offset));
813 proto_tree_add_text(rr_tree, tvb, cur_offset,
814 data_len, "(incomplete entry)");
817 proto_tree_add_text(rr_tree, tvb, cur_offset, 4,
818 "Number of good receives: %u",
819 tvb_get_ntohl(tvb, cur_offset));
824 proto_tree_add_text(rr_tree, tvb, cur_offset,
825 data_len, "(incomplete entry)");
828 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
829 "Number of retransmits: %u", tvb_get_ntohs(tvb, cur_offset));
834 proto_tree_add_text(rr_tree, tvb, cur_offset,
835 data_len, "(incomplete entry)");
838 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
839 "Number of no resource conditions: %u",
840 tvb_get_ntohs(tvb, cur_offset));
845 proto_tree_add_text(rr_tree, tvb, cur_offset,
846 data_len, "(incomplete entry)");
849 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
850 "Number of command blocks: %u",
851 tvb_get_ntohs(tvb, cur_offset));
856 proto_tree_add_text(rr_tree, tvb, cur_offset,
857 data_len, "(incomplete entry)");
860 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
861 "Number of pending sessions: %u",
862 tvb_get_ntohs(tvb, cur_offset));
867 proto_tree_add_text(rr_tree, tvb, cur_offset,
868 data_len, "(incomplete entry)");
871 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
872 "Max number of pending sessions: %u",
873 tvb_get_ntohs(tvb, cur_offset));
878 proto_tree_add_text(rr_tree, tvb, cur_offset,
879 data_len, "(incomplete entry)");
882 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
883 "Max total sessions possible: %u",
884 tvb_get_ntohs(tvb, cur_offset));
889 proto_tree_add_text(rr_tree, tvb, cur_offset,
890 data_len, "(incomplete entry)");
893 proto_tree_add_text(rr_tree, tvb, cur_offset, 2,
894 "Session data packet size: %u",
895 tvb_get_ntohs(tvb, cur_offset));
903 col_append_fstr(cinfo, COL_INFO, " %s", type_name);
904 if (nbns_tree == NULL)
906 trr = proto_tree_add_text(nbns_tree, tvb, offset,
907 (data_offset - data_start) + data_len,
908 "%s: type %s, class %s",
909 name, type_name, class_name);
910 rr_tree = add_rr_to_tree(trr, ett_nbns_rr, tvb, offset, name,
911 name_len, type_name, class_name, ttl, data_len);
912 proto_tree_add_text(rr_tree, tvb, cur_offset, data_len, "Data");
913 cur_offset += data_len;
917 return cur_offset - data_start;
921 dissect_query_records(tvbuff_t *tvb, int cur_off, int nbns_data_offset,
922 int count, column_info *cinfo, proto_tree *nbns_tree)
924 int start_off, add_off;
925 proto_tree *qatree = NULL;
926 proto_item *ti = NULL;
929 if (nbns_tree != NULL) {
930 ti = proto_tree_add_text(nbns_tree, tvb, start_off, 0, "Queries");
931 qatree = proto_item_add_subtree(ti, ett_nbns_qry);
933 while (count-- > 0) {
934 add_off = dissect_nbns_query(tvb, cur_off, nbns_data_offset,
937 /* We ran past the end of the captured data in the
944 proto_item_set_len(ti, cur_off - start_off);
946 return cur_off - start_off;
952 dissect_answer_records(tvbuff_t *tvb, int cur_off, int nbns_data_offset,
953 int count, column_info *cinfo, proto_tree *nbns_tree, int opcode,
956 int start_off, add_off;
957 proto_tree *qatree = NULL;
958 proto_item *ti = NULL;
961 if (nbns_tree != NULL) {
962 ti = proto_tree_add_text(nbns_tree, tvb, start_off, 0, name);
963 qatree = proto_item_add_subtree(ti, ett_nbns_ans);
965 while (count-- > 0) {
966 add_off = dissect_nbns_answer(tvb, cur_off, nbns_data_offset,
967 cinfo, qatree, opcode);
969 /* We ran past the end of the captured data in the
976 proto_item_set_len(ti, cur_off - start_off);
977 return cur_off - start_off;
981 dissect_nbns(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
984 int nbns_data_offset;
986 proto_tree *nbns_tree = NULL;
988 guint16 id, flags, quest, ans, auth, add;
991 nbns_data_offset = offset;
993 if (check_col(pinfo->cinfo, COL_PROTOCOL))
994 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NBNS");
995 if (check_col(pinfo->cinfo, COL_INFO))
996 col_clear(pinfo->cinfo, COL_INFO);
998 /* To do: check for runts, errs, etc. */
999 id = tvb_get_ntohs(tvb, offset + NBNS_ID);
1000 flags = tvb_get_ntohs(tvb, offset + NBNS_FLAGS);
1002 if (check_col(pinfo->cinfo, COL_INFO)) {
1003 col_add_fstr(pinfo->cinfo, COL_INFO, "%s%s",
1004 val_to_str(flags & F_OPCODE, opcode_vals,
1005 "Unknown operation (%x)"),
1006 (flags & F_RESPONSE) ? " response" : "");
1007 cinfo = pinfo->cinfo;
1009 /* Set "cinfo" to NULL; we pass a NULL "cinfo" to the query
1010 and answer dissectors, as a way of saying that they
1011 shouldn't add stuff to the COL_INFO column (a call to
1012 "check_col(cinfo, COL_INFO)" is more expensive than
1013 a check that a pointer isn't NULL). */
1018 ti = proto_tree_add_item(tree, proto_nbns, tvb, offset,
1019 tvb_length(tvb), FALSE);
1020 nbns_tree = proto_item_add_subtree(ti, ett_nbns);
1022 if (flags & F_RESPONSE) {
1023 proto_tree_add_boolean_hidden(nbns_tree, hf_nbns_response, tvb,
1026 proto_tree_add_boolean_hidden(nbns_tree, hf_nbns_query, tvb,
1030 proto_tree_add_uint(nbns_tree, hf_nbns_transaction_id, tvb,
1031 offset + NBNS_ID, 2, id);
1033 nbns_add_nbns_flags(nbns_tree, tvb, offset + NBNS_FLAGS,
1036 quest = tvb_get_ntohs(tvb, offset + NBNS_QUEST);
1038 proto_tree_add_uint(nbns_tree, hf_nbns_count_questions, tvb,
1039 offset + NBNS_QUEST, 2, quest);
1041 ans = tvb_get_ntohs(tvb, offset + NBNS_ANS);
1043 proto_tree_add_uint(nbns_tree, hf_nbns_count_answers, tvb,
1044 offset + NBNS_ANS, 2, ans);
1046 auth = tvb_get_ntohs(tvb, offset + NBNS_AUTH);
1048 proto_tree_add_uint(nbns_tree, hf_nbns_count_auth_rr, tvb,
1049 offset + NBNS_AUTH, 2, auth);
1051 add = tvb_get_ntohs(tvb, offset + NBNS_ADD);
1053 proto_tree_add_uint(nbns_tree, hf_nbns_count_add_rr, tvb,
1054 offset + NBNS_ADD, 2, add);
1057 cur_off = offset + NBNS_HDRLEN;
1060 /* If this is a response, don't add information about the
1061 queries to the summary, just add information about the
1063 cur_off += dissect_query_records(tvb, cur_off,
1064 nbns_data_offset, quest,
1065 (!(flags & F_RESPONSE) ? cinfo : NULL), nbns_tree);
1069 /* If this is a request, don't add information about the
1070 answers to the summary, just add information about the
1072 cur_off += dissect_answer_records(tvb, cur_off,
1073 nbns_data_offset, ans,
1074 ((flags & F_RESPONSE) ? cinfo : NULL), nbns_tree,
1075 flags & F_OPCODE, "Answers");
1079 /* Don't add information about the authoritative name
1080 servers, or the additional records, to the summary. */
1082 cur_off += dissect_answer_records(tvb, cur_off,
1084 auth, NULL, nbns_tree,
1086 "Authoritative nameservers");
1089 cur_off += dissect_answer_records(tvb, cur_off,
1091 add, NULL, nbns_tree,
1093 "Additional records");
1097 /* NetBIOS datagram packet, from RFC 1002, page 32 */
1098 struct nbdgm_header {
1109 /* For packets with data */
1113 /* For error packets */
1118 * NBDS message types.
1120 #define NBDS_DIRECT_UNIQUE 0x10
1121 #define NBDS_DIRECT_GROUP 0x11
1122 #define NBDS_BROADCAST 0x12
1123 #define NBDS_ERROR 0x13
1124 #define NBDS_QUERY_REQUEST 0x14
1125 #define NBDS_POS_QUERY_RESPONSE 0x15
1126 #define NBDS_NEG_QUERY_RESPONSE 0x16
1128 static const value_string nbds_msgtype_vals[] = {
1129 { NBDS_DIRECT_UNIQUE, "Direct_unique datagram" },
1130 { NBDS_DIRECT_GROUP, "Direct_group datagram" },
1131 { NBDS_BROADCAST, "Broadcast datagram" },
1132 { NBDS_ERROR, "Datagram error" },
1133 { NBDS_QUERY_REQUEST, "Datagram query request" },
1134 { NBDS_POS_QUERY_RESPONSE, "Datagram positive query response" },
1135 { NBDS_NEG_QUERY_RESPONSE, "Datagram negative query response" },
1139 static const true_false_string yesno = {
1144 static const value_string node_type_vals[] = {
1153 dissect_nbdgm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1156 proto_tree *nbdgm_tree = NULL;
1157 proto_item *ti = NULL;
1158 struct nbdgm_header header;
1163 static const value_string error_codes[] = {
1164 { 0x82, "Destination name not present" },
1165 { 0x83, "Invalid source name format" },
1166 { 0x84, "Invalid destination name format" },
1170 char name[(NETBIOS_NAME_LEN - 1)*4 + MAXDNAME];
1174 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1175 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NBDS");
1176 if (check_col(pinfo->cinfo, COL_INFO))
1177 col_clear(pinfo->cinfo, COL_INFO);
1179 header.msg_type = tvb_get_guint8(tvb, offset);
1181 flags = tvb_get_guint8(tvb, offset+1);
1182 header.flags.more = flags & 1;
1183 header.flags.first = (flags & 2) >> 1;
1184 header.flags.node_type = (flags & 12) >> 2;
1186 header.dgm_id = tvb_get_ntohs(tvb, offset+2);
1187 tvb_memcpy(tvb, (guint8 *)&header.src_ip, offset+4, 4);
1188 header.src_port = tvb_get_ntohs(tvb, offset+8);
1190 switch (header.msg_type) {
1192 case NBDS_DIRECT_UNIQUE:
1193 case NBDS_DIRECT_GROUP:
1194 case NBDS_BROADCAST:
1195 header.dgm_length = tvb_get_ntohs(tvb, offset+10);
1196 header.pkt_offset = tvb_get_ntohs(tvb, offset+12);
1200 header.error_code = tvb_get_ntohs(tvb, offset+10);
1204 message_index = header.msg_type - 0x0f;
1205 if (message_index < 1 || message_index > 8) {
1209 if (check_col(pinfo->cinfo, COL_INFO)) {
1210 col_add_str(pinfo->cinfo, COL_INFO,
1211 val_to_str(header.msg_type, nbds_msgtype_vals,
1212 "Unknown message type (0x%02X)"));
1216 ti = proto_tree_add_item(tree, proto_nbdgm, tvb, offset,
1217 tvb_length_remaining(tvb, offset), FALSE);
1218 nbdgm_tree = proto_item_add_subtree(ti, ett_nbdgm);
1220 proto_tree_add_uint(nbdgm_tree, hf_nbdgm_type, tvb,
1223 proto_tree_add_boolean(nbdgm_tree, hf_nbdgm_fragment, tvb,
1226 proto_tree_add_boolean(nbdgm_tree, hf_nbdgm_first, tvb,
1228 header.flags.first);
1229 proto_tree_add_uint(nbdgm_tree, hf_nbdgm_node_type, tvb,
1231 header.flags.node_type);
1233 proto_tree_add_uint(nbdgm_tree, hf_nbdgm_datagram_id, tvb,
1234 offset+2, 2, header.dgm_id);
1235 proto_tree_add_ipv4(nbdgm_tree, hf_nbdgm_src_ip, tvb,
1236 offset+4, 4, header.src_ip);
1237 proto_tree_add_uint(nbdgm_tree, hf_nbdgm_src_port, tvb,
1238 offset+8, 2, header.src_port);
1244 switch (header.msg_type) {
1246 case NBDS_DIRECT_UNIQUE:
1247 case NBDS_DIRECT_GROUP:
1248 case NBDS_BROADCAST:
1250 proto_tree_add_text(nbdgm_tree, tvb, offset, 2,
1251 "Datagram length: %d bytes", header.dgm_length);
1252 proto_tree_add_text(nbdgm_tree, tvb, offset+2, 2,
1253 "Packet offset: %d bytes", header.pkt_offset);
1259 len = get_nbns_name(tvb, offset, offset, name, &name_type);
1262 add_name_and_type(nbdgm_tree, tvb, offset, len,
1263 "Source name", name, name_type);
1267 /* Destination name */
1268 len = get_nbns_name(tvb, offset, offset, name, &name_type);
1271 add_name_and_type(nbdgm_tree, tvb, offset, len,
1272 "Destination name", name, name_type);
1277 * Here we can pass the packet off to the next protocol.
1278 * Set the length of our top-level tree item to include
1281 * XXX - take the datagram length into account?
1283 proto_item_set_len(ti, offset);
1284 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
1285 dissect_netbios_payload(next_tvb, pinfo, tree);
1290 proto_tree_add_text(nbdgm_tree, tvb, offset, 1, "Error code: %s",
1291 val_to_str(header.error_code, error_codes, "Unknown (0x%x)"));
1294 proto_item_set_len(ti, offset);
1297 case NBDS_QUERY_REQUEST:
1298 case NBDS_POS_QUERY_RESPONSE:
1299 case NBDS_NEG_QUERY_RESPONSE:
1300 /* Destination name */
1301 len = get_nbns_name(tvb, offset, offset, name, &name_type);
1304 add_name_and_type(nbdgm_tree, tvb, offset, len,
1305 "Destination name", name, name_type);
1308 proto_item_set_len(ti, offset);
1314 * NetBIOS Session Service message types.
1316 #define SESSION_MESSAGE 0x00
1317 #define SESSION_REQUEST 0x81
1318 #define POSITIVE_SESSION_RESPONSE 0x82
1319 #define NEGATIVE_SESSION_RESPONSE 0x83
1320 #define RETARGET_SESSION_RESPONSE 0x84
1321 #define SESSION_KEEP_ALIVE 0x85
1323 static const value_string message_types[] = {
1324 { SESSION_MESSAGE, "Session message" },
1325 { SESSION_REQUEST, "Session request" },
1326 { POSITIVE_SESSION_RESPONSE, "Positive session response" },
1327 { NEGATIVE_SESSION_RESPONSE, "Negative session response" },
1328 { RETARGET_SESSION_RESPONSE, "Retarget session response" },
1329 { SESSION_KEEP_ALIVE, "Session keep-alive" },
1334 * NetBIOS Session Service flags.
1336 #define NBSS_FLAGS_E 0x1
1338 static const value_string error_codes[] = {
1339 { 0x80, "Not listening on called name" },
1340 { 0x81, "Not listening for called name" },
1341 { 0x82, "Called name not present" },
1342 { 0x83, "Called name present, but insufficient resources" },
1343 { 0x8F, "Unspecified error" },
1348 * Dissect a single NBSS packet (there may be more than one in a given
1351 * [ Hmmm, in my experience, I have never seen more than one NBSS in a
1352 * single segment, since they mostly contain SMBs which are essentially
1353 * a request response type protocol (RJS). ]
1355 * [ However, under heavy load with many requests multiplexed on one
1356 * session it is not unusual to see multiple requests in one TCP
1357 * segment. Unfortunately, in this case a single session message is
1358 * frequently split over multiple segments, which frustrates decoding
1362 dissect_nbss_packet(tvbuff_t *tvb, int offset, packet_info *pinfo,
1363 proto_tree *tree, int max_data, int is_cifs)
1365 proto_tree *nbss_tree = NULL;
1366 proto_item *ti = NULL;
1367 proto_tree *field_tree;
1371 volatile int length;
1373 char name[(NETBIOS_NAME_LEN - 1)*4 + MAXDNAME];
1377 const char *saved_proto;
1379 msg_type = tvb_get_guint8(tvb, offset);
1383 length = tvb_get_ntoh24(tvb, offset + 1);
1385 flags = tvb_get_guint8(tvb, offset + 1);
1386 length = tvb_get_ntohs(tvb, offset + 2);
1387 if (flags & NBSS_FLAGS_E)
1392 if (nbss_desegment) {
1393 if (pinfo->can_desegment
1394 && length > tvb_length_remaining(tvb, offset+4)) {
1396 * This frame doesn't have all of the data for
1397 * this message, but we can do reassembly on it.
1399 * Tell the TCP dissector where the data for this
1400 * message starts in the data it handed us, and
1401 * how many more bytes we need, and return.
1403 pinfo->desegment_offset = offset;
1404 pinfo->desegment_len =
1405 length - tvb_length_remaining(tvb, offset+4);
1411 ti = proto_tree_add_item(tree, proto_nbss, tvb, offset, length + 4, FALSE);
1412 nbss_tree = proto_item_add_subtree(ti, ett_nbss);
1414 proto_tree_add_uint_format(nbss_tree, hf_nbss_type, tvb,
1418 val_to_str(msg_type, message_types,
1426 proto_tree_add_text(nbss_tree, tvb, offset, 3, "Length: %u", length);
1431 tf = proto_tree_add_uint(nbss_tree, hf_nbss_flags, tvb, offset, 1, flags);
1432 field_tree = proto_item_add_subtree(tf, ett_nbss_flags);
1433 proto_tree_add_text(field_tree, tvb, offset, 1, "%s",
1434 decode_boolean_bitfield(flags, NBSS_FLAGS_E,
1435 8, "Add 65536 to length", "Add 0 to length"));
1440 proto_tree_add_text(nbss_tree, tvb, offset, 2, "Length: %u", length);
1448 case SESSION_REQUEST:
1449 len = get_nbns_name(tvb, offset, offset, name, &name_type);
1451 add_name_and_type(nbss_tree, tvb, offset, len,
1452 "Called name", name, name_type);
1455 len = get_nbns_name(tvb, offset, offset, name, &name_type);
1458 add_name_and_type(nbss_tree, tvb, offset, len,
1459 "Calling name", name, name_type);
1463 case NEGATIVE_SESSION_RESPONSE:
1465 proto_tree_add_text(nbss_tree, tvb, offset, 1,
1467 val_to_str(tvb_get_guint8(tvb, offset),
1468 error_codes, "Unknown (%x)"));
1471 case RETARGET_SESSION_RESPONSE:
1473 proto_tree_add_text(nbss_tree, tvb, offset, 4,
1474 "Retarget IP address: %s",
1475 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1480 proto_tree_add_text(nbss_tree, tvb, offset, 2,
1481 "Retarget port: %u",
1482 tvb_get_ntohs(tvb, offset));
1486 case SESSION_MESSAGE:
1488 * Here we can pass the message off to the next protocol.
1489 * Set the length of our top-level tree item to include
1492 proto_item_set_len(ti, offset);
1493 len = tvb_length_remaining(tvb, offset);
1494 reported_len = tvb_reported_length_remaining(tvb, offset);
1497 if (reported_len > length)
1498 reported_len = length;
1500 next_tvb = tvb_new_subset(tvb, offset, len, reported_len);
1503 * Catch the ReportedBoundsError exception; if this
1504 * particular message happens to get a ReportedBoundsError
1505 * exception, that doesn't mean that we should stop
1506 * dissecting NetBIOS messages within this frame or chunk
1507 * of reassembled data.
1509 * If it gets a BoundsError, we can stop, as there's nothing
1510 * more to see, so we just re-throw it.
1512 saved_proto = pinfo->current_proto;
1514 dissect_netbios_payload(next_tvb, pinfo, tree);
1516 CATCH(BoundsError) {
1519 CATCH(ReportedBoundsError) {
1520 if (check_col(pinfo->cinfo, COL_INFO))
1521 col_append_str(pinfo->cinfo, COL_INFO, "[Malformed Packet]");
1522 proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
1523 "[Malformed Packet: %s]", pinfo->current_proto );
1524 pinfo->current_proto = saved_proto;
1534 dissect_nbss(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1536 struct tcpinfo *tcpinfo = pinfo->private_data;
1544 proto_tree *nbss_tree;
1547 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1548 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NBSS");
1549 if (check_col(pinfo->cinfo, COL_INFO))
1550 col_clear(pinfo->cinfo, COL_INFO);
1552 max_data = tvb_length(tvb);
1554 msg_type = tvb_get_guint8(tvb, offset);
1556 if (pinfo->match_port == TCP_PORT_CIFS) {
1558 * Windows 2000 CIFS clients can dispense completely
1559 * with the NETBIOS encapsulation and directly use CIFS
1560 * over TCP. As would be expected, the framing is
1561 * identical, except that the length is 24 bits instead
1562 * of 17. The only message types used are
1563 * SESSION_MESSAGE and SESSION_KEEP_ALIVE.
1571 * This might be a continuation of an earlier message.
1572 * (Yes, that might be true even if we're doing TCP reassembly,
1573 * as the first TCP segment in the capture might start in the
1574 * middle of an NBNS message.)
1578 * If this isn't reassembled data, check to see whether it
1579 * looks like a continuation of a message.
1580 * (If it is reassembled data, it shouldn't be a continuation,
1581 * as reassembly should've gathered the continuations together
1584 if (!tcpinfo->is_reassembled) {
1587 * Not enough data for an NBSS header; assume
1588 * it's a continuation of a message.
1590 * XXX - if there's not enough data, we should
1591 * attempt to reassemble the data, if the first byte
1592 * is a valid message type.
1598 * We have enough data for an NBSS header.
1599 * Get the flags and length of the message,
1600 * and see if they're sane.
1604 length = tvb_get_ntoh24(tvb, offset + 1);
1606 flags = tvb_get_guint8(tvb, offset + 1);
1607 length = tvb_get_ntohs(tvb, offset + 2);
1608 if (flags & NBSS_FLAGS_E)
1611 if ((flags & (~NBSS_FLAGS_E)) != 0) {
1613 * A bogus flag was set; assume it's a continuation.
1620 case SESSION_MESSAGE:
1622 * This is variable-length.
1623 * All we know is that it shouldn't be zero.
1624 * (XXX - can we get zero-length messages?
1625 * Not with SMB, but perhaps other NetBIOS-based
1626 * protocols have them.)
1632 case SESSION_REQUEST:
1634 * This is variable-length.
1635 * The names are DNS-encoded 32-byte values;
1636 * we need at least 2 bytes (one for each name;
1637 * actually, we should have more for the first
1638 * name, as there's no name preceding it so
1639 * there should be no compression), and we
1640 * shouldn't have more than 128 bytes (actually,
1641 * we shouldn't have that many).
1643 * XXX - actually, MacOS X 10.1 (yes, that's
1644 * redundant, but that's what Apple calls it,
1645 * not MacOS X.1) puts names longer than 16
1646 * characters into session request messages,
1647 * so we can have more than 32 bytes of
1648 * name value, so we can have more than 128
1651 if (length < 2 || length > 256)
1655 case POSITIVE_SESSION_RESPONSE:
1657 * This has no data, so the length must be zero.
1663 case NEGATIVE_SESSION_RESPONSE:
1665 * This has 1 byte of data.
1671 case RETARGET_SESSION_RESPONSE:
1673 * This has 6 bytes of data.
1679 case SESSION_KEEP_ALIVE:
1681 * This has no data, so the length must be zero.
1689 * Unknown message type; assume it's a continuation.
1695 if (check_col(pinfo->cinfo, COL_INFO)) {
1696 col_add_fstr(pinfo->cinfo, COL_INFO,
1697 val_to_str(msg_type, message_types, "Unknown (%02x)"));
1700 while (max_data > 0) {
1701 len = dissect_nbss_packet(tvb, offset, pinfo, tree, max_data,
1711 * It looks like a continuation.
1713 if (check_col(pinfo->cinfo, COL_INFO))
1714 col_add_fstr(pinfo->cinfo, COL_INFO, "NBSS Continuation Message");
1717 ti = proto_tree_add_item(tree, proto_nbss, tvb, 0,
1719 nbss_tree = proto_item_add_subtree(ti, ett_nbss);
1720 proto_tree_add_text(nbss_tree, tvb, 0, max_data,
1721 "Continuation data");
1726 proto_register_nbt(void)
1729 static hf_register_info hf_nbns[] = {
1730 { &hf_nbns_response,
1731 { "Response", "nbns.response",
1732 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1733 "TRUE if NBNS response", HFILL }},
1735 { "Query", "nbns.query",
1736 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1737 "TRUE if NBNS query", HFILL }},
1738 { &hf_nbns_transaction_id,
1739 { "Transaction ID", "nbns.id",
1740 FT_UINT16, BASE_HEX, NULL, 0x0,
1741 "Identification of transaction", HFILL }},
1742 { &hf_nbns_count_questions,
1743 { "Questions", "nbns.count.queries",
1744 FT_UINT16, BASE_DEC, NULL, 0x0,
1745 "Number of queries in packet", HFILL }},
1746 { &hf_nbns_count_answers,
1747 { "Answer RRs", "nbns.count.answers",
1748 FT_UINT16, BASE_DEC, NULL, 0x0,
1749 "Number of answers in packet", HFILL }},
1750 { &hf_nbns_count_auth_rr,
1751 { "Authority RRs", "nbns.count.auth_rr",
1752 FT_UINT16, BASE_DEC, NULL, 0x0,
1753 "Number of authoritative records in packet", HFILL }},
1754 { &hf_nbns_count_add_rr,
1755 { "Additional RRs", "nbns.count.add_rr",
1756 FT_UINT16, BASE_DEC, NULL, 0x0,
1757 "Number of additional records in packet", HFILL }}
1760 static hf_register_info hf_nbdgm[] = {
1762 { "Message Type", "nbdgm.type",
1763 FT_UINT8, BASE_DEC, VALS(nbds_msgtype_vals), 0x0,
1764 "NBDGM message type", HFILL }},
1765 { &hf_nbdgm_fragment,
1766 { "More fragments follow", "nbdgm.next",
1767 FT_BOOLEAN, BASE_NONE, TFS(&yesno), 0x0,
1768 "TRUE if more fragments follow", HFILL }},
1770 { "This is first fragment", "nbdgm.first",
1771 FT_BOOLEAN, BASE_NONE, TFS(&yesno), 0x0,
1772 "TRUE if first fragment", HFILL }},
1773 { &hf_nbdgm_node_type,
1774 { "Node Type", "nbdgm.node_type",
1775 FT_UINT8, BASE_DEC, VALS(node_type_vals), 0x0,
1776 "Node type", HFILL }},
1777 { &hf_nbdgm_datagram_id,
1778 { "Datagram ID", "nbdgm.dgram_id",
1779 FT_UINT16, BASE_HEX, NULL, 0x0,
1780 "Datagram identifier", HFILL }},
1782 { "Source IP", "nbdgm.src.ip",
1783 FT_IPv4, BASE_NONE, NULL, 0x0,
1784 "Source IPv4 address", HFILL }},
1785 { &hf_nbdgm_src_port,
1786 { "Source Port", "nbdgm.src.port",
1787 FT_UINT16, BASE_DEC, NULL, 0x0,
1788 "Source port", HFILL }}
1791 static hf_register_info hf_nbss[] = {
1793 { "Message Type", "nbss.type",
1794 FT_UINT8, BASE_DEC, NULL, 0x0,
1795 "NBSS message type", HFILL }},
1797 { "Flags", "nbss.flags",
1798 FT_UINT8, BASE_HEX, NULL, 0x0,
1799 "NBSS message flags", HFILL }}
1801 static gint *ett[] = {
1806 &ett_nbns_name_flags,
1814 module_t *nbss_module;
1816 proto_nbns = proto_register_protocol("NetBIOS Name Service", "NBNS", "nbns");
1817 proto_register_field_array(proto_nbns, hf_nbns, array_length(hf_nbns));
1819 proto_nbdgm = proto_register_protocol("NetBIOS Datagram Service",
1821 proto_register_field_array(proto_nbdgm, hf_nbdgm, array_length(hf_nbdgm));
1823 proto_nbss = proto_register_protocol("NetBIOS Session Service",
1825 proto_register_field_array(proto_nbss, hf_nbss, array_length(hf_nbss));
1827 proto_register_subtree_array(ett, array_length(ett));
1829 nbss_module = prefs_register_protocol(proto_nbss, NULL);
1830 prefs_register_bool_preference(nbss_module, "desegment_nbss_commands",
1831 "Desegment all NBSS packets spanning multiple TCP segments",
1832 "Whether NBSS dissector should desegment all packets spanning multiple TCP segments",
1837 proto_reg_handoff_nbt(void)
1839 dissector_handle_t nbns_handle, nbdgm_handle, nbss_handle;
1841 nbns_handle = create_dissector_handle(dissect_nbns, proto_nbns);
1842 dissector_add("udp.port", UDP_PORT_NBNS, nbns_handle);
1843 nbdgm_handle = create_dissector_handle(dissect_nbdgm, proto_nbdgm);
1844 dissector_add("udp.port", UDP_PORT_NBDGM, nbdgm_handle);
1845 nbss_handle = create_dissector_handle(dissect_nbss, proto_nbss);
1846 dissector_add("tcp.port", TCP_PORT_NBSS, nbss_handle);
1847 dissector_add("tcp.port", TCP_PORT_CIFS, nbss_handle);