]>
The Tcpdump Group git mirrors - tcpdump/blob - print-rip.c
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
[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-rip.c,v 1.54 2002-12-11 07:14:07 guy Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "extract.h" /* must come after interface.h */
41 u_int8_t rip_cmd
; /* request/response */
42 u_int8_t rip_vers
; /* protocol version # */
43 u_int16_t rip_zero2
; /* unused */
45 #define RIPCMD_REQUEST 1 /* want info */
46 #define RIPCMD_RESPONSE 2 /* responding to request */
47 #define RIPCMD_TRACEON 3 /* turn tracing on */
48 #define RIPCMD_TRACEOFF 4 /* turn it off */
49 #define RIPCMD_POLL 5 /* want info from everybody */
50 #define RIPCMD_POLLENTRY 6 /* poll for entry */
52 #define RIP_AUTHLEN 16
58 u_int32_t rip_dest_mask
;
60 u_int32_t rip_metric
; /* cost of route */
64 rip_printblk(const u_char
*cp
, const u_char
*ep
)
66 for (; cp
< ep
; cp
+= 2)
67 printf(" %04x", EXTRACT_16BITS(cp
));
72 rip_entry_print_v1(register const struct rip_netinfo
*ni
)
74 register u_short family
;
77 family
= EXTRACT_16BITS(&ni
->rip_family
);
78 if (family
!= AF_INET
) {
79 printf(" [family %d:", family
);
80 rip_printblk((u_char
*)&ni
->rip_tag
,
81 (u_char
*)&ni
->rip_metric
+
82 sizeof(ni
->rip_metric
));
86 if (EXTRACT_16BITS(&ni
->rip_tag
) ||
87 EXTRACT_32BITS(&ni
->rip_dest_mask
) ||
88 EXTRACT_32BITS(&ni
->rip_router
)) {
89 /* MBZ fields not zero */
91 rip_printblk((u_char
*)&ni
->rip_family
,
92 (u_char
*)&ni
->rip_metric
+
93 sizeof(ni
->rip_metric
));
97 printf(" {%s}(%d)", ipaddr_string(&ni
->rip_dest
),
98 EXTRACT_32BITS(&ni
->rip_metric
));
102 rip_entry_print_v2(register const struct rip_netinfo
*ni
)
105 register u_short family
;
106 u_char buf
[RIP_AUTHLEN
];
109 family
= EXTRACT_16BITS(&ni
->rip_family
);
110 if (family
== 0xFFFF) {
111 if (EXTRACT_16BITS(&ni
->rip_tag
) == 2) {
112 memcpy(buf
, &ni
->rip_dest
, sizeof(buf
));
113 buf
[sizeof(buf
)-1] = '\0';
114 for (p
= buf
; *p
; p
++) {
119 printf(" [password %s]", buf
);
121 printf(" [password: ");
122 rip_printblk((u_char
*)&ni
->rip_dest
,
123 (u_char
*)&ni
->rip_metric
+
124 sizeof(ni
->rip_metric
));
129 EXTRACT_16BITS(&ni
->rip_tag
));
130 rip_printblk((u_char
*)&ni
->rip_dest
,
131 (u_char
*)&ni
->rip_metric
+
132 sizeof(ni
->rip_metric
));
135 } else if (family
!= AF_INET
) {
136 printf(" [family %d:", family
);
137 rip_printblk((u_char
*)&ni
->rip_tag
,
138 (u_char
*)&ni
->rip_metric
+
139 sizeof(ni
->rip_metric
));
142 } else { /* AF_INET */
143 printf(" {%s", ipaddr_string(&ni
->rip_dest
));
144 if (EXTRACT_32BITS(&ni
->rip_dest_mask
))
145 printf("/%s", ipaddr_string(&ni
->rip_dest_mask
));
146 if (EXTRACT_32BITS(&ni
->rip_router
))
147 printf("->%s", ipaddr_string(&ni
->rip_router
));
148 if (EXTRACT_16BITS(&ni
->rip_tag
))
149 printf(" tag %04x", EXTRACT_16BITS(&ni
->rip_tag
));
150 printf("}(%d)", EXTRACT_32BITS(&ni
->rip_metric
));
155 rip_print(const u_char
*dat
, u_int length
)
157 register const struct rip
*rp
;
158 register const struct rip_netinfo
*ni
;
169 if (i
< sizeof(*rp
)) {
175 rp
= (struct rip
*)dat
;
176 switch (rp
->rip_vers
) {
181 * XXX - RFC 1058 says
183 * 0 Datagrams whose version number is zero are to be ignored.
184 * These are from a previous version of the protocol, whose
185 * packet format was machine-specific.
187 * so perhaps we should just dump the first few words of
188 * the packet, in hex.
191 ni
= (struct rip_netinfo
*)(rp
+ 1);
192 rip_printblk((u_char
*)&ni
->rip_family
,
193 (u_char
*)&ni
->rip_metric
+
194 sizeof(ni
->rip_metric
));
197 switch (rp
->rip_cmd
) {
199 printf(" RIPv%d-req %d", rp
->rip_vers
, length
);
201 case RIPCMD_RESPONSE
:
202 j
= length
/ sizeof(*ni
);
203 if (j
* sizeof(*ni
) + 4 != length
)
204 printf(" RIPv%d-resp [items %d] [%d]:",
205 rp
->rip_vers
, j
, length
);
207 printf(" RIPv%d-resp [items %d]:",
209 trunc
= (i
/ sizeof(*ni
)) != j
;
210 ni
= (struct rip_netinfo
*)(rp
+ 1);
211 for (; i
>= sizeof(*ni
); ++ni
) {
212 if (rp
->rip_vers
== 1)
213 rip_entry_print_v1(ni
);
215 rip_entry_print_v2(ni
);
222 printf(" RIPv%d-traceon %d: \"", rp
->rip_vers
, length
);
223 (void)fn_print((const u_char
*)(rp
+ 1), snapend
);
226 case RIPCMD_TRACEOFF
:
227 printf(" RIPv%d-traceoff %d", rp
->rip_vers
, length
);
230 printf(" RIPv%d-poll %d", rp
->rip_vers
, length
);
232 case RIPCMD_POLLENTRY
:
233 printf(" RIPv%d-pollentry %d", rp
->rip_vers
, length
);
236 printf(" RIPv%d-#%d %d", rp
->rip_vers
, rp
->rip_cmd
,