Copy the RIP header to a buffer, so that we don't blow up if it's
[obnox/wireshark/wip.git] / packet-atalk.c
1 /* packet-ddp.c
2  * Routines for DDP packet disassembly.
3  *
4  * Simon Wilkinson <sxw@dcs.ed.ac.uk>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <gtk/gtk.h>
26
27 #include <stdio.h>
28
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
31 #endif
32
33 #ifdef HAVE_NETINET_IN_H
34 # include <netinet/in.h>
35 #endif
36
37 #include "ethereal.h"
38 #include "packet.h"
39 #include "etypes.h"
40 #include "resolv.h"
41
42 extern packet_info pi;
43
44 typedef struct _e_ddp {
45 #if BYTE_ORDER == BIG_ENDIAN
46   guint16       pad:2,hops:4,len:10;
47 #else
48   guint16       len:10,hops:4,pad:2;
49 #endif
50   guint16       sum,dnet,snet;
51   guint8        dnode,snode;
52   guint8        dport,sport;
53   guint8        type;
54 } e_ddp;
55
56 #define DDP_RTMPDATA    0x01
57 #define DDP_NBP         0x02
58 #define DDP_ATP         0x03
59 #define DDP_AEP         0x04
60 #define DDP_RTMPREQ     0x05
61 #define DDP_ZIP         0x06
62 #define DDP_ADSP        0x07
63
64 void
65 dissect_ddp(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
66   e_ddp       ddp;
67   GtkWidget *ddp_tree, *ti;
68   value_string op_vals[] = { {DDP_RTMPDATA, "AppleTalk Routing Table response or data" },
69                              {DDP_NBP, "AppleTalk Name Binding Protocol packet"},
70                              {DDP_ATP, "AppleTalk Transaction Protocol packet"},
71                              {DDP_AEP, "AppleTalk Echo Protocol packet"},
72                              {DDP_RTMPREQ, "AppleTalk Routing Table request"},
73                              {DDP_ZIP, "AppleTalk Zone Information Protocol packet"},
74                              {DDP_ADSP, "AppleTalk Data Stream Protocol"},
75                              {0, NULL} };
76
77   memcpy(&ddp, &pd[offset], sizeof(e_ddp));
78   ddp.dnet=ntohs(ddp.dnet);
79   ddp.snet=ntohs(ddp.snet);
80   ddp.sum=ntohs(ddp.sum);
81   
82   if (check_col(fd, COL_RES_NET_SRC))
83     col_add_fstr(fd, COL_RES_NET_SRC, "%d.%d:%d", ddp.snet, ddp.snode, ddp.sport);
84   if (check_col(fd, COL_RES_NET_DST))
85     col_add_fstr(fd, COL_RES_NET_DST, "%d.%d:%d", ddp.dnet, ddp.dnode, ddp.dport);
86   if (check_col(fd, COL_PROTOCOL))
87     col_add_str(fd, COL_PROTOCOL, "DDP");
88   if (check_col(fd, COL_INFO))
89     col_add_str(fd, COL_INFO,
90       val_to_str(ddp.type, op_vals, "Unknown DDP protocol (%02x)"));
91   
92   if (tree) {
93     ti = add_item_to_tree(GTK_WIDGET(tree), offset, 13,
94       "Datagram Delivery Protocol");
95     ddp_tree = gtk_tree_new();
96     add_subtree(ti, ddp_tree, ETT_IP);
97     add_item_to_tree(ddp_tree, offset,      1, "Hop count: %d", ddp.hops);
98     add_item_to_tree(ddp_tree, offset,      2, "Datagram length: %d", ddp.len);
99     add_item_to_tree(ddp_tree, offset + 2,  2, "Checksum: %d",ddp.sum);
100     add_item_to_tree(ddp_tree, offset + 4,  2, "Destination Net: %d",ddp.dnet);
101     add_item_to_tree(ddp_tree, offset + 6,  2, "Source Net: %d",ddp.snet);
102     add_item_to_tree(ddp_tree, offset + 8,  1, "Destination Node: %d",ddp.dnode);
103     add_item_to_tree(ddp_tree, offset + 9,  1, "Source Node: %d",ddp.snode);
104     add_item_to_tree(ddp_tree, offset + 10, 1, "Destination Socket: %d",ddp.dport);
105     add_item_to_tree(ddp_tree, offset + 11, 1, "Source Socket: %d",ddp.sport);
106     add_item_to_tree(ddp_tree, offset + 12, 1, "Type: %d",ddp.type);  
107   }
108
109   offset += 13;
110
111 }