4 * Copyright (c) 1989, 1990, 1991, 1993, 1994, 1996
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include <sys/cdefs.h>
27 static const char rcsid
[] _U_
=
28 "@(#) Header: /tcpdump/master/tcpdump/print-rip.c,v 1.57 2003/11/16 09:36:34 guy Exp (LBL)";
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
38 #include <tcpdump-stdinc.h>
43 #include "interface.h"
44 #include "addrtoname.h"
45 #include "extract.h" /* must come after interface.h */
48 u_int8_t rip_cmd
; /* request/response */
49 u_int8_t rip_vers
; /* protocol version # */
50 u_int8_t unused
[2]; /* unused */
53 #define RIPCMD_REQUEST 1 /* want info */
54 #define RIPCMD_RESPONSE 2 /* responding to request */
55 #define RIPCMD_TRACEON 3 /* turn tracing on */
56 #define RIPCMD_TRACEOFF 4 /* turn it off */
57 #define RIPCMD_POLL 5 /* want info from everybody */
58 #define RIPCMD_POLLENTRY 6 /* poll for entry */
60 static const struct tok rip_cmd_values
[] = {
61 { RIPCMD_REQUEST
, "Request" },
62 { RIPCMD_RESPONSE
, "Response" },
63 { RIPCMD_TRACEON
, "Trace on" },
64 { RIPCMD_TRACEOFF
, "Trace off" },
65 { RIPCMD_POLL
, "Poll" },
66 { RIPCMD_POLLENTRY
, "Poll Entry" },
70 #define RIP_AUTHLEN 16
71 #define RIP_ROUTELEN 20
77 * 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
78 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79 * | Command (1) | Version (1) | unused |
80 * +---------------+---------------+-------------------------------+
81 * | Address Family Identifier (2) | Route Tag (2) |
82 * +-------------------------------+-------------------------------+
84 * +---------------------------------------------------------------+
86 * +---------------------------------------------------------------+
88 * +---------------------------------------------------------------+
90 * +---------------------------------------------------------------+
98 u_int32_t rip_dest_mask
;
100 u_int32_t rip_metric
; /* cost of route */
104 rip_entry_print_v1(register const struct rip_netinfo
*ni
)
106 register u_short family
;
109 family
= EXTRACT_16BITS(&ni
->rip_family
);
110 if (family
!= AF_INET
) {
111 printf("\n\t AFI: %u:", family
);
112 print_unknown_data((u_int8_t
*)&ni
->rip_family
,"\n\t ",RIP_ROUTELEN
);
115 if (EXTRACT_16BITS(&ni
->rip_tag
) ||
116 EXTRACT_32BITS(&ni
->rip_dest_mask
) ||
117 EXTRACT_32BITS(&ni
->rip_router
)) {
118 /* MBZ fields not zero */
119 print_unknown_data((u_int8_t
*)&ni
->rip_family
,"\n\t ",RIP_ROUTELEN
);
122 printf("\n\t %s, metric: %u",
123 ipaddr_string(&ni
->rip_dest
),
124 EXTRACT_32BITS(&ni
->rip_metric
));
128 rip_entry_print_v2(register const struct rip_netinfo
*ni
)
131 register u_short family
;
132 u_char buf
[RIP_AUTHLEN
];
134 family
= EXTRACT_16BITS(&ni
->rip_family
);
135 if (family
== 0xFFFF) { /* 16 bytes authentication ? */
136 if (EXTRACT_16BITS(&ni
->rip_tag
) == 2) { /* simple text authentication ? */
137 memcpy(buf
, &ni
->rip_dest
, sizeof(buf
));
138 buf
[sizeof(buf
)-1] = '\0';
139 for (p
= buf
; *p
; p
++) {
143 printf("\n\t Simple Text Authentication data: %s", buf
);
145 printf("\n\t Unknown (%u) Authentication data:",
146 EXTRACT_16BITS(&ni
->rip_tag
));
147 print_unknown_data((u_int8_t
*)&ni
->rip_dest
,"\n\t ",RIP_AUTHLEN
);
149 } else if (family
!= AF_INET
) {
150 printf("\n\t AFI: %u", family
);
151 print_unknown_data((u_int8_t
*)&ni
->rip_tag
,"\n\t ",RIP_ROUTELEN
-2);
153 } else { /* AF_INET */
154 printf("\n\t AFI: IPv4: %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ",
155 ipaddr_string(&ni
->rip_dest
),
156 mask2plen(EXTRACT_32BITS(&ni
->rip_dest_mask
)),
157 EXTRACT_16BITS(&ni
->rip_tag
),
158 EXTRACT_32BITS(&ni
->rip_metric
));
159 if (EXTRACT_32BITS(&ni
->rip_router
))
160 printf("%s", ipaddr_string(&ni
->rip_router
));
167 rip_print(const u_char
*dat
, u_int length
)
169 register const struct rip
*rp
;
170 register const struct rip_netinfo
*ni
;
181 if (i
< sizeof(*rp
)) {
187 rp
= (struct rip
*)dat
;
190 (vflag
>= 1) ? "\n\t" : "",
193 switch (rp
->rip_vers
) {
198 * XXX - RFC 1058 says
200 * 0 Datagrams whose version number is zero are to be ignored.
201 * These are from a previous version of the protocol, whose
202 * packet format was machine-specific.
204 * so perhaps we should just dump the packet, in hex.
206 print_unknown_data((u_int8_t
*)&rp
->rip_cmd
,"\n\t",length
);
209 /* dump version and lets see if we know the commands name*/
210 printf(", %s, length: %u",
211 tok2str(rip_cmd_values
,
212 "unknown command (%u)",
219 switch (rp
->rip_cmd
) {
220 case RIPCMD_RESPONSE
:
221 j
= length
/ sizeof(*ni
);
222 printf(", routes: %u",j
);
223 trunc
= (i
/ sizeof(*ni
)) != j
;
224 ni
= (struct rip_netinfo
*)(rp
+ 1);
225 for (; i
>= sizeof(*ni
); ++ni
) {
226 if (rp
->rip_vers
== 1)
227 rip_entry_print_v1(ni
);
228 else if (rp
->rip_vers
== 2)
229 rip_entry_print_v2(ni
);
239 case RIPCMD_TRACEOFF
:
241 case RIPCMD_POLLENTRY
:
248 if(!print_unknown_data((u_int8_t
*)rp
,"\n\t",length
))
253 /* do we want to see an additionally hexdump ? */
255 if(!print_unknown_data((u_int8_t
*)rp
,"\n\t",length
))