]> The Tcpdump Group git mirrors - tcpdump/blob - print-ripng.c
Bring in KAME IPv6 tcpdump. replaces esp/ah/isakmp decoder.
[tcpdump] / print-ripng.c
1 /*
2 * Copyright (c) 1989, 1990, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) /master/usr.sbin/tcpdump/tcpdump/print-rip.c,v 2.1 1995/02/03 18:15:05 polk Exp (LBL)";
25 #endif
26
27 #ifdef INET6
28
29 #include <sys/param.h>
30 #include <sys/time.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33
34 #include <netinet/in.h>
35 #include <netinet/in_systm.h>
36 #include <netinet/ip.h>
37 #include <netinet/ip_var.h>
38 #include <netinet/udp.h>
39 #include <netinet/udp_var.h>
40
41 #include <errno.h>
42 #include <stdio.h>
43
44 #include <netinet/ip6.h>
45
46 #include "route6d.h"
47 #include "interface.h"
48 #include "addrtoname.h"
49
50 static int
51 rip6_entry_print(register const struct netinfo6 *ni, int metric)
52 {
53 int l;
54 l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen);
55 if (ni->rip6_tag)
56 l += printf(" [%d]", ntohs(ni->rip6_tag));
57 if (metric)
58 l += printf(" (%d)", ni->rip6_metric);
59 return l;
60 }
61
62 void
63 ripng_print(const u_char *dat, int length)
64 {
65 register const struct rip6 *rp = (struct rip6 *)dat;
66 register const struct netinfo6 *ni;
67 register int amt = snapend - dat;
68 register int i = min(length, amt) -
69 (sizeof(struct rip6) - sizeof(struct netinfo6));
70 int j;
71 int trunc;
72
73 if (i < 0)
74 return;
75
76 switch (rp->rip6_cmd) {
77
78 case RIP6_REQUEST:
79 j = length / sizeof(*ni);
80 if (j == 1
81 && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6
82 && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) {
83 printf(" ripng-req dump");
84 break;
85 }
86 if (j * sizeof(*ni) != length - 4)
87 printf(" ripng-req %d[%d]:", j, length);
88 else
89 printf(" ripng-req %d:", j);
90 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
91 for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
92 if (vflag)
93 printf("\n\t");
94 else
95 printf(" ");
96 rip6_entry_print(ni, 0);
97 }
98 break;
99 case RIP6_RESPONSE:
100 j = length / sizeof(*ni);
101 if (j * sizeof(*ni) != length - 4)
102 printf(" ripng-resp %d[%d]:", j, length);
103 else
104 printf(" ripng-resp %d:", j);
105 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
106 for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
107 if (vflag)
108 printf("\n\t");
109 else
110 printf(" ");
111 rip6_entry_print(ni, ni->rip6_metric);
112 }
113 if (trunc)
114 printf("[|rip]");
115 break;
116 default:
117 printf(" ripng-%d ?? %d", rp->rip6_cmd, length);
118 break;
119 }
120 if (rp->rip6_vers != RIP6_VERSION)
121 printf(" [vers %d]", rp->rip6_vers);
122 }
123 #endif /* INET6 */