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

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