]> The Tcpdump Group git mirrors - tcpdump/blob - print-ripng.c
c514791157df07f30463988fc413ac1735270e8d
[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 "@(#) $Header: /tcpdump/master/tcpdump/print-ripng.c,v 1.6 2000-09-29 04:58:47 guy Exp $";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #ifdef INET6
32
33 #include <sys/param.h>
34 #include <sys/time.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
37
38 #include <netinet/in.h>
39
40 #include <errno.h>
41 #include <stdio.h>
42
43 #include <netinet/ip6.h>
44
45 #include "route6d.h"
46 #include "interface.h"
47 #include "addrtoname.h"
48
49 static int
50 rip6_entry_print(register const struct netinfo6 *ni, int metric)
51 {
52 int l;
53 l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen);
54 if (ni->rip6_tag)
55 l += printf(" [%d]", ntohs(ni->rip6_tag));
56 if (metric)
57 l += printf(" (%d)", ni->rip6_metric);
58 return l;
59 }
60
61 void
62 ripng_print(const u_char *dat, int length)
63 {
64 register const struct rip6 *rp = (struct rip6 *)dat;
65 register const struct netinfo6 *ni;
66 register int amt = snapend - dat;
67 register int i = min(length, amt) -
68 (sizeof(struct rip6) - sizeof(struct netinfo6));
69 int j;
70 int trunc;
71
72 if (i < 0)
73 return;
74
75 switch (rp->rip6_cmd) {
76
77 case RIP6_REQUEST:
78 j = length / sizeof(*ni);
79 if (j == 1
80 && rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6
81 && IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) {
82 printf(" ripng-req dump");
83 break;
84 }
85 if (j * sizeof(*ni) != length - 4)
86 printf(" ripng-req %d[%d]:", j, length);
87 else
88 printf(" ripng-req %d:", j);
89 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
90 for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
91 if (vflag)
92 printf("\n\t");
93 else
94 printf(" ");
95 rip6_entry_print(ni, 0);
96 }
97 break;
98 case RIP6_RESPONSE:
99 j = length / sizeof(*ni);
100 if (j * sizeof(*ni) != length - 4)
101 printf(" ripng-resp %d[%d]:", j, length);
102 else
103 printf(" ripng-resp %d:", j);
104 trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
105 for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
106 if (vflag)
107 printf("\n\t");
108 else
109 printf(" ");
110 rip6_entry_print(ni, ni->rip6_metric);
111 }
112 if (trunc)
113 printf("[|rip]");
114 break;
115 default:
116 printf(" ripng-%d ?? %d", rp->rip6_cmd, length);
117 break;
118 }
119 if (rp->rip6_vers != RIP6_VERSION)
120 printf(" [vers %d]", rp->rip6_vers);
121 }
122 #endif /* INET6 */