Silly mistake which caused if(tree) to fail.
[obnox/wireshark/wip.git] / packet-nbipx.c
1 /* packet-nbipx.c
2  * Routines for NetBIOS over IPX packet disassembly
3  * Gilbert Ramirez <gram@verdict.uthscsa.edu>
4  *
5  * $Id: packet-nbipx.c,v 1.3 1998/10/14 05:18:32 gram Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * 
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.
16  * 
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.
21  * 
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.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <gtk/gtk.h>
32 #include <pcap.h>
33
34 #include <stdio.h>
35 #include <memory.h>
36
37 #ifdef HAVE_SYS_TYPES_H
38 # include <sys/types.h>
39 #endif
40
41 #ifdef HAVE_NETINET_IN_H
42 # include <netinet/in.h>
43 #endif
44
45 #include "ethereal.h"
46 #include "packet.h"
47 #include "packet-ipx.h" /* for ipxnet_to_string() */
48
49 enum nbipx_protocol {
50         NETBIOS_NETWARE,
51         NETBIOS_NWLINK
52 };
53
54 static void
55 nbipx_ns(const u_char *pd, int offset, frame_data *fd, GtkTree *tree,
56                 enum nbipx_protocol nbipx);
57
58 /* There is no RFC or public specification of Netware or Microsoft
59  * NetBIOS over IPX packets. I have had to decode the protocol myself,
60  * so there are holes and perhaps errors in this code. (gram)
61  */
62 static char
63 *packet_type[] = {
64                 "",
65                 "Name Query"
66 };
67
68 struct nbipx_header {
69         /* Netware & NT NetBIOS over IPX */
70         guint32         router[8];
71         guint8          name_type;
72         guint8          packet_type;
73
74         char            name[17];
75
76         /* NT NetBIOS over IPX */
77         guint16         junk;
78         char            node_name[17];
79         
80 };
81
82
83 /* NetWare */
84 void
85 dissect_nbipx_ns(const u_char *pd, int offset, frame_data *fd, GtkTree *tree)
86 {
87         nbipx_ns(pd, offset, fd, tree, NETBIOS_NETWARE);
88 }
89
90 void
91 dissect_nwlink_dg(const u_char *pd, int offset, frame_data *fd, GtkTree *tree)
92 {
93         nbipx_ns(pd, offset, fd, tree, NETBIOS_NWLINK);
94 }
95
96
97 static void
98 nbipx_ns(const u_char *pd, int offset, frame_data *fd, GtkTree *tree,
99                 enum nbipx_protocol nbipx)
100 {
101         GtkWidget                       *nbipx_tree, *ti;
102         struct nbipx_header     header;
103         int                                     i, rtr_offset;
104         int                                     name_offset;
105
106         if (nbipx == NETBIOS_NETWARE) {
107                 name_offset = 34;
108         }
109         else {
110                 name_offset = 36;
111         }
112
113
114         header.name_type = pd[offset+32];
115         header.packet_type = pd[offset+33];
116         memcpy(header.name, &pd[offset+name_offset], 16);
117         header.name[16] = 0; /* null-terminate the string */
118
119         if (nbipx == NETBIOS_NWLINK) {
120                 memcpy(header.node_name, &pd[offset+52], 16);
121                 header.node_name[17] = 0; /* null-terminate the string */
122         }
123
124         if (fd->win_info[COL_NUM]) {
125                 if (nbipx == NETBIOS_NETWARE) {
126                         strcpy(fd->win_info[COL_PROTOCOL], "NetBIOS");
127                 }
128                 else {
129                         strcpy(fd->win_info[COL_PROTOCOL], "NWLink");
130                 }
131
132                         switch (header.packet_type) {
133                                 case 1:
134                                         sprintf(fd->win_info[COL_INFO], "Name Query for %s",
135                                                         header.name);
136                                         break;
137
138                                 default:
139                                         strcpy(fd->win_info[COL_INFO], "NetBIOS over IPX");
140                         }
141         }
142
143         if (tree) {
144                 ti = add_item_to_tree(GTK_WIDGET(tree), offset, END_OF_FRAME,
145                                 "NetBIOS over IPX");
146                 nbipx_tree = gtk_tree_new();
147                 add_subtree(ti, nbipx_tree, ETT_NBIPX);
148
149                 if (header.packet_type <= 1) {
150                         add_item_to_tree(nbipx_tree, offset+33, 1,
151                                         "Packet Type: %s (%02X)", packet_type[header.packet_type],
152                                         header.packet_type);
153                 }
154                 else {
155                         add_item_to_tree(nbipx_tree, offset+33, 1,
156                                         "Packet Type: Unknown (%02X)", header.packet_type);
157                 }
158
159                 /* Eight routers are listed */
160                 for (i = 0; i < 8; i++) {
161                         rtr_offset = offset + (i << 2);
162                         memcpy(&header.router[i], &pd[rtr_offset], 4);
163                         if (header.router[i] != 0) {
164                                 add_item_to_tree(nbipx_tree, rtr_offset, 4, "IPX Network: %s",
165                                                 ipxnet_to_string((guint8*)&header.router[i]));
166                         }
167                 }
168
169                 add_item_to_tree(nbipx_tree, offset+32, 1, "Name Type: %02X",
170                                 header.name_type);
171
172                 if (nbipx == NETBIOS_NETWARE) {
173                         add_item_to_tree(nbipx_tree, offset+name_offset, 16,
174                                         "Name String: %s", header.name);
175                 }
176                 else {
177                         add_item_to_tree(nbipx_tree, offset+name_offset, 16,
178                                         "Group Name String: %s", header.name);
179                         add_item_to_tree(nbipx_tree, offset+52, 16,
180                                         "Node Name String: %s", header.node_name);
181
182                 }
183         }
184
185         if (nbipx == NETBIOS_NWLINK) {
186                 dissect_data(pd, offset + 68, fd, tree);
187         }
188 }
189
190
191
192