Give the Appletalk DDP dissector a dissector hash table, and have the
[obnox/wireshark/wip.git] / packet-eigrp.c
1 /* packet-eigrp.c
2  *
3  * $Id: packet-eigrp.c,v 1.1 2000/05/28 22:59:18 guy Exp $
4  *
5  * Ethereal - Network traffic analyzer
6  * By Gerald Combs <gerald@zing.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * 
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  * 
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
31 #endif
32
33 #include <glib.h>
34 #include "packet.h"
35 #include "resolv.h"
36
37 #include "packet-eigrp.h"
38 #include "packet-atalk.h"
39 #include "packet-ip.h"
40
41 /* EIGRP Structs and Definitions. */    
42
43 /* EIGRP Opcodes */
44
45 #define EIGRP_UPDATE    0x01
46 #define EIGRP_REQUEST   0x02
47 #define EIGRP_QUERY     0x03
48 #define EIGRP_REPLY     0x04
49 #define EIGRP_HELLO     0x05
50
51 typedef struct _e_eigrp 
52    {
53    guint8 eigrp_version;
54    guint8 eigrp_opcode;
55    guint16 eigrp_checksum;
56    guint16 eigrp_subnets;
57    guint16 eigrp_networks;
58    guint32 eigrp_sequence;
59    guint32 eigrp_asnumber;
60    guint8 eigrp_type1;
61    guint8 eigrp_subtype1;
62    guint16 eigrp_length1;
63    guint16 eigrp_holdtime;
64    guint8 eigrp_type2;
65    guint8 eigrp_subtype2;
66    guint16 eigrp_length2;
67    guint8 eigrp_level;
68    guint16 eigrp_dummy;
69    } e_eigrp;
70
71 static int proto_eigrp = -1;
72
73 static gint ett_eigrp = -1;
74
75 static const value_string eigrp_opcode_vals[] = {
76         { EIGRP_HELLO,          "Hello/Ack" },
77         { EIGRP_UPDATE,         "Update" },
78         { EIGRP_REPLY,          "Reply" },
79         { EIGRP_QUERY,          "Query" },
80         { EIGRP_REQUEST,        "Request" },
81         { 0,                            NULL }    
82 };
83
84 void
85 dissect_eigrp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
86   e_eigrp     ih;
87   proto_tree *eigrp_tree;
88   proto_item *ti;
89   guint16    cksum;
90
91   /* Avoids alignment problems on many architectures. */
92   memcpy(&ih, &pd[offset], sizeof(e_eigrp));
93   /* To do: check for runts, errs, etc. */
94   cksum = ntohs(ih.eigrp_checksum);
95   
96   if (check_col(fd, COL_PROTOCOL))
97     col_add_str(fd, COL_PROTOCOL, "EIGRP");
98   if (check_col(fd, COL_INFO))
99     col_add_str(fd, COL_INFO,
100         val_to_str( ih.eigrp_opcode, eigrp_opcode_vals, "Unknown (0x%04x)"));
101   if (tree) {
102
103      ti = proto_tree_add_item(tree, proto_eigrp, NullTVB, offset, END_OF_FRAME, NULL);
104      eigrp_tree = proto_item_add_subtree(ti, ett_eigrp);
105   
106      proto_tree_add_text(eigrp_tree, NullTVB, offset, 1, "Version: %u", ih.eigrp_version); 
107      proto_tree_add_text(eigrp_tree, NullTVB, offset + 1, 1, "Opcode: %u (%s)", ih.eigrp_opcode,
108          val_to_str( ih.eigrp_opcode, eigrp_opcode_vals, "Unknown") );
109      proto_tree_add_text(eigrp_tree, NullTVB, offset + 2, 2, "Checksum: 0x%x", cksum); 
110      proto_tree_add_text(eigrp_tree, NullTVB, offset + 4, 2, "Subnets in local net: %u", ih.eigrp_subnets); 
111      proto_tree_add_text(eigrp_tree, NullTVB, offset + 6, 2, "Networks in Autonomous System: %d", ih.eigrp_networks); 
112      proto_tree_add_text(eigrp_tree, NullTVB, offset + 8, 4, "Sequence Number: 0x%x", ih.eigrp_sequence); 
113      proto_tree_add_text(eigrp_tree, NullTVB, offset + 12, 4, "Autonomous System number: %u", ih.eigrp_asnumber); 
114    }
115 }
116
117 void
118 proto_register_eigrp(void)
119    {
120       static gint *ett[] = {
121         &ett_eigrp,
122       };
123    proto_eigrp = proto_register_protocol("Enhanced Interior Gateway Routing Protocol", "eigrp");
124    proto_register_subtree_array(ett, array_length(ett));
125    }
126
127 void
128 proto_reg_handoff_eigrp(void)
129 {
130     dissector_add("ip.proto", IP_PROTO_EIGRP, dissect_eigrp);
131     dissector_add("ddp.type", DDP_EIGRP, dissect_eigrp);
132 }