xref: /openbsd/usr.sbin/tcpdump/print-ripng.c (revision 133306f0)
1 /*	$OpenBSD: print-ripng.c,v 1.1 2000/04/26 21:35:42 jakob Exp $	*/
2 
3 /*
4  * Copyright (c) 1989, 1990, 1991, 1993, 1994
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that: (1) source code distributions
9  * retain the above copyright notice and this paragraph in its entirety, (2)
10  * distributions including binary code include the above copyright notice and
11  * this paragraph in its entirety in the documentation or other materials
12  * provided with the distribution, and (3) all advertising materials mentioning
13  * features or use of this software display the following acknowledgement:
14  * ``This product includes software developed by the University of California,
15  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16  * the University nor the names of its contributors may be used to endorse
17  * or promote products derived from this software without specific prior
18  * written permission.
19  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22  */
23 
24 #ifndef lint
25 static const char rcsid[] =
26     "@(#) /master/usr.sbin/tcpdump/tcpdump/print-rip.c,v 2.1 1995/02/03 18:15:05 polk Exp (LBL)";
27 #endif
28 
29 #ifdef INET6
30 
31 #include <sys/param.h>
32 #include <sys/time.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 
36 #include <netinet/in.h>
37 #include <netinet/in_systm.h>
38 #include <netinet/ip.h>
39 #include <netinet/ip_var.h>
40 #include <netinet/udp.h>
41 #include <netinet/udp_var.h>
42 
43 #include <errno.h>
44 #include <stdio.h>
45 
46 #include <netinet/ip6.h>
47 
48 #include "route6d.h"
49 #include "interface.h"
50 #include "addrtoname.h"
51 
52 static int
53 rip6_entry_print(register const struct netinfo6 *ni, int metric)
54 {
55 	int l;
56 	l = printf("%s/%d", ip6addr_string(&ni->rip6_dest), ni->rip6_plen);
57 	if (ni->rip6_tag)
58 		l += printf(" [%d]", ntohs(ni->rip6_tag));
59 	if (metric)
60 		l += printf(" (%d)", ni->rip6_metric);
61 	return l;
62 }
63 
64 void
65 ripng_print(const u_char *dat, int length)
66 {
67 	register const struct rip6 *rp = (struct rip6 *)dat;
68 	register const struct netinfo6 *ni;
69 	register int amt = snapend - dat;
70 	register int i = min(length, amt) -
71 			 (sizeof(struct rip6) - sizeof(struct netinfo6));
72 	int j;
73 	int trunc;
74 
75 	if (i < 0)
76 		return;
77 
78 	switch (rp->rip6_cmd) {
79 
80 	case RIP6_REQUEST:
81 		j = length / sizeof(*ni);
82 		if (j == 1
83 		    &&  rp->rip6_nets->rip6_metric == HOPCNT_INFINITY6
84 		    &&  IN6_IS_ADDR_UNSPECIFIED(&rp->rip6_nets->rip6_dest)) {
85 			printf(" ripng-req dump");
86 			break;
87 		}
88 		if (j * sizeof(*ni) != length - 4)
89 			printf(" ripng-req %d[%d]:", j, length);
90 		else
91 			printf(" ripng-req %d:", j);
92 		trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
93 		for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
94 			if (vflag)
95 				printf("\n\t");
96 			else
97 				printf(" ");
98 			rip6_entry_print(ni, 0);
99 		}
100 		break;
101 	case RIP6_RESPONSE:
102 		j = length / sizeof(*ni);
103 		if (j * sizeof(*ni) != length - 4)
104 			printf(" ripng-resp %d[%d]:", j, length);
105 		else
106 			printf(" ripng-resp %d:", j);
107 		trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
108 		for (ni = rp->rip6_nets; (i -= sizeof(*ni)) >= 0; ++ni) {
109 			if (vflag)
110 				printf("\n\t");
111 			else
112 				printf(" ");
113 			rip6_entry_print(ni, ni->rip6_metric);
114 		}
115 		if (trunc)
116 			printf("[|rip]");
117 		break;
118 	default:
119 		printf(" ripng-%d ?? %d", rp->rip6_cmd, length);
120 		break;
121 	}
122 	if (rp->rip6_vers != RIP6_VERSION)
123 		printf(" [vers %d]", rp->rip6_vers);
124 }
125 #endif /* INET6 */
126