]>
The Tcpdump Group git mirrors - tcpdump/blob - print-dvmrp.c
2 * Copyright (c) 1995, 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-dvmrp.c,v 1.16 1999-11-21 09:36:51 fenner Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <netinet/in_systm.h>
37 #include <netinet/ip.h>
38 #include <netinet/ip_var.h>
39 #include <netinet/udp.h>
40 #include <netinet/udp_var.h>
41 #include <netinet/tcp.h>
48 #include "interface.h"
49 #include "addrtoname.h"
52 * DVMRP message types and flag values shamelessly stolen from
55 #define DVMRP_PROBE 1 /* for finding neighbors */
56 #define DVMRP_REPORT 2 /* for reporting some or all routes */
57 #define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */
59 * of this router's neighbors
61 #define DVMRP_NEIGHBORS 4 /* response to such a request */
62 #define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */
63 #define DVMRP_NEIGHBORS2 6
64 #define DVMRP_PRUNE 7 /* prune message */
65 #define DVMRP_GRAFT 8 /* graft message */
66 #define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */
69 * 'flags' byte values in DVMRP_NEIGHBORS2 reply.
71 #define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */
72 #define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */
73 #define DVMRP_NF_DOWN 0x10 /* kernel state of interface */
74 #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */
75 #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */
77 static void print_probe(const u_char
*, const u_char
*, u_int
);
78 static void print_report(const u_char
*, const u_char
*, u_int
);
79 static void print_neighbors(const u_char
*, const u_char
*, u_int
);
80 static void print_neighbors2(const u_char
*, const u_char
*, u_int
);
81 static void print_prune(const u_char
*, const u_char
*, u_int
);
82 static void print_graft(const u_char
*, const u_char
*, u_int
);
83 static void print_graft_ack(const u_char
*, const u_char
*, u_int
);
85 static u_int32_t target_level
;
88 dvmrp_print(register const u_char
*bp
, register u_int len
)
90 register const u_char
*ep
;
93 ep
= (const u_char
*)snapend
;
110 print_probe(bp
, ep
, len
);
116 print_report(bp
, ep
, len
);
119 case DVMRP_ASK_NEIGHBORS
:
120 printf(" Ask-neighbors(old)");
123 case DVMRP_NEIGHBORS
:
124 printf(" Neighbors(old)");
125 print_neighbors(bp
, ep
, len
);
128 case DVMRP_ASK_NEIGHBORS2
:
129 printf(" Ask-neighbors2");
132 case DVMRP_NEIGHBORS2
:
133 printf(" Neighbors2");
135 * extract version and capabilities from IGMP group
139 target_level
= (bp
[0] << 24) | (bp
[1] << 16) |
140 (bp
[2] << 8) | bp
[3];
142 print_neighbors2(bp
, ep
, len
);
147 print_prune(bp
, ep
, len
);
152 print_graft(bp
, ep
, len
);
155 case DVMRP_GRAFT_ACK
:
156 printf(" Graft-ACK");
157 print_graft_ack(bp
, ep
, len
);
161 printf(" [type %d]", type
);
167 print_report(register const u_char
*bp
, register const u_char
*ep
,
170 register u_int32_t mask
, origin
;
171 register int metric
, i
, width
, done
;
178 mask
= (u_int32_t
)0xff << 24 | bp
[0] << 16 | bp
[1] << 8 | bp
[2];
187 printf("\n\tMask %s", intoa(htonl(mask
)));
191 if (bp
+ width
+ 1 > ep
) {
195 if (len
< width
+ 1) {
196 printf("\n\t [Truncated Report]");
200 for (i
= 0; i
< width
; ++i
)
201 origin
= origin
<< 8 | *bp
++;
206 done
= metric
& 0x80;
208 printf("\n\t %s metric %d", intoa(htonl(origin
)),
215 #define GET_ADDR(to) (memcpy((char *)to, (char *)bp, 4), bp += 4)
218 print_probe(register const u_char
*bp
, register const u_char
*ep
,
221 register u_int32_t genid
;
224 if ((len
< 4) || ((bp
+ 4) > ep
)) {
229 genid
= (bp
[0] << 24) | (bp
[1] << 16) | (bp
[2] << 8) | bp
[3];
232 printf("\n\tgenid %u", genid
);
234 while ((len
> 0) && (bp
< ep
)) {
235 if ((len
< 4) || ((bp
+ 4) > ep
)) {
241 printf("\n\tneighbor %s", ipaddr_string(neighbor
));
246 print_neighbors(register const u_char
*bp
, register const u_char
*ep
,
249 u_char laddr
[4], neighbor
[4];
250 register u_char metric
;
251 register u_char thresh
;
254 while (len
> 0 && bp
< ep
) {
255 if (len
< 7 || (bp
+ 7) >= ep
) {
264 while (--ncount
>= 0 && (len
>= 4) && (bp
+ 4) < ep
) {
266 printf(" [%s ->", ipaddr_string(laddr
));
267 printf(" %s, (%d/%d)]",
268 ipaddr_string(neighbor
), metric
, thresh
);
275 print_neighbors2(register const u_char
*bp
, register const u_char
*ep
,
278 u_char laddr
[4], neighbor
[4];
279 register u_char metric
, thresh
, flags
;
282 printf(" (v %d.%d):",
283 (int)target_level
& 0xff,
284 (int)(target_level
>> 8) & 0xff);
286 while (len
> 0 && bp
< ep
) {
287 if (len
< 8 || (bp
+ 8) >= ep
) {
297 while (--ncount
>= 0 && (len
>= 4) && (bp
+ 4) <= ep
) {
299 printf(" [%s -> ", ipaddr_string(laddr
));
300 printf("%s (%d/%d", ipaddr_string(neighbor
),
302 if (flags
& DVMRP_NF_TUNNEL
)
304 if (flags
& DVMRP_NF_SRCRT
)
306 if (flags
& DVMRP_NF_QUERIER
)
308 if (flags
& DVMRP_NF_DISABLED
)
310 if (flags
& DVMRP_NF_DOWN
)
323 print_prune(register const u_char
*bp
, register const u_char
*ep
,
331 if (len
< 12 || (bp
+ 12) > ep
) {
335 printf(" src %s grp %s", ipaddr_string(bp
), ipaddr_string(bp
+ 4));
337 GET_ADDR(prune_timer
.b
);
338 printf(" timer %d", (int)ntohl(prune_timer
.i
));
342 print_graft(register const u_char
*bp
, register const u_char
*ep
,
346 if (len
< 8 || (bp
+ 8) > ep
) {
350 printf(" src %s grp %s", ipaddr_string(bp
), ipaddr_string(bp
+ 4));
354 print_graft_ack(register const u_char
*bp
, register const u_char
*ep
,
358 if (len
< 8 || (bp
+ 8) > ep
) {
362 printf(" src %s grp %s", ipaddr_string(bp
), ipaddr_string(bp
+ 4));