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