]>
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.53 2002-11-09 17:19:30 itojun 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 */
44 } __attribute__((packed
));
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 */
61 } __attribute__((packed
));
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 (ni
->rip_tag
|| ni
->rip_dest_mask
|| ni
->rip_router
) {
87 /* MBZ fields not zero */
89 rip_printblk((u_char
*)&ni
->rip_family
,
90 (u_char
*)&ni
->rip_metric
+
91 sizeof(ni
->rip_metric
));
95 printf(" {%s}(%d)", ipaddr_string(&ni
->rip_dest
),
96 EXTRACT_32BITS(&ni
->rip_metric
));
100 rip_entry_print_v2(register const struct rip_netinfo
*ni
)
103 register u_short family
;
104 u_char buf
[RIP_AUTHLEN
];
107 family
= EXTRACT_16BITS(&ni
->rip_family
);
108 if (family
== 0xFFFF) {
109 if (EXTRACT_16BITS(&ni
->rip_tag
) == 2) {
110 memcpy(buf
, &ni
->rip_dest
, sizeof(buf
));
111 buf
[sizeof(buf
)-1] = '\0';
112 for (p
= buf
; *p
; p
++) {
117 printf(" [password %s]", buf
);
119 printf(" [password: ");
120 rip_printblk((u_char
*)&ni
->rip_dest
,
121 (u_char
*)&ni
->rip_metric
+
122 sizeof(ni
->rip_metric
));
127 EXTRACT_16BITS(&ni
->rip_tag
));
128 rip_printblk((u_char
*)&ni
->rip_dest
,
129 (u_char
*)&ni
->rip_metric
+
130 sizeof(ni
->rip_metric
));
133 } else if (family
!= AF_INET
) {
134 printf(" [family %d:", family
);
135 rip_printblk((u_char
*)&ni
->rip_tag
,
136 (u_char
*)&ni
->rip_metric
+
137 sizeof(ni
->rip_metric
));
140 } else { /* AF_INET */
141 printf(" {%s", ipaddr_string(&ni
->rip_dest
));
142 if (ni
->rip_dest_mask
)
143 printf("/%s", ipaddr_string(&ni
->rip_dest_mask
));
145 printf("->%s", ipaddr_string(&ni
->rip_router
));
147 printf(" tag %04x", EXTRACT_16BITS(&ni
->rip_tag
));
148 printf("}(%d)", EXTRACT_32BITS(&ni
->rip_metric
));
153 rip_print(const u_char
*dat
, u_int length
)
155 register const struct rip
*rp
;
156 register const struct rip_netinfo
*ni
;
167 if (i
< sizeof(*rp
)) {
173 rp
= (struct rip
*)dat
;
174 switch (rp
->rip_vers
) {
179 * XXX - RFC 1058 says
181 * 0 Datagrams whose version number is zero are to be ignored.
182 * These are from a previous version of the protocol, whose
183 * packet format was machine-specific.
185 * so perhaps we should just dump the first few words of
186 * the packet, in hex.
189 ni
= (struct rip_netinfo
*)(rp
+ 1);
190 rip_printblk((u_char
*)&ni
->rip_family
,
191 (u_char
*)&ni
->rip_metric
+
192 sizeof(ni
->rip_metric
));
195 switch (rp
->rip_cmd
) {
197 printf(" RIPv%d-req %d", rp
->rip_vers
, length
);
199 case RIPCMD_RESPONSE
:
200 j
= length
/ sizeof(*ni
);
201 if (j
* sizeof(*ni
) + 4 != length
)
202 printf(" RIPv%d-resp [items %d] [%d]:",
203 rp
->rip_vers
, j
, length
);
205 printf(" RIPv%d-resp [items %d]:",
207 trunc
= (i
/ sizeof(*ni
)) != j
;
208 ni
= (struct rip_netinfo
*)(rp
+ 1);
209 for (; i
>= sizeof(*ni
); ++ni
) {
210 if (rp
->rip_vers
== 1)
211 rip_entry_print_v1(ni
);
213 rip_entry_print_v2(ni
);
220 printf(" RIPv%d-traceon %d: \"", rp
->rip_vers
, length
);
221 (void)fn_print((const u_char
*)(rp
+ 1), snapend
);
224 case RIPCMD_TRACEOFF
:
225 printf(" RIPv%d-traceoff %d", rp
->rip_vers
, length
);
228 printf(" RIPv%d-poll %d", rp
->rip_vers
, length
);
230 case RIPCMD_POLLENTRY
:
231 printf(" RIPv%d-pollentry %d", rp
->rip_vers
, length
);
234 printf(" RIPv%d-#%d %d", rp
->rip_vers
, rp
->rip_cmd
,