A correct programming practice is to save errno and restore its value
[obnox/wireshark/wip.git] / packet-eigrp.c
1 /* packet-eigrp.c
2  * Routines for EIGRP dissection
3  * Copyright 2000, Paul Ionescu <paul@acorp.ro>
4  *
5  * $Id: packet-eigrp.c,v 1.25 2002/08/28 21:00:13 jmayer Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/resolv.h>
33
34 #include <epan/atalk-utils.h>
35 #include "ipproto.h"
36 #include "packet-ipx.h"
37
38 #define EIGRP_UPDATE    0x01
39 #define EIGRP_REQUEST   0x02
40 #define EIGRP_QUERY     0x03
41 #define EIGRP_REPLY     0x04
42 #define EIGRP_HELLO     0x05
43 #define EIGRP_SAP       0x06
44 #define EIGRP_HI        0x20  /* This value is for my own need to make a difference between Hello and Ack */
45 #define EIGRP_ACK       0x40  /* This value is for my own need to make a difference between Hello and Ack */
46
47 #define TLV_PAR         0x0001
48 #define TLV_AUTH        0x0002
49 #define TLV_SEQ         0x0003
50 #define TLV_SV          0x0004
51 #define TLV_NMS         0x0005
52 #define TLV_IP_INT      0x0102
53 #define TLV_IP_EXT      0x0103
54 #define TLV_AT_INT      0x0202
55 #define TLV_AT_EXT      0x0203
56 #define TLV_AT_CBL      0x0204
57 #define TLV_IPX_INT     0x0302
58 #define TLV_IPX_EXT     0x0303
59
60 #define EIGRP_HEADER_LENGTH     20
61
62 static gint proto_eigrp = -1;
63
64 static gint hf_eigrp_opcode = -1;
65 static gint hf_eigrp_as = -1;
66 static gint hf_eigrp_tlv = -1;
67
68 static gint ett_eigrp = -1;
69 static gint ett_tlv = -1;
70
71 static dissector_handle_t ipxsap_handle;
72
73
74 static const value_string eigrp_opcode_vals[] = {
75         { EIGRP_HELLO,          "Hello/Ack" },
76         { EIGRP_UPDATE,         "Update" },
77         { EIGRP_REPLY,          "Reply" },
78         { EIGRP_QUERY,          "Query" },
79         { EIGRP_REQUEST,        "Request" },
80         { EIGRP_SAP,            "IPX/SAP Update" },
81         { EIGRP_HI,             "Hello" },
82         { EIGRP_ACK,            "Acknowledge" },
83         { 0,                            NULL }
84 };
85
86 static const value_string eigrp_tlv_vals[] = {
87         { TLV_PAR,     "EIGRP Parameters"},
88         { TLV_AUTH,    "Authentication data"},
89         { TLV_SEQ ,    "Sequence"},
90         { TLV_SV,      "Software Version"},
91         { TLV_NMS   ,  "Next multicast sequence"},
92         { TLV_IP_INT,  "IP internal route"},
93         { TLV_IP_EXT,  "IP external route"},
94         { TLV_AT_INT,  "AppleTalk internal route"},
95         { TLV_AT_EXT,  "AppleTalk external route"},
96         { TLV_AT_CBL,  "AppleTalk cable configuration"},
97         { TLV_IPX_INT, "IPX internal route"},
98         { TLV_IPX_EXT, "IPX external route"},
99         { 0,            NULL}
100 };
101
102 static const value_string eigrp_pid_vals[] = {
103         { 1,    "IGRP"},
104         { 2,    "EIGRP"},
105         { 3,    "Static Route"},
106         { 4,    "RIP"},
107         { 5,    "Hello"},
108         { 6,    "OSPF"},
109         { 7,    "IS-IS"},
110         { 8,    "EGP"},
111         { 9,    "BGP"},
112         { 10,   "IDRP"},
113         { 11,   "Connected link"},
114         { 0,    NULL}
115 };
116
117
118 static void dissect_eigrp_par (tvbuff_t *tvb, proto_tree *tree);
119 static void dissect_eigrp_seq (tvbuff_t *tvb, proto_tree *tree);
120 static void dissect_eigrp_sv  (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
121 static void dissect_eigrp_nms (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
122
123 static void dissect_eigrp_ip_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
124 static void dissect_eigrp_ip_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
125
126 static void dissect_eigrp_ipx_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
127 static void dissect_eigrp_ipx_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
128
129 static void dissect_eigrp_at_cbl (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
130 static void dissect_eigrp_at_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
131 static void dissect_eigrp_at_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
132
133 static void
134 dissect_eigrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
135
136   proto_tree *eigrp_tree,*tlv_tree;
137   proto_item *ti;
138
139   guint opcode,opcode_tmp;
140   guint16 tlv,size, offset = EIGRP_HEADER_LENGTH;
141   guint32 ack;
142
143   if (check_col(pinfo->cinfo, COL_PROTOCOL))
144     col_set_str(pinfo->cinfo, COL_PROTOCOL, "EIGRP");
145   if (check_col(pinfo->cinfo, COL_INFO))
146     col_clear(pinfo->cinfo, COL_INFO);
147
148   opcode_tmp=opcode=tvb_get_guint8(tvb,1);
149   ack = tvb_get_ntohl(tvb,12);
150   if (opcode==EIGRP_HELLO) { if (ack == 0) opcode_tmp=EIGRP_HI; else opcode_tmp=EIGRP_ACK; }
151
152   if (check_col(pinfo->cinfo, COL_INFO))
153     col_add_str(pinfo->cinfo, COL_INFO,
154         val_to_str(opcode_tmp , eigrp_opcode_vals, "Unknown (0x%04x)"));
155
156
157
158
159   if (tree) {
160
161      ti = proto_tree_add_protocol_format(tree, proto_eigrp, tvb, 0, -1,
162               "Cisco EIGRP");
163
164      eigrp_tree = proto_item_add_subtree(ti, ett_eigrp);
165
166      proto_tree_add_text (eigrp_tree, tvb, 0,1,"Version    = %u",tvb_get_guint8(tvb,0)) ;
167      proto_tree_add_uint_format (eigrp_tree, hf_eigrp_opcode, tvb, 1,1,opcode,"Opcode = %u (%s)",opcode,val_to_str(opcode_tmp,eigrp_opcode_vals, "Unknown")) ;
168      proto_tree_add_text (eigrp_tree, tvb, 2,2,"Checksum   = 0x%04x",tvb_get_ntohs(tvb,2)) ;
169      proto_tree_add_text (eigrp_tree, tvb, 4,4,"Flags      = 0x%08x",tvb_get_ntohl(tvb,4)) ;
170      proto_tree_add_text (eigrp_tree, tvb, 8,4,"Sequence   = %u",tvb_get_ntohl(tvb,8)) ;
171      proto_tree_add_text (eigrp_tree, tvb, 12,4,"Acknowledge  = %u",tvb_get_ntohl(tvb,12)) ;
172      proto_tree_add_uint (eigrp_tree, hf_eigrp_as, tvb, 16,4,tvb_get_ntohl(tvb,16)) ;
173
174      if (opcode==EIGRP_SAP)
175         {
176         call_dissector(ipxsap_handle, tvb_new_subset(tvb, EIGRP_HEADER_LENGTH, -1, -1), pinfo, eigrp_tree);
177         return;
178         }
179
180      while ( tvb_reported_length_remaining(tvb,offset)>0 ) {
181
182              tlv = tvb_get_ntohs(tvb,offset);
183              size =  tvb_get_ntohs(tvb,offset+2);
184              if ( size == 0 )
185                 {
186                 proto_tree_add_text(eigrp_tree,tvb,offset,-1,"Unknown data (maybe authentication)");
187                 return;
188                 }
189
190              ti = proto_tree_add_text (eigrp_tree, tvb, offset,size,
191                  "%s",val_to_str(tlv, eigrp_tlv_vals, "Unknown (0x%04x)"));
192
193              tlv_tree = proto_item_add_subtree (ti, ett_tlv);
194              proto_tree_add_uint_format (tlv_tree,hf_eigrp_tlv, tvb,offset,2,tlv,"Type = 0x%04x (%s)",tlv,val_to_str(tlv,eigrp_tlv_vals, "Unknown")) ;
195              proto_tree_add_text (tlv_tree,tvb,offset+2,2,"Size = %u bytes",size) ;
196
197
198              switch (tlv){
199                 case TLV_PAR:
200                         dissect_eigrp_par(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree);
201                         break;
202                 case TLV_SEQ:
203                         dissect_eigrp_seq(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree);
204                         break;
205                 case TLV_SV:
206                         dissect_eigrp_sv(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
207                         break;
208                 case TLV_NMS:
209                         dissect_eigrp_nms(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
210                         break;
211
212                 case TLV_IP_INT:
213                         dissect_eigrp_ip_int(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
214                         break;
215                 case TLV_IP_EXT:
216                         dissect_eigrp_ip_ext(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
217                         break;
218
219                 case TLV_IPX_INT:
220                         dissect_eigrp_ipx_int(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
221                         break;
222                 case TLV_IPX_EXT:
223                         dissect_eigrp_ipx_ext(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
224                         break;
225
226                 case TLV_AT_CBL:
227                         dissect_eigrp_at_cbl(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
228                         break;
229                 case TLV_AT_INT:
230                         dissect_eigrp_at_int(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
231                         break;
232                 case TLV_AT_EXT:
233                         dissect_eigrp_at_ext(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
234                         break;
235                 case TLV_AUTH:
236                         proto_tree_add_text(tlv_tree,tvb,offset+4,size-4,"Authentication data");
237                         break;
238              }
239
240              offset+=size;
241      }
242
243    }
244 }
245
246
247
248 static void dissect_eigrp_par (tvbuff_t *tvb, proto_tree *tree) {
249         proto_tree_add_text (tree,tvb,0,1,"K1 = %u",tvb_get_guint8(tvb,0));
250         proto_tree_add_text (tree,tvb,1,1,"K2 = %u",tvb_get_guint8(tvb,1));
251         proto_tree_add_text (tree,tvb,2,1,"K3 = %u",tvb_get_guint8(tvb,2));
252         proto_tree_add_text (tree,tvb,3,1,"K4 = %u",tvb_get_guint8(tvb,3));
253         proto_tree_add_text (tree,tvb,4,1,"K5 = %u",tvb_get_guint8(tvb,4));
254         proto_tree_add_text (tree,tvb,5,1,"Reserved");
255         proto_tree_add_text (tree,tvb,6,2,"Hold Time = %u",tvb_get_ntohs(tvb,6));
256 }
257
258 static void dissect_eigrp_seq (tvbuff_t *tvb, proto_tree *tree)
259 {       guint8 addr_len;
260         addr_len=tvb_get_guint8(tvb,0);
261         proto_tree_add_text (tree,tvb,0,1,"Address length = %u",addr_len);
262         switch (addr_len){
263                 case 4:
264                         proto_tree_add_text (tree,tvb,1,addr_len,"IP Address = %u.%u.%u.%u",tvb_get_guint8(tvb,1),tvb_get_guint8(tvb,2),tvb_get_guint8(tvb,3),tvb_get_guint8(tvb,4));
265                         break;
266                 case 10:
267                         proto_tree_add_text (tree,tvb,1,addr_len,"IPX Address = %08x.%04x.%04x.%04x",tvb_get_ntohl(tvb,1),tvb_get_ntohs(tvb,5),tvb_get_ntohs(tvb,7),tvb_get_ntohs(tvb,9));
268                         break;
269                 default:
270                         /* nothing */
271                         ;
272                 }
273 }
274
275 static void dissect_eigrp_sv (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
276 {
277         guint8 ios_rel_major, ios_rel_minor;
278         guint8 eigrp_rel_major, eigrp_rel_minor;
279
280         ios_rel_major = tvb_get_guint8(tvb,0);
281         ios_rel_minor = tvb_get_guint8(tvb,1);
282         proto_tree_add_text (tree,tvb,0,2," IOS  release version = %u.%u",
283                              ios_rel_major, ios_rel_minor);
284         proto_item_append_text (ti,": IOS=%u.%u", ios_rel_major, ios_rel_minor);
285
286         eigrp_rel_major = tvb_get_guint8(tvb,2);
287         eigrp_rel_minor = tvb_get_guint8(tvb,3);
288         proto_tree_add_text (tree,tvb,2,2,"EIGRP release version = %u.%u",
289                              eigrp_rel_major, eigrp_rel_minor);
290         proto_item_append_text (ti,", EIGRP=%u.%u",
291                                 eigrp_rel_major, eigrp_rel_minor);
292 }
293
294 static void dissect_eigrp_nms (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
295 {
296         proto_tree_add_text (tree,tvb,0,4,"Next Multicast Sequence = %u",tvb_get_ntohl(tvb,0));
297         proto_item_append_text (ti,": %u",tvb_get_ntohl(tvb,0));
298 }
299
300
301
302 static void dissect_eigrp_ip_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
303 {
304         guint8 ip_addr[4],length,addr_len;
305         tvb_memcpy(tvb,ip_addr,0,4);
306         proto_tree_add_text (tree,tvb,0,4, "Next Hop    = %s",ip_to_str(ip_addr));
307         proto_tree_add_text (tree,tvb,4,4, "Delay       = %u",tvb_get_ntohl(tvb,4));
308         proto_tree_add_text (tree,tvb,8,4, "Bandwidth   = %u",tvb_get_ntohl(tvb,8));
309         proto_tree_add_text (tree,tvb,12,3,"MTU         = %u",tvb_get_ntoh24(tvb,12));
310         proto_tree_add_text (tree,tvb,15,1,"Hop Count   = %u",tvb_get_guint8(tvb,15));
311         proto_tree_add_text (tree,tvb,16,1,"Reliability = %u",tvb_get_guint8(tvb,16));
312         proto_tree_add_text (tree,tvb,17,1,"Load        = %u",tvb_get_guint8(tvb,17));
313         proto_tree_add_text (tree,tvb,18,2,"Reserved ");
314         length=tvb_get_guint8(tvb,20);
315         proto_tree_add_text (tree,tvb,20,1,"Prefix Length = %u",length);
316         if (length % 8 == 0) addr_len=length/8 ; else addr_len=length/8+1;
317         ip_addr[0]=ip_addr[1]=ip_addr[2]=ip_addr[3]=0;
318         tvb_memcpy(tvb,ip_addr,21,addr_len);
319         proto_tree_add_text (tree,tvb,21,addr_len,"Destination = %s",ip_to_str(ip_addr));
320         proto_item_append_text (ti,"  =   %s/%u%s",ip_to_str(ip_addr),length,((tvb_get_ntohl(tvb,4)==0xffffffff)?" - Destination unreachable":""));
321 }
322
323 static void dissect_eigrp_ip_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
324 {
325         guint8 ip_addr[4],length,addr_len;
326         tvb_memcpy(tvb,ip_addr,0,4);
327         proto_tree_add_text (tree,tvb,0,4,"Next Hop = %s",ip_to_str(ip_addr));
328         tvb_memcpy(tvb,ip_addr,4,4);
329         proto_tree_add_text (tree,tvb,4,4,"Originating router = %s",ip_to_str(ip_addr));
330         proto_tree_add_text (tree,tvb,8,4,"Originating A.S. = %u",tvb_get_ntohl(tvb,8));
331         proto_tree_add_text (tree,tvb,12,4,"Arbitrary tag = %u",tvb_get_ntohl(tvb,12));
332         proto_tree_add_text (tree,tvb,16,4,"External protocol metric = %u",tvb_get_ntohl(tvb,16));
333         proto_tree_add_text (tree,tvb,20,2,"Reserved");
334         proto_tree_add_text (tree,tvb,22,1,"External protocol ID = %u (%s)",tvb_get_guint8(tvb,22),val_to_str(tvb_get_guint8(tvb,22),eigrp_pid_vals, "Unknown"));
335         proto_tree_add_text (tree,tvb,23,1,"Flags = 0x%0x",tvb_get_guint8(tvb,23));
336
337         proto_tree_add_text (tree,tvb,24,4,"Delay     = %u",tvb_get_ntohl(tvb,24));
338         proto_tree_add_text (tree,tvb,28,4,"Bandwidth = %u",tvb_get_ntohl(tvb,28));
339         proto_tree_add_text (tree,tvb,32,3,"MTU    = %u",tvb_get_ntoh24(tvb,32));
340         proto_tree_add_text (tree,tvb,35,1,"Hop Count = %u",tvb_get_guint8(tvb,35));
341         proto_tree_add_text (tree,tvb,36,1,"Reliability = %u",tvb_get_guint8(tvb,36));
342         proto_tree_add_text (tree,tvb,37,1,"Load = %u",tvb_get_guint8(tvb,37));
343         proto_tree_add_text (tree,tvb,38,2,"Reserved ");
344         length=tvb_get_guint8(tvb,40);
345         proto_tree_add_text (tree,tvb,40,1,"Prefix Length = %u",length);
346         if (length % 8 == 0) addr_len=length/8 ; else addr_len=length/8+1;
347         ip_addr[0]=ip_addr[1]=ip_addr[2]=ip_addr[3]=0;
348         tvb_memcpy(tvb,ip_addr,41,addr_len);
349         proto_tree_add_text (tree,tvb,41,addr_len,"Destination = %s",ip_to_str(ip_addr));
350         proto_item_append_text (ti,"  =   %s/%u%s",ip_to_str(ip_addr),length,((tvb_get_ntohl(tvb,24)==0xffffffff)?" - Destination unreachable":""));
351 }
352
353
354
355 static void dissect_eigrp_ipx_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
356 {
357         proto_tree_add_text (tree,tvb,0,4,"Next Hop Address = %08x",tvb_get_ntohl(tvb,4));
358         proto_tree_add_text (tree,tvb,4,6,"Next Hop ID      = %04x:%04x:%04x",tvb_get_ntohs(tvb,4),tvb_get_ntohs(tvb,6),tvb_get_ntohs(tvb,8));
359         proto_tree_add_text (tree,tvb,10,4,"Delay     = %u",tvb_get_ntohl(tvb,10));
360         proto_tree_add_text (tree,tvb,14,4,"Bandwidth = %u",tvb_get_ntohl(tvb,14));
361         proto_tree_add_text (tree,tvb,18,3,"MTU    = %u",tvb_get_ntoh24(tvb,18));
362         proto_tree_add_text (tree,tvb,21,1,"Hop Count = %u",tvb_get_guint8(tvb,21));
363         proto_tree_add_text (tree,tvb,22,1,"Reliability = %u",tvb_get_guint8(tvb,22));
364         proto_tree_add_text (tree,tvb,23,1,"Load = %u",tvb_get_guint8(tvb,23));
365         proto_tree_add_text (tree,tvb,24,2,"Reserved ");
366         proto_tree_add_text (tree,tvb,26,4,"Destination Address =  %08x",tvb_get_ntohl(tvb,26));
367         proto_item_append_text (ti,"  =   %08x%s",tvb_get_ntohl(tvb,26),((tvb_get_ntohl(tvb,10)==0xffffffff)?" - Destination unreachable":""));
368 }
369
370 static void dissect_eigrp_ipx_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
371 {
372         proto_tree_add_text (tree,tvb,0,4,"Next Hop Address = %08x",tvb_get_ntohl(tvb,4));
373         proto_tree_add_text (tree,tvb,4,6,"Next Hop ID      = %04x:%04x:%04x",tvb_get_ntohs(tvb,4),tvb_get_ntohs(tvb,6),tvb_get_ntohs(tvb,8));
374
375         proto_tree_add_text (tree,tvb,10,6,"Originating router ID = %04x:%04x:%04x",tvb_get_ntohs(tvb,10),tvb_get_ntohs(tvb,12),tvb_get_ntohs(tvb,14));
376         proto_tree_add_text (tree,tvb,16,4,"Originating A.S. = %u",tvb_get_ntohl(tvb,16));
377         proto_tree_add_text (tree,tvb,20,4,"Arbitrary tag = %u",tvb_get_ntohl(tvb,20));
378         proto_tree_add_text (tree,tvb,24,1,"External protocol  = %u",tvb_get_guint8(tvb,24));
379         proto_tree_add_text (tree,tvb,25,1,"Reserved");
380         proto_tree_add_text (tree,tvb,26,2,"External metric = %u ",tvb_get_ntohs(tvb,26));
381         proto_tree_add_text (tree,tvb,28,2,"External delay  = %u ",tvb_get_ntohs(tvb,28));
382
383         proto_tree_add_text (tree,tvb,30,4,"Delay     = %u",tvb_get_ntohl(tvb,30));
384         proto_tree_add_text (tree,tvb,34,4,"Bandwidth = %u",tvb_get_ntohl(tvb,34));
385         proto_tree_add_text (tree,tvb,38,3,"MTU    = %u",tvb_get_ntoh24(tvb,38));
386         proto_tree_add_text (tree,tvb,41,1,"Hop Count = %u",tvb_get_guint8(tvb,41));
387         proto_tree_add_text (tree,tvb,42,1,"Reliability = %u",tvb_get_guint8(tvb,42));
388         proto_tree_add_text (tree,tvb,43,1,"Load = %u",tvb_get_guint8(tvb,43));
389         proto_tree_add_text (tree,tvb,44,2,"Reserved ");
390         proto_tree_add_text (tree,tvb,46,4,"Destination Address =  %08x",tvb_get_ntohl(tvb,46));
391         proto_item_append_text (ti,"  =   %08x%s",tvb_get_ntohl(tvb,46),((tvb_get_ntohl(tvb,30)==0xffffffff)?" - Destination unreachable":""));
392
393 }
394
395
396
397 static void dissect_eigrp_at_cbl (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
398 {
399         proto_tree_add_text (tree,tvb,0,4,"AppleTalk Cable Range = %u-%u",tvb_get_ntohs(tvb,0),tvb_get_ntohs(tvb,2));
400         proto_tree_add_text (tree,tvb,4,4,"AppleTalk Router ID   = %u",tvb_get_ntohl(tvb,4));
401         proto_item_append_text (ti,": Cable range= %u-%u, Router ID= %u",tvb_get_ntohs(tvb,0),tvb_get_ntohs(tvb,2),tvb_get_ntohl(tvb,4));
402
403 }
404
405 static void dissect_eigrp_at_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
406 {
407         proto_tree_add_text (tree,tvb,0,4,"Next Hop Address = %u.%u",tvb_get_ntohs(tvb,0),tvb_get_ntohs(tvb,2));
408
409         proto_tree_add_text (tree,tvb,4,4,"Delay     = %u",tvb_get_ntohl(tvb,4));
410         proto_tree_add_text (tree,tvb,8,4,"Bandwidth = %u",tvb_get_ntohl(tvb,8));
411         proto_tree_add_text (tree,tvb,12,3,"MTU    = %u",tvb_get_ntoh24(tvb,12));
412         proto_tree_add_text (tree,tvb,15,1,"Hop Count = %u",tvb_get_guint8(tvb,15));
413         proto_tree_add_text (tree,tvb,16,1,"Reliability = %u",tvb_get_guint8(tvb,16));
414         proto_tree_add_text (tree,tvb,17,1,"Load = %u",tvb_get_guint8(tvb,17));
415         proto_tree_add_text (tree,tvb,18,2,"Reserved ");
416         proto_tree_add_text (tree,tvb,20,4,"Cable range = %u-%u",tvb_get_ntohs(tvb,20),tvb_get_ntohs(tvb,22));
417
418         proto_item_append_text (ti,": %u-%u",tvb_get_ntohs(tvb,20),tvb_get_ntohs(tvb,22));
419
420 }
421
422 static void dissect_eigrp_at_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
423 {
424         proto_tree_add_text (tree,tvb,0,4,"Next Hop Address = %u.%u",tvb_get_ntohs(tvb,0),tvb_get_ntohs(tvb,2));
425         proto_tree_add_text (tree,tvb,4,4,"Originating router ID = %u",tvb_get_ntohl(tvb,4));
426         proto_tree_add_text (tree,tvb,8,4,"Originating A.S. = %u",tvb_get_ntohl(tvb,8));
427         proto_tree_add_text (tree,tvb,12,4,"Arbitrary tag = %u",tvb_get_ntohl(tvb,12));
428         proto_tree_add_text (tree,tvb,16,1,"External protocol ID = %u ",tvb_get_guint8(tvb,16));
429         proto_tree_add_text (tree,tvb,17,1,"Flags = 0x%0x",tvb_get_guint8(tvb,17));
430         proto_tree_add_text (tree,tvb,18,2,"External protocol metric = %u",tvb_get_ntohs(tvb,18));
431
432         proto_tree_add_text (tree,tvb,20,4,"Delay     = %u",tvb_get_ntohl(tvb,20));
433         proto_tree_add_text (tree,tvb,24,4,"Bandwidth = %u",tvb_get_ntohl(tvb,24));
434         proto_tree_add_text (tree,tvb,28,3,"MTU    = %u",tvb_get_ntoh24(tvb,28));
435         proto_tree_add_text (tree,tvb,31,1,"Hop Count = %u",tvb_get_guint8(tvb,31));
436         proto_tree_add_text (tree,tvb,32,1,"Reliability = %u",tvb_get_guint8(tvb,32));
437         proto_tree_add_text (tree,tvb,33,1,"Load = %u",tvb_get_guint8(tvb,33));
438         proto_tree_add_text (tree,tvb,34,2,"Reserved ");
439         proto_tree_add_text (tree,tvb,36,4,"Cable range = %u-%u",tvb_get_ntohs(tvb,36),tvb_get_ntohs(tvb,38));
440
441         proto_item_append_text (ti,": %u-%u",tvb_get_ntohs(tvb,36),tvb_get_ntohs(tvb,38));
442 }
443
444
445
446
447 void
448 proto_register_eigrp(void)
449 {
450   static hf_register_info hf[] = {
451    { &hf_eigrp_opcode,
452     { "Opcode", "eigrp.opcode",
453      FT_UINT8, BASE_DEC, NULL, 0x0 ,
454      "Opcode number", HFILL }
455      },
456    { &hf_eigrp_as,
457     { "Autonomous System  ", "eigrp.as",
458       FT_UINT16, BASE_DEC, NULL, 0x0 ,
459      "Autonomous System number", HFILL }
460     },
461    { &hf_eigrp_tlv,
462     { "Entry  ",           "eigrp.tlv",
463       FT_UINT16, BASE_DEC, NULL, 0x0 ,
464      "Type/Length/Value", HFILL }
465     },
466    };
467
468    static gint *ett[] = {
469      &ett_eigrp,
470      &ett_tlv,
471    };
472    proto_eigrp = proto_register_protocol("Enhanced Interior Gateway Routing Protocol",
473                                          "EIGRP", "eigrp");
474    proto_register_field_array(proto_eigrp, hf, array_length(hf));
475    proto_register_subtree_array(ett, array_length(ett));
476 }
477
478 void
479 proto_reg_handoff_eigrp(void)
480 {
481     dissector_handle_t eigrp_handle;
482
483     ipxsap_handle = find_dissector("ipxsap");
484     eigrp_handle = create_dissector_handle(dissect_eigrp, proto_eigrp);
485     dissector_add("ip.proto", IP_PROTO_EIGRP, eigrp_handle);
486     dissector_add("ddp.type", DDP_EIGRP, eigrp_handle);
487     dissector_add("ipx.socket", IPX_SOCKET_EIGRP, eigrp_handle);
488 }