Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-dvmrp.c
1 /* packet-dvmrp.c   2001 Ronnie Sahlberg <See AUTHORS for email>
2  * Routines for IGMP/DVMRP packet disassembly
3  *
4  * $Id: packet-dvmrp.c,v 1.12 2002/08/02 23:35:49 jmayer Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
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
26
27                         DVMRP   DVMRP
28         code            v1      v3
29
30         0x01            *       *
31         0x02            *       *
32         0x03            x
33         0x04            x
34         0x07                    x
35         0x08                    x
36         0x09                    x
37
38
39         * V3 has len>=8 and byte[6]==0xff and byte[7]==0x03
40
41
42         DVMRP is defined in the following RFCs
43         RFC1075 Version 1
44         draft-ietf-idmr-dvmrp-v3-10.txt Version 3
45
46         V1 and V3 can be distinguished by looking at bytes 6 and 7 in the 
47         IGMP/DVMRP header.
48         If header[6]==0xff and header[7]==0x03 we have version 3.
49
50
51         RFC1075 has typos in 3.12.2 and 3.12.4, see if you can spot them.
52 */
53
54 #ifdef HAVE_CONFIG_H
55 # include "config.h"
56 #endif
57
58 #include <stdio.h>
59 #include <string.h>
60 #include <glib.h>
61
62 #include <epan/packet.h>
63 #include "ipproto.h"
64 #include "packet-igmp.h"
65 #include "packet-dvmrp.h"
66
67 static int proto_dvmrp = -1;
68 static int hf_version = -1;
69 static int hf_type = -1;
70 static int hf_code_v1 = -1;
71 static int hf_checksum = -1;
72 static int hf_checksum_bad = -1;
73 static int hf_commands = -1;
74 static int hf_command = -1;
75 static int hf_count = -1;
76 static int hf_afi = -1;
77 static int hf_netmask = -1;
78 static int hf_metric = -1;
79 static int hf_dest_unr = -1;
80 static int hf_split_horiz = -1;
81 static int hf_infinity = -1;
82 static int hf_daddr = -1;
83 static int hf_maddr = -1;
84 static int hf_hold = -1;
85 static int hf_code_v3 = -1;
86 static int hf_capabilities = -1;
87 static int hf_cap_leaf = -1;
88 static int hf_cap_prune = -1;
89 static int hf_cap_genid = -1;
90 static int hf_cap_mtrace = -1;
91 static int hf_cap_snmp = -1;
92 static int hf_cap_netmask = -1;
93 static int hf_min_ver = -1;
94 static int hf_maj_ver = -1;
95 static int hf_genid = -1;
96 static int hf_route = -1;
97 static int hf_saddr = -1;
98 static int hf_life = -1;
99 static int hf_neighbor = -1;
100
101 static int ett_dvmrp = -1;
102 static int ett_commands = -1;
103 static int ett_capabilities = -1;
104 static int ett_route = -1;
105
106
107 #define DVMRP_TYPE                              0x13
108 static const value_string dvmrp_type[] = {
109         {DVMRP_TYPE,    "DVMRP" },
110         {0,             NULL}
111 };
112
113 #define DVMRP_V1_RESPONSE                       1
114 #define DVMRP_V1_REQUEST                        2
115 #define DVMRP_V1_NON_MEMBERSHIP_REPORT          3
116 #define DVMRP_V1_NON_MEMBERSHIP_CANCELLATION    4
117 static const value_string code_v1[] = {
118         {DVMRP_V1_RESPONSE,                     "Response"                      },
119         {DVMRP_V1_REQUEST,                      "Request"                       },
120         {DVMRP_V1_NON_MEMBERSHIP_REPORT,        "Non-membership report"         },
121         {DVMRP_V1_NON_MEMBERSHIP_CANCELLATION,  "Non-membership cancellation"   },      
122         {0,                                     NULL}
123 };
124
125 #define DVMRP_V3_PROBE                          0x1
126 #define DVMRP_V3_REPORT                         0x2
127 #define DVMRP_V3_ASK_NEIGHBORS                  0x3
128 #define DVMRP_V3_NEIGHBORS                      0x4
129 #define DVMRP_V3_ASK_NEIGHBORS_2                0x5
130 #define DVMRP_V3_NEIGHBORS_2                    0x6
131 #define DVMRP_V3_PRUNE                          0x7
132 #define DVMRP_V3_GRAFT                          0x8
133 #define DVMRP_V3_GRAFT_ACK                      0x9
134 static const value_string code_v3[] = {
135         {DVMRP_V3_PROBE,                "Probe"},
136         {DVMRP_V3_REPORT,               "Report"},
137         {DVMRP_V3_ASK_NEIGHBORS,        "Ask Neighbors"},
138         {DVMRP_V3_NEIGHBORS,            "Neighbors"},
139         {DVMRP_V3_ASK_NEIGHBORS_2,      "Ask Neighbors 2"},
140         {DVMRP_V3_NEIGHBORS_2,          "Neighbors 2"},
141         {DVMRP_V3_PRUNE,                "Prune"},
142         {DVMRP_V3_GRAFT,                "Graft"},
143         {DVMRP_V3_GRAFT_ACK,            "Graft ACK"},
144         {0,                             NULL}
145 };
146
147 #define DVMRP_V3_CAP_LEAF       0x01
148 #define DVMRP_V3_CAP_PRUNE      0x02
149 #define DVMRP_V3_CAP_GENID      0x04
150 #define DVMRP_V3_CAP_MTRACE     0x08
151 #define DVMRP_V3_CAP_SNMP       0x10
152 #define DVMRP_V3_CAP_NETMASK    0x20
153         
154
155 #define V1_COMMAND_NULL         0
156 #define V1_COMMAND_AFI          2
157 #define V1_COMMAND_SUBNETMASK   3
158 #define V1_COMMAND_METRIC       4
159 #define V1_COMMAND_FLAGS0       5
160 #define V1_COMMAND_INFINITY     6
161 #define V1_COMMAND_DA           7
162 #define V1_COMMAND_RDA          8
163 #define V1_COMMAND_NMR          9
164 #define V1_COMMAND_NMR_CANCEL   10
165 static const value_string command[] = {
166         {V1_COMMAND_NULL,       "NULL"  },
167         {V1_COMMAND_AFI,        "Address Family Indicator"},
168         {V1_COMMAND_SUBNETMASK, "Subnetmask"},
169         {V1_COMMAND_METRIC,     "Metric"},
170         {V1_COMMAND_FLAGS0,     "Flags0"},
171         {V1_COMMAND_INFINITY,   "Infinity"},
172         {V1_COMMAND_DA,         "Destination Address"},
173         {V1_COMMAND_RDA,        "Requested Destination Address"},
174         {V1_COMMAND_NMR,        "Non-Membership Report"},
175         {V1_COMMAND_NMR_CANCEL, "Non-Membership Report Cancel"},
176         {0,                     NULL}
177 };
178
179 #define V1_AFI_IP               2
180 static const value_string afi[] = {
181         {V1_AFI_IP,     "IP v4 Family"},
182         {0,             NULL}
183 };
184
185 static const true_false_string tfs_dest_unreach = {
186         "Destination Unreachable",
187         "NOT Destination Unreachable"
188 };
189
190 static const true_false_string tfs_split_horiz = {
191         "Split Horizon concealed route",
192         "NOT Split Horizon concealed route"
193 };
194
195 static const true_false_string tfs_cap_leaf = {
196         "Leaf",
197         "NOT Leaf"
198 };
199 static const true_false_string tfs_cap_prune = {
200         "Prune capable",
201         "NOT Prune capable"
202 };
203 static const true_false_string tfs_cap_genid = {
204         "Genid capable",
205         "NOT Genid capable"
206 };
207 static const true_false_string tfs_cap_mtrace = {
208         "Multicast Traceroute capable",
209         "NOT Multicast Traceroute capable"
210 };
211 static const true_false_string tfs_cap_snmp = {
212         "SNMP capable",
213         "NOT SNMP capable"
214 };
215 static const true_false_string tfs_cap_netmask = {
216         "Netmask capable",
217         "NOT Netmask capable"
218 };
219
220 static int
221 dissect_v3_report(tvbuff_t *tvb, proto_tree *parent_tree, int offset)
222 {
223         guint8 m0,m1,m2,m3;
224         guint8 s0,s1,s2,s3;
225         guint8 metric;
226         guint32 ip;
227
228         while (tvb_reported_length_remaining(tvb, offset) > 0) {
229                 proto_tree *tree;
230                 proto_item *item;
231                 int old_offset = offset;
232
233                 item = proto_tree_add_item(parent_tree, hf_route, 
234                                 tvb, offset, -1, FALSE);
235                 tree = proto_item_add_subtree(item, ett_route);
236
237                 m0 = 0xff;
238                 /* read the mask */
239                 m1 = tvb_get_guint8(tvb, offset);
240                 m2 = tvb_get_guint8(tvb, offset+1);
241                 m3 = tvb_get_guint8(tvb, offset+2);
242
243                 ip = m3;
244                 ip = (ip<<8)|m2;
245                 ip = (ip<<8)|m1;
246                 ip = (ip<<8)|m0;
247                 proto_tree_add_ipv4(tree, hf_netmask, tvb, offset, 3, ip);
248
249                 offset += 3;
250
251                 /* read every srcnet, metric  pairs */
252                 do {
253                         int old_offset = offset;
254                         m0 = 0xff;
255
256                         s0 = 0;
257                         s1 = 0;
258                         s2 = 0;
259                         s3 = 0;
260
261                         s0 = tvb_get_guint8(tvb, offset);
262                         offset += 1;
263                         if (m1) {
264                                 s1 = tvb_get_guint8(tvb, offset);
265                                 offset += 1;
266                         }
267                         if (m2) {
268                                 s2 = tvb_get_guint8(tvb, offset);
269                                 offset += 1;
270                         }
271                         if (m3) {
272                                 s3 = tvb_get_guint8(tvb, offset);
273                                 offset += 1;
274                         }
275
276                         /* handle special case for default route V3/3.4.3 */
277                         if ((!m1)&&(!m2)&&(!m3)&&(!s0)) {
278                                 m0 = 0;
279                         }
280
281                         ip = s3;
282                         ip = (ip<<8)|s2;
283                         ip = (ip<<8)|s1;
284                         ip = (ip<<8)|s0;
285                         proto_tree_add_ipv4_format(tree, hf_saddr, tvb, 
286                                 old_offset, offset-old_offset, ip,
287                                 "%s %d.%d.%d.%d (netmask %d.%d.%d.%d)",
288                                 m0?"Source Network":"Default Route",
289                                 s0,s1,s2,s3,m0,m1,m2,m3);
290                         
291                         metric = tvb_get_guint8(tvb, offset);
292                         proto_tree_add_uint(tree, hf_metric, tvb,
293                                 offset, 1, metric&0x7f);
294                         offset += 1;
295
296
297                 } while (!(metric&0x80));
298
299                 proto_item_set_len(item, offset-old_offset);
300         }
301
302         return offset;
303 }
304
305 static int
306 dissect_dvmrp_v3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
307 {
308         guint8 code,count;
309
310         /* version */
311         proto_tree_add_uint(parent_tree, hf_version, tvb, 0, 0, 3);
312
313         /* type of command */
314         proto_tree_add_uint(parent_tree, hf_type, tvb, offset, 1, 0x13);
315         offset += 1;
316
317         /* code */
318         code = tvb_get_guint8(tvb, offset);
319         proto_tree_add_uint(parent_tree, hf_code_v3, tvb, offset, 1, code);
320         offset += 1;
321         if (check_col(pinfo->cinfo, COL_INFO)) {
322                 col_add_fstr(pinfo->cinfo, COL_INFO,
323                         "V%d %s",3 ,val_to_str(code, code_v3, 
324                                 "Unknown Type:0x%02x"));
325         }
326
327         /* checksum */
328         igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
329         offset += 2;
330
331         /* skip unused byte */
332         offset += 1;
333
334         /* PROBE and NEIGHBORS 2 packets have capabilities flags, unused
335            for other packets */
336         if (code==DVMRP_V3_PROBE || code==DVMRP_V3_NEIGHBORS_2) {
337                 proto_tree *tree;
338                 proto_item *item;
339
340                 item = proto_tree_add_item(parent_tree, hf_capabilities, 
341                                 tvb, offset, 1, FALSE);
342                 tree = proto_item_add_subtree(item, ett_capabilities);
343
344                 count = tvb_get_guint8(tvb, offset);
345                 proto_tree_add_boolean(tree, hf_cap_netmask, tvb, offset, 1, count);
346                 proto_tree_add_boolean(tree, hf_cap_snmp, tvb, offset, 1, count);
347                 proto_tree_add_boolean(tree, hf_cap_mtrace, tvb, offset, 1, count);
348                 proto_tree_add_boolean(tree, hf_cap_genid, tvb, offset, 1, count);
349                 proto_tree_add_boolean(tree, hf_cap_prune, tvb, offset, 1, count);
350                 proto_tree_add_boolean(tree, hf_cap_leaf, tvb, offset, 1, count);
351         }
352         offset += 1;
353
354         /* minor version */
355         proto_tree_add_item(parent_tree, hf_min_ver, tvb, offset, 1, FALSE);
356         offset += 1;
357
358         /* major version */
359         proto_tree_add_item(parent_tree, hf_maj_ver, tvb, offset, 1, FALSE);
360         offset += 1;
361
362         switch (code) {
363         case DVMRP_V3_PROBE:
364                 /* generation id */
365                 proto_tree_add_item(parent_tree, hf_genid, tvb, 
366                         offset, 4, FALSE);
367                 offset += 4;
368                 while (tvb_reported_length_remaining(tvb, offset) > 0) {
369                         proto_tree_add_item(parent_tree, hf_neighbor, 
370                                 tvb, offset, 4, FALSE);
371                         offset += 4;
372                 }
373                 break;
374         case DVMRP_V3_REPORT:
375                 offset = dissect_v3_report(tvb, parent_tree, offset);
376                 break;
377         case DVMRP_V3_PRUNE:
378                 /* source address */
379                 proto_tree_add_item(parent_tree, hf_saddr, 
380                         tvb, offset, 4, FALSE);
381                 offset += 4;
382                 /* group address */
383                 proto_tree_add_item(parent_tree, hf_maddr, 
384                         tvb, offset, 4, FALSE);
385                 offset += 4;
386                 /* prune lifetime */
387                 proto_tree_add_item(parent_tree, hf_life, 
388                         tvb, offset, 4, FALSE);
389                 offset += 4;
390                 /* source netmask */
391                 if (tvb_reported_length_remaining(tvb, offset)>=4) {
392                         proto_tree_add_item(parent_tree, hf_netmask,
393                                 tvb, offset, 4, FALSE);
394                         offset += 4;
395                 }
396                 break;
397         case DVMRP_V3_GRAFT:
398                 /* source address */
399                 proto_tree_add_item(parent_tree, hf_saddr, 
400                         tvb, offset, 4, FALSE);
401                 offset += 4;
402                 /* group address */
403                 proto_tree_add_item(parent_tree, hf_maddr, 
404                         tvb, offset, 4, FALSE);
405                 offset += 4;
406                 /* source netmask */
407                 if (tvb_reported_length_remaining(tvb, offset)>=4) {
408                         proto_tree_add_item(parent_tree, hf_netmask, 
409                                 tvb, offset, 4, FALSE);
410                         offset += 4;
411                 }
412                 break;
413         case DVMRP_V3_GRAFT_ACK:
414                 /* source address */
415                 proto_tree_add_item(parent_tree, hf_saddr, 
416                         tvb, offset, 4, FALSE);
417                 offset += 4;
418                 /* group address */
419                 proto_tree_add_item(parent_tree, hf_maddr, 
420                         tvb, offset, 4, FALSE);
421                 offset += 4;
422                 /* source netmask */
423                 if (tvb_reported_length_remaining(tvb, offset)>=4) {
424                         proto_tree_add_item(parent_tree, hf_netmask, 
425                                 tvb, offset, 4, FALSE);
426                         offset += 4;
427                 }
428                 break;
429         case DVMRP_V3_ASK_NEIGHBORS:
430         case DVMRP_V3_NEIGHBORS:
431                 /* XXX - obsolete, and the draft doesn't describe them */
432                 break;
433         case DVMRP_V3_ASK_NEIGHBORS_2:
434                 /* No data */
435                 break;
436         case DVMRP_V3_NEIGHBORS_2:
437                 /* XXX - fill this in */
438                 break;
439         }
440
441         return offset;
442 }
443         
444
445 static int
446 dissect_dvmrp_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
447 {
448         guint8 code;
449         guint8 af=2; /* default */
450
451         /* version */
452         proto_tree_add_uint(parent_tree, hf_version, tvb, 0, 0, 1);
453
454         /* type of command */
455         proto_tree_add_uint(parent_tree, hf_type, tvb, offset, 1, 0x13);
456         offset += 1;
457
458         /* code */
459         code = tvb_get_guint8(tvb, offset);
460         proto_tree_add_uint(parent_tree, hf_code_v1, tvb, offset, 1, code);
461         offset += 1;
462         if (check_col(pinfo->cinfo, COL_INFO)) {
463                 col_add_fstr(pinfo->cinfo, COL_INFO,
464                         "V%d %s",1 ,val_to_str(code, code_v1, 
465                                 "Unknown Type:0x%02x"));
466         }
467
468         /* checksum */
469         igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
470         offset += 2;
471
472         /* decode all the v1 commands */
473         while (tvb_reported_length_remaining(tvb, offset)) {
474                 proto_tree *tree;
475                 proto_item *item;
476                 guint8 cmd,count;
477                 int old_offset = offset;
478
479                 item = proto_tree_add_item(parent_tree, hf_commands, 
480                                 tvb, offset, -1, FALSE);
481                 tree = proto_item_add_subtree(item, ett_commands);
482
483                 cmd = tvb_get_guint8(tvb, offset);
484                 proto_tree_add_uint(tree, hf_command, tvb,
485                         offset, 1, cmd);
486                 offset += 1;
487
488                 switch (cmd){
489                 case V1_COMMAND_NULL:
490                         offset += 1; /* skip ignored/pad byte*/
491                         if (item) {
492                                 proto_item_set_text(item, "Command: NULL");
493                         }
494                         break;
495                 case V1_COMMAND_AFI:
496                         af = tvb_get_guint8(tvb, offset);
497                         proto_tree_add_uint(tree, hf_afi, tvb,
498                                 offset, 1, af);
499                         offset += 1;
500                         if (item) {
501                                 proto_item_set_text(item, "%s: %s",
502                                         val_to_str(cmd, command, "Unknown Command:0x%02x"),
503                                         val_to_str(af, afi, "Unknown Family:0x%02x")
504                                 );
505                         }
506                         break;          
507                 case V1_COMMAND_SUBNETMASK:
508                         count = tvb_get_guint8(tvb, offset);
509                         proto_tree_add_uint(tree, hf_count, tvb,
510                                 offset, 1, count);
511                         offset += 1;
512                         if (count) { /* must be 0 or 1 */
513                                 proto_tree_add_item(tree, hf_netmask, 
514                                         tvb, offset, 4, FALSE);
515                                 if (item) {
516                                         proto_item_set_text(item, "%s: %d.%d.%d.%d",
517                                                 val_to_str(cmd, command, "Unknown Command:0x%02x"), 
518                                                 tvb_get_guint8(tvb, offset),
519                                                 tvb_get_guint8(tvb, offset+1),
520                                                 tvb_get_guint8(tvb, offset+2),
521                                                 tvb_get_guint8(tvb, offset+3));
522                                 }
523                                 offset += 4;
524                         } else {
525                                 if (item) {
526                                         proto_item_set_text(item, "%s: <no mask supplied>",
527                                                 val_to_str(cmd, command, "Unknown Command:0x%02x"));
528                                 }
529                         }
530                         break;  
531                 case V1_COMMAND_METRIC:
532                         proto_tree_add_item(tree, hf_metric, tvb,
533                                 offset, 1, FALSE);
534                         if (item) {
535                                 proto_item_set_text(item, "%s: %d",
536                                         val_to_str(cmd, command, "Unknown Command:0x%02x"), 
537                                         tvb_get_guint8(tvb, offset));
538                         }
539                         offset += 1;
540                         break;          
541                 case V1_COMMAND_FLAGS0:
542                         count = tvb_get_guint8(tvb, offset);
543                         proto_tree_add_boolean(tree, hf_dest_unr, tvb, offset, 1, count);
544                         proto_tree_add_boolean(tree, hf_split_horiz, tvb, offset, 1, count);
545                         if (item) {
546                                 proto_item_set_text(item, "%s: 0x%02x",
547                                         val_to_str(cmd, command, "Unknown Command:0x%02x"), count);
548                         }
549                         offset += 1;
550                         break;
551                 case V1_COMMAND_INFINITY:
552                         proto_tree_add_item(tree, hf_infinity, tvb,
553                                 offset, 1, FALSE);
554                         if (item) {
555                                 proto_item_set_text(item, "%s: %d",
556                                         val_to_str(cmd, command, "Unknown Command:0x%02x"), tvb_get_guint8(tvb, offset));
557                         }
558                         offset += 1;
559                         break;          
560                 case V1_COMMAND_DA:
561                 case V1_COMMAND_RDA: /* same as DA */
562                         count = tvb_get_guint8(tvb, offset);
563                         proto_tree_add_uint(tree, hf_count, tvb,
564                                 offset, 1, count);
565                         offset += 1;
566                         while (count--) {
567                                 proto_tree_add_item(tree, hf_daddr, 
568                                         tvb, offset, 4, FALSE);
569                                 offset += 4;
570                         }
571                         if (item) {
572                                 proto_item_set_text(item, "%s",
573                                         val_to_str(cmd, command, "Unknown Command:0x%02x"));
574                         }
575                         break;  
576                 case V1_COMMAND_NMR:
577                         count = tvb_get_guint8(tvb, offset);
578                         proto_tree_add_uint(tree, hf_count, tvb,
579                                 offset, 1, count);
580                         offset += 1;
581                         while (count--) {
582                                 proto_tree_add_item(tree, hf_maddr, 
583                                         tvb, offset, 4, FALSE);
584                                 offset += 4;
585                                 proto_tree_add_item(tree, hf_hold, tvb,
586                                         offset, 4, FALSE);
587                                 offset += 4;
588                         }
589                         if (item) {
590                                 proto_item_set_text(item, "%s",
591                                         val_to_str(cmd, command, "Unknown Command:0x%02x"));
592                         }
593                         break;  
594                 case V1_COMMAND_NMR_CANCEL:
595                         count = tvb_get_guint8(tvb, offset);
596                         proto_tree_add_uint(tree, hf_count, tvb,
597                                 offset, 1, count);
598                         offset += 1;
599                         while (count--) {
600                                 proto_tree_add_item(tree, hf_maddr, 
601                                         tvb, offset, 4, FALSE);
602                                 offset += 4;
603                         }
604                         if (item) {
605                                 proto_item_set_text(item, "%s",
606                                         val_to_str(cmd, command, "Unknown Command:0x%02x"));
607                         }
608                         break;  
609                 }
610
611                 proto_item_set_len(item, offset-old_offset);
612         }
613
614         return offset;
615 }
616
617 /* This function is only called from the IGMP dissector */
618 int
619 dissect_dvmrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
620 {
621         proto_tree *tree;
622         proto_item *item;
623
624         if (!proto_is_protocol_enabled(proto_dvmrp)) {
625                 /* we are not enabled, skip entire packet to be nice
626                    to the igmp layer. (so clicking on IGMP will display the data)
627                  */
628                 return offset+tvb_length_remaining(tvb, offset);
629         }
630
631         item = proto_tree_add_item(parent_tree, proto_dvmrp, tvb, offset, -1, FALSE);
632         tree = proto_item_add_subtree(item, ett_dvmrp);
633
634
635         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
636                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DVMRP");
637         }
638         if (check_col(pinfo->cinfo, COL_INFO)) {
639                 col_clear(pinfo->cinfo, COL_INFO);
640         }
641
642
643         if ((tvb_length_remaining(tvb, offset)>=8)
644          && (tvb_get_guint8(tvb, 6)==0xff)
645          && (tvb_get_guint8(tvb, 7)==0x03)) {
646                 offset = dissect_dvmrp_v3(tvb, pinfo, tree, offset);
647                 proto_item_set_len(item, offset);
648                 return offset;
649         }
650
651         
652         offset = dissect_dvmrp_v1(tvb, pinfo, tree, offset);
653         proto_item_set_len(item, offset);
654         return offset;
655 }
656
657 void
658 proto_register_dvmrp(void)
659 {
660         static hf_register_info hf[] = {
661                 { &hf_version,
662                         { "DVMRP Version", "dvmrp.version", FT_UINT8, BASE_DEC,
663                           NULL, 0, "DVMRP Version", HFILL }},
664
665                 { &hf_type,
666                         { "Type", "dvmrp.type", FT_UINT8, BASE_HEX,
667                           VALS(dvmrp_type), 0, "DVMRP Packet Type", HFILL }},
668
669                 { &hf_code_v1,
670                         { "Code", "dvmrp.v1.code", FT_UINT8, BASE_HEX,
671                           VALS(code_v1), 0, "DVMRP Packet Code", HFILL }},
672
673                 { &hf_checksum,
674                         { "Checksum", "dvmrp.checksum", FT_UINT16, BASE_HEX,
675                           NULL, 0, "DVMRP Checksum", HFILL }},
676
677                 { &hf_checksum_bad,
678                         { "Bad Checksum", "dvmrp.checksum_bad", FT_BOOLEAN, BASE_NONE,
679                           NULL, 0, "Bad DVMRP Checksum", HFILL }},
680
681                 { &hf_commands,
682                         { "Commands", "dvmrp.commands", FT_NONE, BASE_NONE,
683                           NULL, 0, "DVMRP V1 Commands", HFILL }},
684
685                 { &hf_command,
686                         { "Command", "dvmrp.command", FT_UINT8, BASE_HEX,
687                           VALS(command), 0, "DVMRP V1 Command", HFILL }},
688
689                 { &hf_afi,
690                         { "Address Family", "dvmrp.afi", FT_UINT8, BASE_HEX,
691                           VALS(afi), 0, "DVMRP Address Family Indicator", HFILL }},
692
693                 { &hf_count,
694                         { "Count", "dvmrp.count", FT_UINT8, BASE_HEX,
695                           NULL, 0, "Count", HFILL }},
696
697                 { &hf_netmask,
698                         { "Netmask", "igmp.netmask", FT_IPv4, BASE_NONE,
699                           NULL, 0, "DVMRP Netmask", HFILL }},
700
701                 { &hf_metric,
702                         { "Metric", "dvmrp.metric", FT_UINT8, BASE_DEC,
703                           NULL, 0, "DVMRP Metric", HFILL }},
704
705                 {&hf_dest_unr,
706                         { "Destination Unreachable", "dvmrp.dest_unreach", FT_BOOLEAN, 8,
707                         TFS(&tfs_dest_unreach), 0x01, "Destination Unreachable", HFILL }},
708
709                 {&hf_split_horiz,
710                         { "Split Horizon", "dvmrp.split_horiz", FT_BOOLEAN, 8,
711                         TFS(&tfs_split_horiz), 0x02, "Split Horizon concealed route", HFILL }},
712
713                 { &hf_infinity,
714                         { "Infinity", "dvmrp.infinity", FT_UINT8, BASE_DEC,
715                           NULL, 0, "DVMRP Infinity", HFILL }},
716
717                 { &hf_daddr,
718                         { "Dest Addr", "igmp.daddr", FT_IPv4, BASE_NONE,
719                           NULL, 0, "DVMRP Destination Address", HFILL }},
720
721                 { &hf_maddr,
722                         { "Multicast Addr", "igmp.maddr", FT_IPv4, BASE_NONE,
723                           NULL, 0, "DVMRP Multicast Address", HFILL }},
724
725                 { &hf_hold,
726                         { "Hold Time", "dvmrp.hold", FT_UINT32, BASE_DEC,
727                           NULL, 0, "DVMRP Hold Time in seconds", HFILL }},
728
729                 { &hf_code_v3,
730                         { "Code", "dvmrp.v3.code", FT_UINT8, BASE_HEX,
731                           VALS(code_v3), 0, "DVMRP Packet Code", HFILL }},
732
733                 { &hf_capabilities,
734                         { "Capabilities", "dvmrp.capabilities", FT_NONE, BASE_NONE,
735                           NULL, 0, "DVMRP V3 Capabilities", HFILL }},
736
737                 {&hf_cap_leaf,
738                         { "Leaf", "dvmrp.cap.leaf", FT_BOOLEAN, 8,
739                         TFS(&tfs_cap_leaf), DVMRP_V3_CAP_LEAF, "Leaf", HFILL }},
740
741                 {&hf_cap_prune,
742                         { "Prune", "dvmrp.cap.prune", FT_BOOLEAN, 8,
743                         TFS(&tfs_cap_prune), DVMRP_V3_CAP_PRUNE, "Prune capability", HFILL }},
744
745                 {&hf_cap_genid,
746                         { "Genid", "dvmrp.cap.genid", FT_BOOLEAN, 8,
747                         TFS(&tfs_cap_genid), DVMRP_V3_CAP_GENID, "Genid capability", HFILL }},
748
749                 {&hf_cap_mtrace,
750                         { "Mtrace", "dvmrp.cap.mtrace", FT_BOOLEAN, 8,
751                         TFS(&tfs_cap_mtrace), DVMRP_V3_CAP_MTRACE, "Mtrace capability", HFILL }},
752
753                 {&hf_cap_snmp,
754                         { "SNMP", "dvmrp.cap.snmp", FT_BOOLEAN, 8,
755                         TFS(&tfs_cap_snmp), DVMRP_V3_CAP_SNMP, "SNMP capability", HFILL }},
756
757                 {&hf_cap_netmask,
758                         { "Netmask", "dvmrp.cap.netmask", FT_BOOLEAN, 8,
759                         TFS(&tfs_cap_netmask), DVMRP_V3_CAP_NETMASK, "Netmask capability", HFILL }},
760
761                 { &hf_min_ver,
762                         { "Minor Version", "dvmrp.min_ver", FT_UINT8, BASE_HEX,
763                           NULL, 0, "DVMRP Minor Version", HFILL }},
764
765                 { &hf_maj_ver,
766                         { "Major Version", "dvmrp.maj_ver", FT_UINT8, BASE_HEX,
767                           NULL, 0, "DVMRP Major Version", HFILL }},
768
769                 { &hf_genid,
770                         { "Generation ID", "dvmrp.genid", FT_UINT32, BASE_DEC,
771                           NULL, 0, "DVMRP Generation ID", HFILL }},
772
773                 { &hf_route,
774                         { "Route", "dvmrp.route", FT_NONE, BASE_NONE,
775                           NULL, 0, "DVMRP V3 Route Report", HFILL }},
776
777                 { &hf_saddr,
778                         { "Source Addr", "igmp.saddr", FT_IPv4, BASE_NONE,
779                           NULL, 0, "DVMRP Source Address", HFILL }},
780
781                 { &hf_life,
782                         { "Prune lifetime", "dvmrp.lifetime", FT_UINT32, BASE_DEC,
783                           NULL, 0, "DVMRP Prune Lifetime", HFILL }},
784
785                 { &hf_neighbor,
786                         { "Neighbor Addr", "igmp.neighbor", FT_IPv4, BASE_NONE,
787                           NULL, 0, "DVMRP Neighbor Address", HFILL }},
788
789         };
790         static gint *ett[] = {
791                 &ett_dvmrp,
792                 &ett_commands,
793                 &ett_capabilities,
794                 &ett_route,
795         };
796
797         proto_dvmrp = proto_register_protocol("Distance Vector Multicast Routing Protocol",
798             "DVMRP", "dvmrp");
799         proto_register_field_array(proto_dvmrp, hf, array_length(hf));
800         proto_register_subtree_array(ett, array_length(ett));
801 }