1 /****************************************************************************
2 ** File: ripng.c
3 **
4 ** Author: Mike Borella
5 **
6 ** Comments: Dump RIPng header information.
7 **
8 ** $Id: ripng.c,v 1.10 2006/11/21 07:47:34 farooq-i-azam Exp $
9 **
10 ** This program is free software; you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License as published by
12 ** the Free Software Foundation; either version 2 of the License, or
13 ** (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 Library 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 #include "global.h"
27 #include "ripng.h"
28
29 #define HOLDER_SIZE 64
30
31 /*
32 * RIPng command map
33 */
34
35 strmap_t ripng_command_map [] =
36 {
37 { RIPNG_CMD_RQ, "request" },
38 { RIPNG_CMD_RP, "reply" },
39 { 0, "" }
40 };
41
42 extern struct arg_t * my_args;
43
44 /*----------------------------------------------------------------------------
45 **
46 ** dump_ripng()
47 **
48 ** Parse RIPng packet and dump fields
49 **
50 **----------------------------------------------------------------------------
51 */
52
dump_ripng(packet_t * pkt)53 void dump_ripng(packet_t *pkt)
54 {
55 ripng_header_t ripng;
56 ripng_route_header_t ripng_route;
57 char holder[HOLDER_SIZE];
58 int route_count;
59
60 /* Set the layer */
61 set_layer(LAYER_APPLICATION);
62
63 /*
64 * Get the RIPng static header
65 */
66
67 if (get_packet_bytes((u_int8_t *) &ripng, pkt, sizeof(ripng_header_t)) == 0)
68 return;
69
70 /*
71 * Dump header
72 */
73
74 if (my_args->m)
75 {
76 display_minimal_string("| RIPng ");
77 display_minimal_string(map2str(ripng_command_map, ripng.command));
78 display_minimal_string(" ");
79 }
80 else
81 {
82 /* announcement */
83 display_header_banner("RIPng Header");
84
85 snprintf(holder, HOLDER_SIZE, "%d (%s)", ripng.command,
86 map2str(ripng_command_map, ripng.command));
87 display_string("Command", holder);
88 display("Version", (u_int8_t *) &ripng.version, 1, DISP_DEC);
89 display("MBZ", (u_int8_t *) &ripng.mbz, 2, DISP_DEC);
90 }
91
92 /*
93 * Do the individual routes.
94 */
95
96 route_count = 0;
97 while (1)
98 {
99 if (get_packet_bytes((u_int8_t *) &ripng_route, pkt,
100 sizeof(ripng_route_header_t)) == 0)
101 break;
102
103 /*
104 * Conversions
105 */
106
107 ripng_route.route_tag = ntohs(ripng_route.route_tag);
108
109 /*
110 * Dump route header
111 */
112
113 if (my_args->m)
114 {
115 /* just count routes in minimal mode */
116 route_count++;
117 }
118 else
119 {
120 display_ipv6("Address", (u_int8_t *) &ripng_route.address);
121 display("Route tag", (u_int8_t *) &ripng_route.route_tag, 2,
122 DISP_DEC);
123 display("Netmask", (u_int8_t *) &ripng_route.netmask, 1,
124 DISP_DEC);
125 display("Metric", (u_int8_t *) &ripng_route.metric, 1,
126 DISP_DEC);
127 }
128
129 } /* while */
130
131 /* display route count in minimal mode */
132 if (my_args->m)
133 {
134 display_minimal((u_int8_t *) &route_count, 4, DISP_DEC);
135 display_minimal_string(" routes ");
136 }
137
138 }
139
140