GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/tcpdump/print-rt6.c Lines: 0 27 0.0 %
Date: 2017-11-07 Branches: 0 23 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: print-rt6.c,v 1.6 2015/11/16 00:16:39 mmcc 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
#ifdef INET6
26
27
#include <sys/time.h>
28
#include <sys/types.h>
29
#include <sys/socket.h>
30
31
#include <net/if.h>
32
33
#include <netinet/in.h>
34
#include <netinet/if_ether.h>
35
#include <netinet/ip.h>
36
#include <netinet/ip_icmp.h>
37
#include <netinet/ip_var.h>
38
#include <netinet/udp.h>
39
#include <netinet/udp_var.h>
40
#include <netinet/tcp.h>
41
42
#include <stdio.h>
43
44
#include <netinet/ip6.h>
45
46
#include "interface.h"
47
#include "addrtoname.h"
48
49
int
50
rt6_print(const u_char *bp, const u_char *bp2)
51
{
52
	const struct ip6_rthdr *dp;
53
	const struct ip6_rthdr0 *dp0;
54
	const struct ip6_hdr *ip;
55
	const u_char *ep;
56
	int i, len;
57
58
	dp = (struct ip6_rthdr *)bp;
59
	ip = (struct ip6_hdr *)bp2;
60
	len = dp->ip6r_len;
61
62
	/* 'ep' points to the end of avaible data. */
63
	ep = snapend;
64
65
#if 0
66
	printf("%s > %s: ",
67
	       ip6addr_string(&ip->ip6_src),
68
	       ip6addr_string(&ip->ip6_dst));
69
#endif
70
71
	TCHECK(dp->ip6r_segleft);
72
73
	printf("srcrt (len=%d, ", dp->ip6r_len);
74
	printf("type=%d, ", dp->ip6r_type);
75
	printf("segleft=%d", dp->ip6r_segleft);
76
77
	switch (dp->ip6r_type) {
78
	case IPV6_RTHDR_TYPE_0:
79
		dp0 = (struct ip6_rthdr0 *)dp;
80
81
		TCHECK(dp0->ip6r0_reserved);
82
		if (dp0->ip6r0_reserved || vflag) {
83
			printf(", rsv=0x%0x",
84
				(u_int32_t)ntohl(dp0->ip6r0_reserved));
85
		}
86
87
		if (len % 2 == 1)
88
			goto trunc;
89
		len >>= 1;
90
		for (i = 0; i < len; i++) {
91
			struct in6_addr *addr;
92
93
			addr = ((struct in6_addr *)(dp0 + 1)) + i;
94
			if ((u_char *)addr > ep - sizeof(*addr))
95
				goto trunc;
96
97
			printf(", [%d]%s", i, ip6addr_string((u_char *)addr));
98
		}
99
		printf(")");
100
		return((dp0->ip6r0_len + 1) << 3);
101
	default:
102
		if (bp + ((dp->ip6r_len + 1) << 3) > ep)
103
			goto trunc;
104
		printf(")");
105
		return((dp->ip6r_len + 1) << 3);
106
	}
107
108
 trunc:
109
	fputs(", [|srcrt]", stdout);
110
	return 65535;		/* XXX */
111
}
112
#endif /* INET6 */