]>
git.saurik.com Git - apple/network_cmds.git/blob - tcpdump.tproj/print-dvmrp.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1995, 1996
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that: (1) source code distributions
30 * retain the above copyright notice and this paragraph in its entirety, (2)
31 * distributions including binary code include the above copyright notice and
32 * this paragraph in its entirety in the documentation or other materials
33 * provided with the distribution, and (3) all advertising materials mentioning
34 * features or use of this software display the following acknowledgement:
35 * ``This product includes software developed by the University of California,
36 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
37 * the University nor the names of its contributors may be used to endorse
38 * or promote products derived from this software without specific prior
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
46 static const char rcsid
[] =
47 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-dvmrp.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)";
50 #include <sys/param.h>
52 #include <sys/socket.h>
54 #include <netinet/in.h>
55 #include <netinet/in_systm.h>
56 #include <netinet/ip.h>
57 #include <netinet/ip_var.h>
58 #include <netinet/udp.h>
59 #include <netinet/udp_var.h>
60 #include <netinet/tcp.h>
61 #include <netinet/tcpip.h>
68 #include "interface.h"
69 #include "addrtoname.h"
72 * DVMRP message types and flag values shamelessly stolen from
75 #define DVMRP_PROBE 1 /* for finding neighbors */
76 #define DVMRP_REPORT 2 /* for reporting some or all routes */
77 #define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */
79 * of this router's neighbors
81 #define DVMRP_NEIGHBORS 4 /* response to such a request */
82 #define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */
83 #define DVMRP_NEIGHBORS2 6
84 #define DVMRP_PRUNE 7 /* prune message */
85 #define DVMRP_GRAFT 8 /* graft message */
86 #define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */
89 * 'flags' byte values in DVMRP_NEIGHBORS2 reply.
91 #define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */
92 #define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */
93 #define DVMRP_NF_DOWN 0x10 /* kernel state of interface */
94 #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */
95 #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */
97 static void print_probe(const u_char
*, const u_char
*, u_int
);
98 static void print_report(const u_char
*, const u_char
*, u_int
);
99 static void print_neighbors(const u_char
*, const u_char
*, u_int
);
100 static void print_neighbors2(const u_char
*, const u_char
*, u_int
);
101 static void print_prune(const u_char
*, const u_char
*, u_int
);
102 static void print_graft(const u_char
*, const u_char
*, u_int
);
103 static void print_graft_ack(const u_char
*, const u_char
*, u_int
);
105 static u_int32_t target_level
;
108 dvmrp_print(register const u_char
*bp
, register u_int len
)
110 register const u_char
*ep
;
111 register u_char type
;
113 ep
= (const u_char
*)snapend
;
130 print_probe(bp
, ep
, len
);
136 print_report(bp
, ep
, len
);
139 case DVMRP_ASK_NEIGHBORS
:
140 printf(" Ask-neighbors(old)");
143 case DVMRP_NEIGHBORS
:
144 printf(" Neighbors(old)");
145 print_neighbors(bp
, ep
, len
);
148 case DVMRP_ASK_NEIGHBORS2
:
149 printf(" Ask-neighbors2");
152 case DVMRP_NEIGHBORS2
:
153 printf(" Neighbors2");
155 * extract version and capabilities from IGMP group
159 target_level
= (bp
[0] << 24) | (bp
[1] << 16) |
160 (bp
[2] << 8) | bp
[3];
162 print_neighbors2(bp
, ep
, len
);
167 print_prune(bp
, ep
, len
);
172 print_graft(bp
, ep
, len
);
175 case DVMRP_GRAFT_ACK
:
176 printf(" Graft-ACK");
177 print_graft_ack(bp
, ep
, len
);
181 printf(" [type %d]", type
);
187 print_report(register const u_char
*bp
, register const u_char
*ep
,
190 register u_int32_t mask
, origin
;
191 register int metric
, i
, width
, done
;
198 mask
= (u_int32_t
)0xff << 24 | bp
[0] << 16 | bp
[1] << 8 | bp
[2];
207 printf("\n\tMask %s", intoa(htonl(mask
)));
211 if (bp
+ width
+ 1 > ep
) {
215 if (len
< width
+ 1) {
216 printf("\n\t [Truncated Report]");
220 for (i
= 0; i
< width
; ++i
)
221 origin
= origin
<< 8 | *bp
++;
226 done
= metric
& 0x80;
228 printf("\n\t %s metric %d", intoa(htonl(origin
)),
235 #define GET_ADDR(to) (memcpy((char *)to, (char *)bp, 4), bp += 4)
238 print_probe(register const u_char
*bp
, register const u_char
*ep
,
241 register u_int32_t genid
;
244 if ((len
< 4) || ((bp
+ 4) > ep
)) {
249 genid
= (bp
[0] << 24) | (bp
[1] << 16) | (bp
[2] << 8) | bp
[3];
252 printf("\n\tgenid %u", genid
);
254 while ((len
> 0) && (bp
< ep
)) {
255 if ((len
< 4) || ((bp
+ 4) > ep
)) {
261 printf("\n\tneighbor %s", ipaddr_string(neighbor
));
266 print_neighbors(register const u_char
*bp
, register const u_char
*ep
,
269 u_char laddr
[4], neighbor
[4];
270 register u_char metric
;
271 register u_char thresh
;
274 while (len
> 0 && bp
< ep
) {
275 if (len
< 7 || (bp
+ 7) >= ep
) {
284 while (--ncount
>= 0 && (len
>= 4) && (bp
+ 4) < ep
) {
286 printf(" [%s ->", ipaddr_string(laddr
));
287 printf(" %s, (%d/%d)]",
288 ipaddr_string(neighbor
), metric
, thresh
);
295 print_neighbors2(register const u_char
*bp
, register const u_char
*ep
,
298 u_char laddr
[4], neighbor
[4];
299 register u_char metric
, thresh
, flags
;
302 printf(" (v %d.%d):",
303 (int)target_level
& 0xff,
304 (int)(target_level
>> 8) & 0xff);
306 while (len
> 0 && bp
< ep
) {
307 if (len
< 8 || (bp
+ 8) >= ep
) {
317 while (--ncount
>= 0 && (len
>= 4) && (bp
+ 4) <= ep
) {
319 printf(" [%s -> ", ipaddr_string(laddr
));
320 printf("%s (%d/%d", ipaddr_string(neighbor
),
322 if (flags
& DVMRP_NF_TUNNEL
)
324 if (flags
& DVMRP_NF_SRCRT
)
326 if (flags
& DVMRP_NF_QUERIER
)
328 if (flags
& DVMRP_NF_DISABLED
)
330 if (flags
& DVMRP_NF_DOWN
)
343 print_prune(register const u_char
*bp
, register const u_char
*ep
,
351 if (len
< 12 || (bp
+ 12) > ep
) {
355 printf(" src %s grp %s", ipaddr_string(bp
), ipaddr_string(bp
+ 4));
357 GET_ADDR(prune_timer
.b
);
358 printf(" timer %d", (int)ntohl(prune_timer
.i
));
362 print_graft(register const u_char
*bp
, register const u_char
*ep
,
366 if (len
< 8 || (bp
+ 8) > ep
) {
370 printf(" src %s grp %s", ipaddr_string(bp
), ipaddr_string(bp
+ 4));
374 print_graft_ack(register const u_char
*bp
, register const u_char
*ep
,
378 if (len
< 8 || (bp
+ 8) > ep
) {
382 printf(" src %s grp %s", ipaddr_string(bp
), ipaddr_string(bp
+ 4));