mopprobe.c revision 1.13 1 1.13 christos /* $NetBSD: mopprobe.c,v 1.13 2016/06/08 01:17:54 christos Exp $ */
2 1.2 thorpej
3 1.1 cjs /*
4 1.1 cjs * Copyright (c) 1993-96 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.13 christos #include "port.h"
28 1.5 lukem #ifndef lint
29 1.13 christos __RCSID("$NetBSD: mopprobe.c,v 1.13 2016/06/08 01:17:54 christos Exp $");
30 1.1 cjs #endif
31 1.1 cjs
32 1.1 cjs /*
33 1.1 cjs * mopprobe - MOP Probe Utility
34 1.1 cjs *
35 1.1 cjs * Usage: mopprobe -a [ -3 | -4 ]
36 1.1 cjs * mopprobe [ -3 | -4 ] interface
37 1.1 cjs */
38 1.1 cjs
39 1.4 christos #include "os.h"
40 1.5 lukem #include "cmp.h"
41 1.5 lukem #include "common.h"
42 1.5 lukem #include "device.h"
43 1.5 lukem #include "get.h"
44 1.5 lukem #include "mopdef.h"
45 1.5 lukem #include "nmadef.h"
46 1.5 lukem #include "pf.h"
47 1.5 lukem #include "print.h"
48 1.8 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. rarp_loop()
52 1.1 cjs * "selects" on the descriptors in this list.
53 1.1 cjs */
54 1.1 cjs 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; /* Not MOP V3 messages */
62 1.1 cjs int Not4Flag = 0; /* Not MOP V4 messages */
63 1.1 cjs int oflag = 0; /* print only once */
64 1.1 cjs int promisc = 1; /* Need promisc mode */
65 1.1 cjs
66 1.5 lukem int
67 1.11 joerg main(int argc, char **argv)
68 1.1 cjs {
69 1.1 cjs int op;
70 1.1 cjs char *interface;
71 1.1 cjs
72 1.8 christos mopInteractive = 1;
73 1.1 cjs
74 1.1 cjs opterr = 0;
75 1.5 lukem while ((op = getopt(argc, argv, "ado")) != -1) {
76 1.1 cjs switch (op) {
77 1.1 cjs case '3':
78 1.1 cjs Not3Flag++;
79 1.1 cjs break;
80 1.1 cjs case '4':
81 1.1 cjs Not4Flag++;
82 1.1 cjs break;
83 1.1 cjs case 'a':
84 1.1 cjs AllFlag++;
85 1.1 cjs break;
86 1.1 cjs case 'd':
87 1.1 cjs DebugFlag++;
88 1.1 cjs break;
89 1.1 cjs case 'o':
90 1.1 cjs oflag++;
91 1.1 cjs break;
92 1.1 cjs
93 1.1 cjs default:
94 1.1 cjs Usage();
95 1.1 cjs /* NOTREACHED */
96 1.1 cjs }
97 1.1 cjs }
98 1.1 cjs interface = argv[optind++];
99 1.1 cjs
100 1.1 cjs if ((AllFlag && interface) ||
101 1.1 cjs (!AllFlag && interface == 0) ||
102 1.1 cjs (Not3Flag && Not4Flag))
103 1.1 cjs Usage();
104 1.1 cjs
105 1.1 cjs if (AllFlag)
106 1.1 cjs deviceInitAll();
107 1.1 cjs else
108 1.1 cjs deviceInitOne(interface);
109 1.1 cjs
110 1.1 cjs Loop();
111 1.5 lukem /* NOTREACHED */
112 1.5 lukem return (0);
113 1.1 cjs }
114 1.1 cjs
115 1.11 joerg static void
116 1.11 joerg Usage(void)
117 1.1 cjs {
118 1.7 cgd (void) fprintf(stderr, "usage: %s -a [ -3 | -4 ]\n", getprogname());
119 1.7 cgd (void) fprintf(stderr, " %s [ -3 | -4 ] interface\n",
120 1.7 cgd getprogname());
121 1.1 cjs exit(1);
122 1.1 cjs }
123 1.1 cjs
124 1.1 cjs /*
125 1.1 cjs * Process incomming packages.
126 1.1 cjs */
127 1.1 cjs void
128 1.11 joerg mopProcess(struct if_info *ii, u_char *pkt)
129 1.1 cjs {
130 1.1 cjs u_char *dst, *src, *p, mopcode, tmpc, ilen;
131 1.12 christos u_short *ptype, moplen, itype, len;
132 1.9 lukem int idx, i, device, trans;
133 1.1 cjs
134 1.1 cjs dst = pkt;
135 1.1 cjs src = pkt+6;
136 1.1 cjs ptype = (u_short *)(pkt+12);
137 1.9 lukem idx = 0;
138 1.1 cjs
139 1.1 cjs if (*ptype < 1600) {
140 1.1 cjs len = *ptype;
141 1.1 cjs trans = TRANS_8023;
142 1.1 cjs ptype = (u_short *)(pkt+20);
143 1.1 cjs p = pkt+22;
144 1.1 cjs if (Not4Flag) return;
145 1.1 cjs } else {
146 1.1 cjs len = 0;
147 1.1 cjs trans = TRANS_ETHER;
148 1.1 cjs p = pkt+14;
149 1.1 cjs if (Not3Flag) return;
150 1.1 cjs }
151 1.1 cjs
152 1.1 cjs /* Ignore our own messages */
153 1.1 cjs
154 1.1 cjs if (mopCmpEAddr(ii->eaddr,src) == 0) {
155 1.1 cjs return;
156 1.1 cjs }
157 1.1 cjs
158 1.1 cjs /* Just check multicast */
159 1.1 cjs
160 1.1 cjs if (mopCmpEAddr(rc_mcst,dst) != 0) {
161 1.1 cjs return;
162 1.1 cjs }
163 1.1 cjs
164 1.1 cjs switch (trans) {
165 1.1 cjs case TRANS_8023:
166 1.1 cjs moplen = len;
167 1.1 cjs break;
168 1.1 cjs default:
169 1.9 lukem moplen = mopGetShort(pkt,&idx);
170 1.1 cjs }
171 1.9 lukem mopcode = mopGetChar(p,&idx);
172 1.1 cjs
173 1.1 cjs /* Just process System Information */
174 1.1 cjs
175 1.1 cjs if (mopcode != MOP_K_CODE_SID) {
176 1.1 cjs return;
177 1.1 cjs }
178 1.1 cjs
179 1.9 lukem tmpc = mopGetChar(pkt,&idx); /* Reserved */
180 1.12 christos (void)mopGetShort(pkt,&idx); /* Receipt # */
181 1.1 cjs
182 1.1 cjs device = 0; /* Unknown Device */
183 1.1 cjs
184 1.9 lukem itype = mopGetShort(pkt,&idx);
185 1.1 cjs
186 1.9 lukem while (idx < (int)(moplen + 2)) {
187 1.9 lukem ilen = mopGetChar(pkt,&idx);
188 1.1 cjs switch (itype) {
189 1.1 cjs case 0:
190 1.9 lukem tmpc = mopGetChar(pkt,&idx);
191 1.9 lukem idx = idx + tmpc;
192 1.1 cjs break;
193 1.1 cjs case MOP_K_INFO_VER:
194 1.9 lukem idx = idx + 3;
195 1.1 cjs break;
196 1.1 cjs case MOP_K_INFO_MFCT:
197 1.9 lukem idx = idx + 2;
198 1.1 cjs break;
199 1.1 cjs case MOP_K_INFO_CNU:
200 1.9 lukem idx = idx + 6;
201 1.1 cjs break;
202 1.1 cjs case MOP_K_INFO_RTM:
203 1.9 lukem idx = idx + 2;
204 1.1 cjs break;
205 1.1 cjs case MOP_K_INFO_CSZ:
206 1.9 lukem idx = idx + 2;
207 1.1 cjs break;
208 1.1 cjs case MOP_K_INFO_RSZ:
209 1.9 lukem idx = idx + 2;
210 1.1 cjs break;
211 1.1 cjs case MOP_K_INFO_HWA:
212 1.9 lukem idx = idx + 6;
213 1.1 cjs break;
214 1.1 cjs case MOP_K_INFO_TIME:
215 1.9 lukem idx = idx + 10;
216 1.1 cjs break;
217 1.1 cjs case MOP_K_INFO_SOFD:
218 1.9 lukem device = mopGetChar(pkt,&idx);
219 1.1 cjs break;
220 1.1 cjs case MOP_K_INFO_SFID:
221 1.9 lukem tmpc = mopGetChar(pkt,&idx);
222 1.9 lukem if ((idx > 0) && (idx < 17))
223 1.9 lukem idx = idx + tmpc;
224 1.1 cjs break;
225 1.1 cjs case MOP_K_INFO_PRTY:
226 1.9 lukem idx = idx + 1;
227 1.1 cjs break;
228 1.1 cjs case MOP_K_INFO_DLTY:
229 1.9 lukem idx = idx + 1;
230 1.1 cjs break;
231 1.1 cjs case MOP_K_INFO_DLBSZ:
232 1.9 lukem idx = idx + 2;
233 1.1 cjs break;
234 1.1 cjs default:
235 1.1 cjs if (((device = NMA_C_SOFD_LCS) || /* DECserver 100 */
236 1.1 cjs (device = NMA_C_SOFD_DS2) || /* DECserver 200 */
237 1.1 cjs (device = NMA_C_SOFD_DP2) || /* DECserver 250 */
238 1.1 cjs (device = NMA_C_SOFD_DS3)) && /* DECserver 300 */
239 1.1 cjs ((itype > 101) && (itype < 107)))
240 1.1 cjs {
241 1.1 cjs switch (itype) {
242 1.1 cjs case 102:
243 1.9 lukem idx = idx + ilen;
244 1.1 cjs break;
245 1.1 cjs case 103:
246 1.9 lukem idx = idx + ilen;
247 1.1 cjs break;
248 1.1 cjs case 104:
249 1.9 lukem idx = idx + 2;
250 1.1 cjs break;
251 1.1 cjs case 105:
252 1.1 cjs (void)fprintf(stdout,"%x:%x:%x:%x:%x:%x\t",
253 1.1 cjs src[0],src[1],src[2],src[3],src[4],src[5]);
254 1.1 cjs for (i = 0; i < ilen; i++) {
255 1.9 lukem (void)fprintf(stdout, "%c",pkt[idx+i]);
256 1.1 cjs }
257 1.9 lukem idx = idx + ilen;
258 1.1 cjs (void)fprintf(stdout, "\n");
259 1.1 cjs break;
260 1.1 cjs case 106:
261 1.9 lukem idx = idx + ilen;
262 1.1 cjs break;
263 1.1 cjs };
264 1.1 cjs } else {
265 1.9 lukem idx = idx + ilen;
266 1.1 cjs };
267 1.1 cjs }
268 1.9 lukem itype = mopGetShort(pkt,&idx);
269 1.1 cjs }
270 1.1 cjs
271 1.1 cjs }
272 1.1 cjs
273