xref: /openbsd-src/usr.sbin/tcpdump/print-rt6.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: print-rt6.c,v 1.2 2007/05/06 09:56:45 claudio Exp $	*/
2 
3 
4 /*
5  * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that: (1) source code distributions
10  * retain the above copyright notice and this paragraph in its entirety, (2)
11  * distributions including binary code include the above copyright notice and
12  * this paragraph in its entirety in the documentation or other materials
13  * provided with the distribution, and (3) all advertising materials mentioning
14  * features or use of this software display the following acknowledgement:
15  * ``This product includes software developed by the University of California,
16  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
17  * the University nor the names of its contributors may be used to endorse
18  * or promote products derived from this software without specific prior
19  * written permission.
20  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23  */
24 
25 #ifndef lint
26 static const char rcsid[] =
27     "@(#) /master/usr.sbin/tcpdump/tcpdump/print-icmp.c,v 2.1 1995/02/03 18:14:42 polk Exp (LBL)";
28 #endif
29 
30 #ifdef INET6
31 
32 #include <sys/param.h>
33 #include <sys/time.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 
37 #include <net/if.h>
38 
39 #include <netinet/in.h>
40 #include <netinet/if_ether.h>
41 #include <netinet/in_systm.h>
42 #include <netinet/ip.h>
43 #include <netinet/ip_icmp.h>
44 #include <netinet/ip_var.h>
45 #include <netinet/udp.h>
46 #include <netinet/udp_var.h>
47 #include <netinet/tcp.h>
48 
49 #include <stdio.h>
50 
51 #include <netinet/ip6.h>
52 
53 #include "interface.h"
54 #include "addrtoname.h"
55 
56 int
57 rt6_print(register const u_char *bp, register const u_char *bp2)
58 {
59 	register const struct ip6_rthdr *dp;
60 	register const struct ip6_rthdr0 *dp0;
61 	register const struct ip6_hdr *ip;
62 	register const u_char *ep;
63 	int i, len;
64 
65 	dp = (struct ip6_rthdr *)bp;
66 	ip = (struct ip6_hdr *)bp2;
67 	len = dp->ip6r_len;
68 
69 	/* 'ep' points to the end of avaible data. */
70 	ep = snapend;
71 
72 #if 0
73 	printf("%s > %s: ",
74 	       ip6addr_string(&ip->ip6_src),
75 	       ip6addr_string(&ip->ip6_dst));
76 #endif
77 
78 	TCHECK(dp->ip6r_segleft);
79 
80 	printf("srcrt (len=%d, ", dp->ip6r_len);
81 	printf("type=%d, ", dp->ip6r_type);
82 	printf("segleft=%d", dp->ip6r_segleft);
83 
84 	switch (dp->ip6r_type) {
85 	case IPV6_RTHDR_TYPE_0:
86 		dp0 = (struct ip6_rthdr0 *)dp;
87 
88 		TCHECK(dp0->ip6r0_reserved);
89 		if (dp0->ip6r0_reserved || vflag) {
90 			printf(", rsv=0x%0x",
91 				(u_int32_t)ntohl(dp0->ip6r0_reserved));
92 		}
93 
94 		if (len % 2 == 1)
95 			goto trunc;
96 		len >>= 1;
97 		for (i = 0; i < len; i++) {
98 			struct in6_addr *addr;
99 
100 			addr = ((struct in6_addr *)(dp0 + 1)) + i;
101 			if ((u_char *)addr > ep - sizeof(*addr))
102 				goto trunc;
103 
104 			printf(", [%d]%s", i, ip6addr_string((u_char *)addr));
105 		}
106 		printf(")");
107 		return((dp0->ip6r0_len + 1) << 3);
108 	default:
109 		if (bp + ((dp->ip6r_len + 1) << 3) > ep)
110 			goto trunc;
111 		printf(")");
112 		return((dp->ip6r_len + 1) << 3);
113 	}
114 
115  trunc:
116 	fputs(", [|srcrt]", stdout);
117 	return 65535;		/* XXX */
118 }
119 #endif /* INET6 */
120