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