Give the IPX dissector dissector hash tables for the IPX type and socket
[obnox/wireshark/wip.git] / packet-ipx.c
1 /* packet-ipx.c
2  * Routines for NetWare's IPX
3  * Gilbert Ramirez <gram@xiexie.org>
4  *
5  * $Id: packet-ipx.c,v 1.60 2000/05/30 03:35:51 guy 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 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #include <stdio.h>
36 #include <glib.h>
37 #include "etypes.h"
38 #include "ppptypes.h"
39 #include "llcsaps.h"
40 #include "packet.h"
41 #include "packet-ipx.h"
42 #include "packet-nbipx.h"
43 #include "resolv.h"
44
45 #include "packet-snmp.h"
46
47 /* The information in this module (IPX, SPX, NCP) comes from:
48         NetWare LAN Analysis, Second Edition
49         Laura A. Chappell and Dan E. Hakes
50         (c) 1994 Novell, Inc.
51         Novell Press, San Jose.
52         ISBN: 0-7821-1362-1
53
54   And from the ncpfs source code by Volker Lendecke
55
56 */
57         
58 static int proto_ipx = -1;
59 static int hf_ipx_checksum = -1;
60 static int hf_ipx_len = -1;
61 static int hf_ipx_hops = -1;
62 static int hf_ipx_packet_type = -1;
63 static int hf_ipx_dnet = -1;
64 static int hf_ipx_dnode = -1;
65 static int hf_ipx_dsocket = -1;
66 static int hf_ipx_snet = -1;
67 static int hf_ipx_snode = -1;
68 static int hf_ipx_ssocket = -1;
69
70 static gint ett_ipx = -1;
71
72 static dissector_table_t ipx_type_dissector_table;
73 static dissector_table_t ipx_socket_dissector_table;
74
75 static int proto_spx = -1;
76 static int hf_spx_connection_control = -1;
77 static int hf_spx_datastream_type = -1;
78 static int hf_spx_src_id = -1;
79 static int hf_spx_dst_id = -1;
80 static int hf_spx_seq_nr = -1;
81 static int hf_spx_ack_nr = -1;
82 static int hf_spx_all_nr = -1;
83
84 static gint ett_spx = -1;
85
86 static int proto_ipxrip = -1;
87 static int hf_ipxrip_request = -1;
88 static int hf_ipxrip_response = -1;
89
90 static gint ett_ipxrip = -1;
91
92 static int proto_sap = -1;
93 static int hf_sap_request = -1;
94 static int hf_sap_response = -1;
95
96 static gint ett_ipxsap = -1;
97 static gint ett_ipxsap_server = -1;
98
99 static gint ett_ipxmsg = -1;
100 static int proto_ipxmsg = -1;
101 static int hf_msg_conn = -1;
102 static int hf_msg_sigchar = -1;
103
104 static void
105 dissect_spx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree);
106
107 static void
108 dissect_ipxrip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree);
109
110 static void
111 dissect_ipxsap(const u_char *pd, int offset, frame_data *fd, proto_tree *tree);
112
113 static void
114 dissect_ipxmsg(const u_char *pd, int offset, frame_data *fd, proto_tree *tree);
115
116 #define UDP_PORT_IPX    213             /* RFC 1234 */
117
118 struct port_info {
119         guint16 port;
120         char    *text;
121 };
122
123 struct conn_info {
124         guint8  ctrl;
125         char    *text;
126 };
127
128 struct server_info {
129         guint16 type;
130         char    *text;
131 };
132
133 /* ================================================================= */
134 /* IPX                                                               */
135 /* ================================================================= */
136
137 static struct port_info ports[] = {
138         { IPX_SOCKET_PING_CISCO,                "CISCO PING" },
139         { IPX_SOCKET_NCP,                       "NCP" },
140         { IPX_SOCKET_SAP,                       "SAP" },
141         { IPX_SOCKET_IPXRIP,                    "RIP" },
142         { IPX_SOCKET_NETBIOS,                   "NetBIOS" },
143         { IPX_SOCKET_DIAGNOSTIC,                "Diagnostic" },
144         { IPX_SOCKET_SERIALIZATION,             "Serialization" },
145         { IPX_SOCKET_NWLINK_SMB_NAMEQUERY,      "NWLink SMB Name Query" },
146         { IPX_SOCKET_NWLINK_SMB_DGRAM,          "NWLink SMB Datagram" },
147         { IPX_SOCKET_NWLINK_SMB_BROWSE,         "NWLink SMB Browse" },
148         { IPX_SOCKET_ATTACHMATE_GW,             "Attachmate Gateway" },
149         { IPX_SOCKET_IPX_MESSAGE,               "IPX Message" },
150         { IPX_SOCKET_SNMP_AGENT,                "SNMP Agent" },
151         { IPX_SOCKET_SNMP_SINK,                 "SNMP Sink" },
152         { IPX_SOCKET_PING_NOVELL,               "NOVELL PING" },
153         { IPX_SOCKET_UDP_TUNNEL,                "UDP Tunnel" },
154         { IPX_SOCKET_TCP_TUNNEL,                "TCP Tunnel" },
155         { IPX_SOCKET_TCP_TUNNEL,                "TCP Tunnel" },
156         { IPX_SOCKET_ADSM,                      "ADSM" },
157         { IPX_SOCKET_EIGRP,                     "Cisco EIGRP for IPX" },
158         { IPX_SOCKET_WIDE_AREA_ROUTER,          "Wide Area Router" },
159         { 0x0000,                               NULL }
160 };
161
162 static char*
163 port_text(guint16 port) {
164         int i=0;
165
166         while (ports[i].text != NULL) {
167                 if (ports[i].port == port) {
168                         return ports[i].text;
169                 }
170                 i++;
171         }
172         return "Unknown";
173 }
174
175 static const value_string ipx_packet_type_vals[] = {
176         { IPX_PACKET_TYPE_IPX,          "IPX" },
177         { IPX_PACKET_TYPE_RIP,          "RIP" },
178         { IPX_PACKET_TYPE_ECHO,         "Echo" },
179         { IPX_PACKET_TYPE_ERROR,        "Error" },
180         { IPX_PACKET_TYPE_PEP,          "PEP" }, /* Packet Exchange Packet */
181         { IPX_PACKET_TYPE_SPX,          "SPX" },
182         { 16,                           "Experimental Protocol" },
183         { IPX_PACKET_TYPE_NCP,          "NCP" },
184         { 18,                           "Experimental Protocol" },
185         { 19,                           "Experimental Protocol" },
186         { IPX_PACKET_TYPE_WANBCAST,     "NetBIOS Broadcast" },
187         { 21,                           "Experimental Protocol" },
188         { 22,                           "Experimental Protocol" },
189         { 23,                           "Experimental Protocol" },
190         { 24,                           "Experimental Protocol" },
191         { 25,                           "Experimental Protocol" },
192         { 26,                           "Experimental Protocol" },
193         { 27,                           "Experimental Protocol" },
194         { 28,                           "Experimental Protocol" },
195         { 29,                           "Experimental Protocol" },
196         { 30,                           "Experimental Protocol" },
197         { 31,                           "Experimental Protocol" },
198         { 0,                            NULL }
199 };
200
201 static const value_string ipxmsg_sigchar_vals[] = {
202         { '?', "Poll inactive station" },
203         { 0, NULL }
204 };
205
206 gchar*
207 ipxnet_to_string(const guint8 *ad)
208 {
209         guint32 addr = pntohl(ad);
210         return ipxnet_to_str_punct(addr, ' ');
211 }
212
213 /* We use a different representation of hardware addresses
214  * than ether_to_str(); we don't put punctuation between the hex
215  * digits.
216  */
217
218 gchar*
219 ipx_addr_to_str(guint32 net, const guint8 *ad)
220 {
221         static gchar    str[3][8+1+MAXNAMELEN+1]; /* 8 digits, 1 period, NAME, 1 null */
222         static gchar    *cur;
223         char            *name;
224
225         if (cur == &str[0][0]) {
226                 cur = &str[1][0];
227         } else if (cur == &str[1][0]) {
228                 cur = &str[2][0];
229         } else {
230                 cur = &str[0][0];
231         }
232
233         name = get_ether_name_if_known(ad);
234
235         if (name) {
236                 sprintf(cur, "%s.%s", get_ipxnet_name(net), name);
237         }
238         else {
239                 sprintf(cur, "%s.%s", get_ipxnet_name(net), ether_to_str_punct(ad, '\0'));
240         }
241         return cur;
242 }
243
244 gchar *
245 ipxnet_to_str_punct(const guint32 ad, char punct) {
246   static gchar  str[3][12];
247   static gchar *cur;
248   gchar        *p;
249   int          i;
250   guint32      octet;
251   static const gchar hex_digits[16] = "0123456789ABCDEF";
252   static const guint32  octet_mask[4] =
253           { 0xff000000 , 0x00ff0000, 0x0000ff00, 0x000000ff };
254
255   if (cur == &str[0][0]) {
256     cur = &str[1][0];
257   } else if (cur == &str[1][0]) {  
258     cur = &str[2][0];
259   } else {  
260     cur = &str[0][0];
261   }
262   p = &cur[12];
263   *--p = '\0';
264   i = 3;
265   for (;;) {
266     octet = (ad & octet_mask[i]) >> ((3 - i) * 8);
267     *--p = hex_digits[octet&0xF];
268     octet >>= 4;
269     *--p = hex_digits[octet&0xF];
270     if (i == 0)
271       break;
272     if (punct)
273       *--p = punct;
274     i--;
275   }
276   return p;
277 }
278
279 void
280 capture_ipx(const u_char *pd, int offset, packet_counts *ld)
281 {
282         ld->ipx++;
283 }
284
285 void
286 dissect_ipx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
287
288         proto_tree      *ipx_tree;
289         proto_item      *ti;
290         guint8          ipx_type, ipx_hops;
291         guint16         ipx_checksum, ipx_length;
292         int             len;
293         guint8          *ipx_snode, *ipx_dnode, *ipx_snet, *ipx_dnet;
294
295         guint16         ipx_dsocket, ipx_ssocket;
296         guint32         ipx_dnet_val, ipx_snet_val;
297
298         /* Calculate here for use in pinfo and in tree */
299         ipx_dnet = (guint8*)&pd[offset+6];
300         ipx_snet = (guint8*)&pd[offset+18];
301         ipx_dnet_val = pntohl(ipx_dnet);
302         ipx_snet_val = pntohl(ipx_snet);
303         ipx_dsocket = pntohs(&pd[offset+16]);
304         ipx_ssocket = pntohs(&pd[offset+28]);
305         ipx_dnode = (guint8*)&pd[offset+10];
306         ipx_snode = (guint8*)&pd[offset+22];
307         ipx_type = pd[offset+5];
308         ipx_length = pntohs(&pd[offset+2]);
309
310         /* Length of IPX datagram plus headers above it. */
311         len = ipx_length + offset;
312
313         /* Set the payload and captured-payload lengths to the minima of
314            (the IPX length plus the length of the headers above it) and
315            the frame lengths. */
316         if (pi.len > len)
317                 pi.len = len;
318         if (pi.captured_len > len)
319                 pi.captured_len = len;
320
321         SET_ADDRESS(&pi.net_src, AT_IPX, 10, &pd[offset+18]);
322         SET_ADDRESS(&pi.src, AT_IPX, 10, &pd[offset+18]);
323         SET_ADDRESS(&pi.net_dst, AT_IPX, 10, &pd[offset+6]);
324         SET_ADDRESS(&pi.dst, AT_IPX, 10, &pd[offset+6]);
325
326         if (check_col(fd, COL_PROTOCOL))
327                 col_add_str(fd, COL_PROTOCOL, "IPX");
328         if (check_col(fd, COL_INFO))
329                 col_add_fstr(fd, COL_INFO, "%s (0x%04X)", port_text(ipx_dsocket),
330                                 ipx_dsocket);
331
332         if (tree) {
333                 ipx_checksum = pntohs(&pd[offset]);
334                 ipx_hops = pd[offset+4];
335
336                 ti = proto_tree_add_item(tree, proto_ipx, NullTVB, offset, 30, NULL);
337                 ipx_tree = proto_item_add_subtree(ti, ett_ipx);
338                 proto_tree_add_item(ipx_tree, hf_ipx_checksum, NullTVB, offset, 2, ipx_checksum);
339                 proto_tree_add_uint_format(ipx_tree, hf_ipx_len, NullTVB, offset+2, 2, ipx_length,
340                         "Length: %d bytes", ipx_length);
341                 proto_tree_add_uint_format(ipx_tree, hf_ipx_hops, NullTVB, offset+4, 1, ipx_hops,
342                         "Transport Control: %d hops", ipx_hops);
343                 proto_tree_add_item(ipx_tree, hf_ipx_packet_type, NullTVB, offset+5, 1, ipx_type);
344                 proto_tree_add_item(ipx_tree, hf_ipx_dnet, NullTVB, offset+6, 4, ipx_dnet_val);
345                 proto_tree_add_item(ipx_tree, hf_ipx_dnode, NullTVB, offset+10, 6, ipx_dnode);
346                 proto_tree_add_uint_format(ipx_tree, hf_ipx_dsocket, NullTVB, offset+16, 2,
347                         ipx_dsocket, "Destination Socket: %s (0x%04X)",
348                         port_text(ipx_dsocket), ipx_dsocket);
349                 proto_tree_add_item(ipx_tree, hf_ipx_snet, NullTVB, offset+18, 4, ipx_snet_val);
350                 proto_tree_add_item(ipx_tree, hf_ipx_snode, NullTVB, offset+22, 6, ipx_snode);
351                 proto_tree_add_uint_format(ipx_tree, hf_ipx_ssocket, NullTVB, offset+28, 2,
352                         ipx_ssocket, "Source Socket: %s (0x%04X)", port_text(ipx_ssocket),
353                         ipx_ssocket);
354         }
355         offset += 30;
356
357         if (dissector_try_port(ipx_type_dissector_table, ipx_type, pd,
358             offset, fd, tree))
359                 return;
360         switch (ipx_type) {
361                 case IPX_PACKET_TYPE_WANBCAST:
362                 case IPX_PACKET_TYPE_PEP:
363                         if (ipx_dsocket == IPX_SOCKET_NETBIOS) {
364                                 dissect_nbipx(pd, offset, fd, tree);
365                                 return;
366                         }
367                         /* else fall through */
368
369                 case 0: /* IPX, fall through to default */
370                         /* XXX - should type 0's be dissected as NBIPX
371                            if they're aimed at the NetBIOS socket? */
372                         break;
373         }
374         if (dissector_try_port(ipx_socket_dissector_table, ipx_dsocket, pd,
375             offset, fd, tree))
376                 return;
377         if (dissector_try_port(ipx_socket_dissector_table, ipx_ssocket, pd,
378             offset, fd, tree))
379                 return;
380         dissect_data(pd, offset, fd, tree);
381 }
382
383
384 /* ================================================================= */
385 /* SPX                                                               */
386 /* ================================================================= */
387 static char*
388 spx_conn_ctrl(u_char ctrl)
389 {
390         int i=0;
391
392         static struct conn_info conns[] = {
393                 { 0x10, "End-of-Message" },
394                 { 0x20, "Attention" },
395                 { 0x40, "Acknowledgment Required"},
396                 { 0x80, "System Packet"},
397                 { 0x00, NULL }
398         };
399
400         while (conns[i].text != NULL) {
401                 if (conns[i].ctrl == ctrl) {
402                         return conns[i].text;
403                 }
404                 i++;
405         }
406         return "Unknown";
407 }
408
409 static char*
410 spx_datastream(u_char type)
411 {
412         switch (type) {
413                 case 0xfe:
414                         return "End-of-Connection";
415                 case 0xff:
416                         return "End-of-Connection Acknowledgment";
417                 default:
418                         return "Client-Defined";
419         }
420 }
421
422 static void
423 dissect_spx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
424         proto_tree      *spx_tree;
425         proto_item      *ti;
426
427         if (check_col(fd, COL_PROTOCOL))
428                 col_add_str(fd, COL_PROTOCOL, "SPX");
429         if (check_col(fd, COL_INFO))
430                 col_add_str(fd, COL_INFO, "SPX");
431
432         if (tree) {
433                 ti = proto_tree_add_item(tree, proto_spx, NullTVB, offset, 12, NULL);
434                 spx_tree = proto_item_add_subtree(ti, ett_spx);
435
436                 proto_tree_add_uint_format(spx_tree, hf_spx_connection_control, NullTVB,
437                                            offset,      1,
438                                            pd[offset],
439                                            "Connection Control: %s (0x%02X)",
440                                            spx_conn_ctrl(pd[offset]), 
441                                            pd[offset]);
442
443                 proto_tree_add_uint_format(spx_tree, hf_spx_datastream_type, NullTVB,
444                                            offset+1,     1,
445                                            pd[offset+1],
446                                            "Datastream Type: %s (0x%02X)",
447                                            spx_datastream(pd[offset+1]), 
448                                            pd[offset+1]);
449
450                 proto_tree_add_item(spx_tree, hf_spx_src_id, NullTVB, 
451                                     offset+2,     2,
452                                     pntohs( &pd[offset+2] ));
453
454                 proto_tree_add_item(spx_tree, hf_spx_dst_id, NullTVB,
455                                     offset+4,     2,
456                                     pntohs( &pd[offset+4] ));
457
458                 proto_tree_add_item(spx_tree, hf_spx_seq_nr, NullTVB, 
459                                     offset+6,     2,
460                                     pntohs( &pd[offset+6] ) );
461
462                 proto_tree_add_item(spx_tree, hf_spx_ack_nr, NullTVB,
463                                     offset+8,     2,
464                                     pntohs( &pd[offset+8] ) );
465
466                 proto_tree_add_item(spx_tree, hf_spx_all_nr, NullTVB,
467                                     offset+10,     2,
468                                     pntohs( &pd[offset+10] ) );
469
470                 offset += 12;
471                 dissect_data(pd, offset, fd, tree);
472         }
473 }
474
475 /* ================================================================= */
476 /* IPX Message                                                       */
477 /* ================================================================= */
478 static void
479 dissect_ipxmsg(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
480         proto_tree      *msg_tree;
481         proto_item      *ti;
482         u_char conn_number, sig_char;
483
484         if ( ! BYTES_ARE_IN_FRAME(offset,2) )
485         {
486                 return;
487         }
488
489         conn_number = pd[offset];
490         sig_char = pd[offset+1];
491
492         if (check_col(fd, COL_PROTOCOL))
493          col_add_str(fd, COL_PROTOCOL, "IPX MSG");
494         if (check_col(fd, COL_PROTOCOL)) {
495                 col_add_fstr(fd, COL_INFO, 
496                         "%s, Connection %d", 
497                         val_to_str(sig_char, ipxmsg_sigchar_vals, "Unknown Signature Char"), conn_number);
498         }
499
500         if (tree) {
501                 ti = proto_tree_add_item(tree, proto_ipxmsg, NullTVB, offset, END_OF_FRAME, NULL);
502                 msg_tree = proto_item_add_subtree(ti, ett_ipxmsg);
503
504                 proto_tree_add_item(msg_tree, hf_msg_conn, NullTVB, offset, 1, conn_number);
505                 proto_tree_add_item(msg_tree, hf_msg_sigchar, NullTVB, offset+1, 1, sig_char);
506         }
507 }
508
509
510 /* ================================================================= */
511 /* IPX RIP                                                           */
512 /* ================================================================= */
513 static void
514 dissect_ipxrip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
515         proto_tree      *rip_tree;
516         proto_item      *ti;
517         guint16         operation;
518         struct ipx_rt_def route;
519         int             cursor;
520
521         char            *rip_type[2] = { "Request", "Response" };
522
523         operation = pntohs(&pd[offset]) - 1;
524
525         if (check_col(fd, COL_PROTOCOL))
526          col_add_str(fd, COL_PROTOCOL, "IPX RIP");
527         if (check_col(fd, COL_PROTOCOL)) {
528          if (operation < 2) {
529                  col_add_str(fd, COL_INFO, rip_type[operation]);
530          }
531          else {
532                  col_add_str(fd, COL_INFO, "Unknown Packet Type");
533          }
534         }
535
536         if (tree) {
537                 ti = proto_tree_add_item(tree, proto_ipxrip, NullTVB, offset, END_OF_FRAME, NULL);
538                 rip_tree = proto_item_add_subtree(ti, ett_ipxrip);
539
540                 if (operation < 2) {
541                         proto_tree_add_text(rip_tree, NullTVB, offset, 2,
542                         "RIP packet type: %s", rip_type[operation]);
543
544                         if (operation == 0) {
545                           proto_tree_add_item_hidden(rip_tree, 
546                                                      hf_ipxrip_request, 
547                                                      NullTVB, offset, 2, 1);
548                         } else {
549                           proto_tree_add_item_hidden(rip_tree, 
550                                                      hf_ipxrip_response, 
551                                                      NullTVB, offset, 2, 1);
552                         }
553
554                 }
555                 else {
556                         proto_tree_add_text(rip_tree, NullTVB, offset, 2, "Unknown RIP packet type");
557                 }
558
559                 for (cursor = offset + 2; cursor < pi.captured_len; cursor += 8) {
560                         memcpy(&route.network, &pd[cursor], 4);
561                         route.hops = pntohs(&pd[cursor+4]);
562                         route.ticks = pntohs(&pd[cursor+6]);
563
564                         if (operation == IPX_RIP_REQUEST - 1) {
565                                 proto_tree_add_text(rip_tree, NullTVB, cursor,      8,
566                                         "Route Vector: %s, %d hop%s, %d tick%s",
567                                         ipxnet_to_string((guint8*)&route.network),
568                                         route.hops,  route.hops  == 1 ? "" : "s",
569                                         route.ticks, route.ticks == 1 ? "" : "s");
570                         }
571                         else {
572                                 proto_tree_add_text(rip_tree, NullTVB, cursor,      8,
573                                         "Route Vector: %s, %d hop%s, %d tick%s (%d ms)",
574                                         ipxnet_to_string((guint8*)&route.network),
575                                         route.hops,  route.hops  == 1 ? "" : "s",
576                                         route.ticks, route.ticks == 1 ? "" : "s",
577                                         route.ticks * 1000 / 18);
578                         }
579                 }
580         }
581 }
582
583
584
585 /* ================================================================= */
586 /* SAP                                                                   */
587 /* ================================================================= */
588 static char*
589 server_type(guint16 type)
590 {
591         int i=0;
592
593         /* some of these are from ncpfs, others are from the book */
594         static struct server_info       servers[] = {
595                 { 0x0001,       "User" },
596                 { 0x0002,       "User Group" },
597                 { 0x0003,       "Print Queue" },
598                 { 0x0004,       "File server" },
599                 { 0x0005,       "Job server" },
600                 { 0x0007,       "Print server" },
601                 { 0x0008,       "Archive server" },
602                 { 0x0009,       "Archive server" },
603                 { 0x000a,       "Job queue" },
604                 { 0x000b,       "Administration" },
605                 { 0x0021,       "NAS SNA gateway" },
606                 { 0x0024,       "Remote bridge" },
607                 { 0x0026,       "Bridge server" },
608                 { 0x0027,       "TCP/IP gateway" },
609                 { 0x002d,       "Time Synchronization VAP" },
610                 { 0x002e,       "Archive Server Dynamic SAP" },
611                 { 0x0047,       "Advertising print server" },
612                 { 0x004b,       "Btrieve VAP 5.0" },
613                 { 0x004c,       "SQL VAP" },
614                 { 0x0050,       "Btrieve VAP" },
615                 { 0x0053,       "Print Queue VAP" },
616                 { 0x007a,       "TES NetWare for VMS" },
617                 { 0x0098,       "NetWare access server" },
618                 { 0x009a,       "Named Pipes server" },
619                 { 0x009e,       "Portable NetWare Unix" },
620                 { 0x0107,       "NetWare 386" },
621                 { 0x0111,       "Test server" },
622                 { 0x0133,       "NetWare Name Service" },
623                 { 0x0166,       "NetWare management" },
624                 { 0x023f,       "SMS Testing and Development" },
625                 { 0x026a,       "NetWare management" },
626                 { 0x026b,       "Time synchronization" },
627                 { 0x027b,       "NetWare Management Agent" },
628                 { 0x0278,       "NetWare Directory server" },
629                 { 0x030c,       "HP LaserJet / Quick Silver" },
630                 { 0x0355,       "Arcada Software" },
631                 { 0x0361,       "NETINELO" },
632                 { 0x037e,       "Powerchute UPS Monitoring" },
633                 { 0x03e1,       "UnixWare Application Server" },
634                 { 0x044c,       "Archive" },
635                 { 0x055d,       "Attachmate SNA gateway" },
636                 { 0x0610,       "Adaptec SCSI Management" },
637                 { 0x0640,       "NT Server-RPC/GW for NW/Win95 User Level Sec" },
638                 { 0x064e,       "NT Server-IIS" },
639                 { 0x0810,       "ELAN License Server Demo" },
640                 { 0x8002,       "Intel NetPort Print Server" },
641
642 /* For any unidentified ones, I found a really big list of them at: */
643 /*    http://www.inpnet.org/cnpweb/saplist.txt */
644 /*    http://www.isi.edu/in-notes/iana/assignments/novell-sap-numbers */
645
646                 { 0x0000,       NULL }
647         };
648
649         while (servers[i].text != NULL) {
650                 if (servers[i].type == type) {
651                         return servers[i].text;
652                 }
653                 i++;
654         }
655         return "Unknown";
656 }
657
658 static void
659 dissect_ipxsap(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
660
661         proto_tree      *sap_tree, *s_tree;
662         proto_item      *ti;
663         int             cursor;
664         struct sap_query query;
665         struct sap_server_ident server;
666
667         char            *sap_type[4] = { "General Query", "General Response",
668                 "Nearest Query", "Nearest Response" };
669
670         query.query_type = pntohs(&pd[offset]);
671         query.server_type = pntohs(&pd[offset+2]);
672
673         if (check_col(fd, COL_PROTOCOL))
674                 col_add_str(fd, COL_PROTOCOL, "SAP");
675         if (check_col(fd, COL_INFO)) {
676                 if (query.query_type >= 1 && query.query_type <= 4) {
677                         col_add_str(fd, COL_INFO, sap_type[query.query_type - 1]);
678                 }
679                 else {
680                         col_add_str(fd, COL_INFO, "Unknown Packet Type");
681                 }
682         }
683
684         if (tree) {
685                 ti = proto_tree_add_item(tree, proto_sap, NullTVB, offset, END_OF_FRAME, NULL);
686                 sap_tree = proto_item_add_subtree(ti, ett_ipxsap);
687
688                 if (query.query_type >= 1 && query.query_type <= 4) {
689                         proto_tree_add_text(sap_tree, NullTVB, offset, 2, sap_type[query.query_type - 1]);
690                         if ((query.query_type - 1) % 2) {
691                           proto_tree_add_item_hidden(sap_tree, 
692                                                      hf_sap_response, 
693                                                      NullTVB, offset, 2, 1);
694                         } else {
695                           proto_tree_add_item_hidden(sap_tree, 
696                                                      hf_sap_request, 
697                                                      NullTVB, offset, 2, 1);
698                         }
699                 }
700                 else {
701                         proto_tree_add_text(sap_tree, NullTVB, offset, 2,
702                                         "Unknown SAP Packet Type %d", query.query_type);
703                 }
704
705                 if (query.query_type == IPX_SAP_GENERAL_RESPONSE ||
706                                 query.query_type == IPX_SAP_NEAREST_RESPONSE) { /* responses */
707
708                         for (cursor = offset + 2; (cursor + 64) <= pi.captured_len; cursor += 64) {
709                                 server.server_type = pntohs(&pd[cursor]);
710                                 memcpy(server.server_name, &pd[cursor+2], 48);
711                                 memcpy(&server.server_network, &pd[cursor+50], 4);
712                                 memcpy(&server.server_node, &pd[cursor+54], 6);
713                                 server.server_port = pntohs(&pd[cursor+60]);
714                                 server.intermediate_network = pntohs(&pd[cursor+62]);
715
716                                 ti = proto_tree_add_text(sap_tree, NullTVB, cursor+2, 48,
717                                         "Server Name: %s", server.server_name);
718                                 s_tree = proto_item_add_subtree(ti, ett_ipxsap_server);
719
720                                 proto_tree_add_text(s_tree, NullTVB, cursor, 2, "Server Type: %s (0x%04X)",
721                                                 server_type(server.server_type), server.server_type);
722                                 proto_tree_add_text(s_tree, NullTVB, cursor+50, 4, "Network: %s",
723                                                 ipxnet_to_string((guint8*)&pd[cursor+50]));
724                                 proto_tree_add_text(s_tree, NullTVB, cursor+54, 6, "Node: %s",
725                                                 ether_to_str((guint8*)&pd[cursor+54]));
726                                 proto_tree_add_text(s_tree, NullTVB, cursor+60, 2, "Socket: %s (0x%04X)",
727                                                 port_text(server.server_port), server.server_port);
728                                 proto_tree_add_text(s_tree, NullTVB, cursor+62, 2,
729                                                 "Intermediate Networks: %d",
730                                                 server.intermediate_network);
731                         }
732                 }
733                 else {  /* queries */
734                         proto_tree_add_text(sap_tree, NullTVB, offset+2, 2, "Server Type: %s (0x%04X)",
735                                         server_type(query.server_type), query.server_type);
736                 }
737         }
738 }
739
740 void
741 proto_register_ipx(void)
742 {
743         static hf_register_info hf_ipx[] = {
744                 { &hf_ipx_checksum,
745                 { "Checksum",           "ipx.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
746                         "" }},
747
748                 { &hf_ipx_len,
749                 { "Length",             "ipx.len", FT_UINT16, BASE_DEC, NULL, 0x0,
750                         "" }},
751
752                 { &hf_ipx_hops,
753                 { "Transport Control (Hops)", "ipx.hops", FT_UINT8, BASE_DEC, NULL, 0x0,
754                         "" }},
755
756                 { &hf_ipx_packet_type,
757                 { "Packet Type",        "ipx.packet_type", FT_UINT8, BASE_HEX, VALS(ipx_packet_type_vals),
758                         0x0,
759                         "" }},
760
761                 { &hf_ipx_dnet,
762                 { "Destination Network","ipx.dst.net", FT_IPXNET, BASE_NONE, NULL, 0x0,
763                         "" }},
764
765                 { &hf_ipx_dnode,
766                 { "Destination Node",   "ipx.dst.node", FT_ETHER, BASE_NONE, NULL, 0x0,
767                         "" }},
768
769                 { &hf_ipx_dsocket,
770                 { "Destination Socket", "ipx.dst.socket", FT_UINT16, BASE_HEX, NULL, 0x0,
771                         "" }},
772
773                 { &hf_ipx_snet,
774                 { "Source Network","ipx.src.net", FT_IPXNET, BASE_NONE, NULL, 0x0,
775                         "" }},
776
777                 { &hf_ipx_snode,
778                 { "Source Node",        "ipx.src.node", FT_ETHER, BASE_NONE, NULL, 0x0,
779                         "" }},
780
781                 { &hf_ipx_ssocket,
782                 { "Source Socket",      "ipx.src.socket", FT_UINT16, BASE_HEX, NULL, 0x0,
783                         "" }},
784         };
785
786         static hf_register_info hf_spx[] = {
787                 { &hf_spx_connection_control,
788                 { "Connection Control",         "spx.ctl", 
789                   FT_UINT8,     BASE_HEX,       NULL,   0x0,
790                   "" }},
791
792                 { &hf_spx_datastream_type,
793                 { "Datastream type",            "spx.type", 
794                   FT_UINT8,     BASE_HEX,       NULL,   0x0,
795                   "" }},
796
797                 { &hf_spx_src_id,
798                 { "Source Connection ID",       "spx.src", 
799                   FT_UINT16,    BASE_DEC,       NULL,   0x0,
800                   "" }},
801
802                 { &hf_spx_dst_id,
803                 { "Destination Connection ID",  "spx.dst", 
804                   FT_UINT16,    BASE_DEC,       NULL,   0x0,
805                   "" }},
806
807                 { &hf_spx_seq_nr,
808                 { "Sequence Number",            "spx.seq", 
809                   FT_UINT16,    BASE_DEC,       NULL,   0x0,
810                   "" }},
811
812                 { &hf_spx_ack_nr,
813                 { "Acknowledgment Number",      "spx.ack", 
814                   FT_UINT16,    BASE_DEC,       NULL,   0x0,
815                   "" }},
816
817                 { &hf_spx_all_nr,
818                 { "Allocation Number",          "spx.alloc", 
819                   FT_UINT16,    BASE_DEC,       NULL,   0x0,
820                   "" }}
821         };
822
823         static hf_register_info hf_ipxrip[] = {
824                 { &hf_ipxrip_request,
825                 { "Request",                    "ipxrip.request", 
826                   FT_BOOLEAN,   BASE_NONE,      NULL,   0x0,
827                   "TRUE if IPX RIP request" }},
828
829                 { &hf_ipxrip_response,
830                 { "Response",                   "ipxrip.response", 
831                   FT_BOOLEAN,   BASE_NONE,      NULL,   0x0,
832                   "TRUE if IPX RIP response" }}
833         };
834
835         static hf_register_info hf_sap[] = {
836                 { &hf_sap_request,
837                 { "Request",                    "ipxsap.request", 
838                   FT_BOOLEAN,   BASE_NONE,      NULL,   0x0,
839                   "TRUE if SAP request" }},
840
841                 { &hf_sap_response,
842                 { "Response",                   "ipxsap.response", 
843                   FT_BOOLEAN,   BASE_NONE,      NULL,   0x0,
844                   "TRUE if SAP response" }}
845         };
846
847         static hf_register_info hf_ipxmsg[] = {
848                 { &hf_msg_conn,
849                 { "Connection Number",                  "ipxmsg.conn", 
850                   FT_UINT8,     BASE_NONE,      NULL,   0x0,
851                   "Connection Number" }},
852
853                 { &hf_msg_sigchar,
854                 { "Signature Char",                     "ipxmsg.sigchar", 
855                   FT_UINT8,     BASE_NONE,      VALS(ipxmsg_sigchar_vals),      0x0,
856                   "Signature Char" }}
857         };
858
859         static gint *ett[] = {
860                 &ett_ipx,
861                 &ett_spx,
862                 &ett_ipxmsg,
863                 &ett_ipxrip,
864                 &ett_ipxsap,
865                 &ett_ipxsap_server,
866         };
867
868         proto_ipx = proto_register_protocol ("Internetwork Packet eXchange", "ipx");
869         proto_register_field_array(proto_ipx, hf_ipx, array_length(hf_ipx));
870
871         proto_spx = proto_register_protocol ("Sequenced Packet eXchange", "spx");
872         proto_register_field_array(proto_spx, hf_spx, array_length(hf_spx));
873
874         proto_ipxrip = proto_register_protocol ("IPX Routing Information Protocol", "ipxrip");
875         proto_register_field_array(proto_ipxrip, hf_ipxrip, array_length(hf_ipxrip));
876
877         proto_ipxmsg = proto_register_protocol ("IPX Message", "ipxmsg");
878         proto_register_field_array(proto_ipxmsg, hf_ipxmsg, array_length(hf_ipxmsg));
879
880         proto_sap = proto_register_protocol ("Service Advertisement Protocol", "ipxsap");
881         proto_register_field_array(proto_sap, hf_sap, array_length(hf_sap));
882
883         proto_register_subtree_array(ett, array_length(ett));
884
885         ipx_type_dissector_table = register_dissector_table("ipx.packet_type");
886         ipx_socket_dissector_table = register_dissector_table("ipx.socket");
887 }
888
889 void
890 proto_reg_handoff_ipx(void)
891 {
892         dissector_add("udp.port", UDP_PORT_IPX, dissect_ipx);
893         dissector_add("ethertype", ETHERTYPE_IPX, dissect_ipx);
894         dissector_add("ppp.protocol", PPP_IPX, dissect_ipx);
895         dissector_add("llc.dsap", SAP_NETWARE, dissect_ipx);
896         dissector_add("ipx.packet_type", IPX_PACKET_TYPE_SPX, dissect_spx);
897         dissector_add("ipx.socket", IPX_SOCKET_SAP, dissect_ipxsap);
898         dissector_add("ipx.socket", IPX_SOCKET_IPXRIP, dissect_ipxrip);
899         dissector_add("ipx.socket", IPX_SOCKET_IPX_MESSAGE, dissect_ipxmsg);
900 }