2 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] _U_
=
24 "@(#) $Header: /tcpdump/master/tcpdump/print-rip.c,v 1.59 2006-03-23 14:58:44 hannes Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "extract.h" /* must come after interface.h */
43 u_int8_t rip_cmd
; /* request/response */
44 u_int8_t rip_vers
; /* protocol version # */
45 u_int8_t unused
[2]; /* unused */
48 #define RIPCMD_REQUEST 1 /* want info */
49 #define RIPCMD_RESPONSE 2 /* responding to request */
50 #define RIPCMD_TRACEON 3 /* turn tracing on */
51 #define RIPCMD_TRACEOFF 4 /* turn it off */
52 #define RIPCMD_POLL 5 /* want info from everybody */
53 #define RIPCMD_POLLENTRY 6 /* poll for entry */
55 static const struct tok rip_cmd_values
[] = {
56 { RIPCMD_REQUEST
, "Request" },
57 { RIPCMD_RESPONSE
, "Response" },
58 { RIPCMD_TRACEON
, "Trace on" },
59 { RIPCMD_TRACEOFF
, "Trace off" },
60 { RIPCMD_POLL
, "Poll" },
61 { RIPCMD_POLLENTRY
, "Poll Entry" },
65 #define RIP_AUTHLEN 16
66 #define RIP_ROUTELEN 20
72 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
73 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 * | Command (1) | Version (1) | unused |
75 * +---------------+---------------+-------------------------------+
76 * | Address Family Identifier (2) | Route Tag (2) |
77 * +-------------------------------+-------------------------------+
79 * +---------------------------------------------------------------+
81 * +---------------------------------------------------------------+
83 * +---------------------------------------------------------------+
85 * +---------------------------------------------------------------+
93 u_int32_t rip_dest_mask
;
95 u_int32_t rip_metric
; /* cost of route */
99 rip_entry_print_v1(register const struct rip_netinfo
*ni
)
101 register u_short family
;
104 family
= EXTRACT_16BITS(&ni
->rip_family
);
105 if (family
!= BSD_AFNUM_INET
) {
106 printf("\n\t AFI %s, ", tok2str(bsd_af_values
, "Unknown (%u)", family
));
107 print_unknown_data((u_int8_t
*)&ni
->rip_family
,"\n\t ",RIP_ROUTELEN
);
110 if (EXTRACT_16BITS(&ni
->rip_tag
) ||
111 EXTRACT_32BITS(&ni
->rip_dest_mask
) ||
112 EXTRACT_32BITS(&ni
->rip_router
)) {
113 /* MBZ fields not zero */
114 print_unknown_data((u_int8_t
*)&ni
->rip_family
,"\n\t ",RIP_ROUTELEN
);
116 } /* BSD_AFNUM_INET */
117 printf("\n\t %s, metric: %u",
118 ipaddr_string(&ni
->rip_dest
),
119 EXTRACT_32BITS(&ni
->rip_metric
));
123 rip_entry_print_v2(register const struct rip_netinfo
*ni
)
126 register u_short family
;
127 u_char buf
[RIP_AUTHLEN
];
129 family
= EXTRACT_16BITS(&ni
->rip_family
);
130 if (family
== 0xFFFF) { /* 16 bytes authentication ? */
131 if (EXTRACT_16BITS(&ni
->rip_tag
) == 2) { /* simple text authentication ? */
132 memcpy(buf
, &ni
->rip_dest
, sizeof(buf
));
133 buf
[sizeof(buf
)-1] = '\0';
134 for (p
= buf
; *p
; p
++) {
138 printf("\n\t Simple Text Authentication data: %s", buf
);
140 printf("\n\t Unknown (%u) Authentication data:",
141 EXTRACT_16BITS(&ni
->rip_tag
));
142 print_unknown_data((u_int8_t
*)&ni
->rip_dest
,"\n\t ",RIP_AUTHLEN
);
144 } else if (family
!= BSD_AFNUM_INET
) {
145 printf("\n\t AFI %s", tok2str(bsd_af_values
, "Unknown (%u)", family
));
146 print_unknown_data((u_int8_t
*)&ni
->rip_tag
,"\n\t ",RIP_ROUTELEN
-2);
148 } else { /* BSD_AFNUM_INET */
149 printf("\n\t AFI %s, %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ",
150 tok2str(bsd_af_values
, "Unknown (%u)", family
),
151 ipaddr_string(&ni
->rip_dest
),
152 mask2plen(EXTRACT_32BITS(&ni
->rip_dest_mask
)),
153 EXTRACT_16BITS(&ni
->rip_tag
),
154 EXTRACT_32BITS(&ni
->rip_metric
));
155 if (EXTRACT_32BITS(&ni
->rip_router
))
156 printf("%s", ipaddr_string(&ni
->rip_router
));
163 rip_print(const u_char
*dat
, u_int length
)
165 register const struct rip
*rp
;
166 register const struct rip_netinfo
*ni
;
177 if (i
< sizeof(*rp
)) {
183 rp
= (struct rip
*)dat
;
186 (vflag
>= 1) ? "\n\t" : "",
189 switch (rp
->rip_vers
) {
194 * XXX - RFC 1058 says
196 * 0 Datagrams whose version number is zero are to be ignored.
197 * These are from a previous version of the protocol, whose
198 * packet format was machine-specific.
200 * so perhaps we should just dump the packet, in hex.
202 print_unknown_data((u_int8_t
*)&rp
->rip_cmd
,"\n\t",length
);
205 /* dump version and lets see if we know the commands name*/
206 printf(", %s, length: %u",
207 tok2str(rip_cmd_values
,
208 "unknown command (%u)",
215 switch (rp
->rip_cmd
) {
216 case RIPCMD_RESPONSE
:
217 j
= length
/ sizeof(*ni
);
218 printf(", routes: %u",j
);
219 trunc
= (i
/ sizeof(*ni
)) != j
;
220 ni
= (struct rip_netinfo
*)(rp
+ 1);
221 for (; i
>= sizeof(*ni
); ++ni
) {
222 if (rp
->rip_vers
== 1)
223 rip_entry_print_v1(ni
);
224 else if (rp
->rip_vers
== 2)
225 rip_entry_print_v2(ni
);
235 case RIPCMD_TRACEOFF
:
237 case RIPCMD_POLLENTRY
:
244 if(!print_unknown_data((u_int8_t
*)rp
,"\n\t",length
))
249 /* do we want to see an additionally hexdump ? */
251 if(!print_unknown_data((u_int8_t
*)rp
,"\n\t",length
))