GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/mopd/moptrace/moptrace.c Lines: 0 34 0.0 %
Date: 2017-11-07 Branches: 0 19 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: moptrace.c,v 1.13 2015/02/09 23:00:14 deraadt Exp $ */
2
3
/*
4
 * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in the
13
 *    documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
/*
28
 * moptrace - MOP Trace Utility
29
 *
30
 * Usage:	moptrace [-3 | -4] [-ad] interface
31
 */
32
33
#include "os.h"
34
#include "common/common.h"
35
#include "common/mopdef.h"
36
#include "common/device.h"
37
#include "common/print.h"
38
#include "common/pf.h"
39
#include "common/dl.h"
40
#include "common/rc.h"
41
#include "common/get.h"
42
43
/*
44
 * The list of all interfaces that are being listened to.
45
 * "selects" on the descriptors in this list.
46
 */
47
struct if_info *iflist;
48
49
void   Usage(void);
50
void   mopProcess(struct if_info *, u_char *);
51
52
int     AllFlag = 0;		/* listen on "all" interfaces  */
53
int     DebugFlag = 0;		/* print debugging messages    */
54
int	Not3Flag = 0;		/* Ignore MOP V3 messages      */
55
int	Not4Flag = 0;		/* Ignore MOP V4 messages      */
56
int	promisc = 1;		/* Need promisc mode           */
57
extern char *__progname;
58
59
int
60
main(int argc, char *argv[])
61
{
62
	int     op;
63
	char   *interface;
64
65
	/* All error reporting is done through syslogs. */
66
	openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON);
67
68
	opterr = 0;
69
	while ((op = getopt(argc, argv, "34ad")) != -1) {
70
		switch (op) {
71
		case '3':
72
			Not3Flag = 1;
73
			break;
74
		case '4':
75
			Not4Flag = 1;
76
			break;
77
		case 'a':
78
			AllFlag = 1;
79
			break;
80
		case 'd':
81
			DebugFlag++;
82
			break;
83
		default:
84
			Usage();
85
			/* NOTREACHED */
86
		}
87
	}
88
89
	interface = argv[optind++];
90
91
	if ((AllFlag && interface) ||
92
	    (!AllFlag && interface == 0) ||
93
	    (Not3Flag && Not4Flag))
94
		Usage();
95
96
	if (AllFlag)
97
 		deviceInitAll();
98
	else
99
		deviceInitOne(interface);
100
101
	Loop();
102
	/* NOTREACHED */
103
}
104
105
void
106
Usage()
107
{
108
	fprintf(stderr, "usage: %s [-3 | -4] [-ad] interface\n", __progname);
109
	exit(1);
110
}
111
112
/*
113
 * Process incoming packages.
114
 */
115
/* ARGSUSED */
116
void
117
mopProcess(struct if_info *ii, u_char *pkt)
118
{
119
	int	 trans;
120
121
	/* We don't known which transport, Guess! */
122
123
	trans = mopGetTrans(pkt, 0);
124
125
	/* Ok, return if we don't want this message */
126
127
	if ((trans == TRANS_ETHER) && Not3Flag) return;
128
	if ((trans == TRANS_8023) && Not4Flag)	return;
129
130
	fprintf(stdout, "Interface    : %s", ii->if_name);
131
	mopPrintHeader(stdout, pkt, trans);
132
	mopPrintMopHeader(stdout, pkt, trans);
133
134
	mopDumpDL(stdout, pkt, trans);
135
	mopDumpRC(stdout, pkt, trans);
136
137
	fprintf(stdout, "\n");
138
	fflush(stdout);
139
}