mopprobe.c revision 1.9 1 1.9 lukem /* $NetBSD: mopprobe.c,v 1.9 2009/04/17 04:16:57 lukem 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 * 3. All advertising materials mentioning features or use of this software
15 1.1 cjs * must display the following acknowledgement:
16 1.1 cjs * This product includes software developed by Mats O Jansson.
17 1.1 cjs * 4. The name of the author may not be used to endorse or promote products
18 1.1 cjs * derived from this software without specific prior written permission.
19 1.1 cjs *
20 1.1 cjs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 cjs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 cjs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 cjs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 cjs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 cjs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 cjs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 cjs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 cjs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 cjs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 cjs */
31 1.1 cjs
32 1.5 lukem #include <sys/cdefs.h>
33 1.5 lukem #ifndef lint
34 1.9 lukem __RCSID("$NetBSD: mopprobe.c,v 1.9 2009/04/17 04:16:57 lukem Exp $");
35 1.1 cjs #endif
36 1.1 cjs
37 1.1 cjs /*
38 1.1 cjs * mopprobe - MOP Probe Utility
39 1.1 cjs *
40 1.1 cjs * Usage: mopprobe -a [ -3 | -4 ]
41 1.1 cjs * mopprobe [ -3 | -4 ] interface
42 1.1 cjs */
43 1.1 cjs
44 1.4 christos #include "os.h"
45 1.5 lukem #include "cmp.h"
46 1.5 lukem #include "common.h"
47 1.5 lukem #include "device.h"
48 1.5 lukem #include "get.h"
49 1.5 lukem #include "mopdef.h"
50 1.5 lukem #include "nmadef.h"
51 1.5 lukem #include "pf.h"
52 1.5 lukem #include "print.h"
53 1.8 christos #include "log.h"
54 1.1 cjs
55 1.1 cjs /*
56 1.1 cjs * The list of all interfaces that are being listened to. rarp_loop()
57 1.1 cjs * "selects" on the descriptors in this list.
58 1.1 cjs */
59 1.1 cjs struct if_info *iflist;
60 1.1 cjs
61 1.5 lukem void Usage __P((void));
62 1.5 lukem int main __P((int, char **));
63 1.5 lukem void mopProcess __P((struct if_info *, u_char *));
64 1.1 cjs
65 1.1 cjs int AllFlag = 0; /* listen on "all" interfaces */
66 1.1 cjs int DebugFlag = 0; /* print debugging messages */
67 1.1 cjs int Not3Flag = 0; /* Not MOP V3 messages */
68 1.1 cjs int Not4Flag = 0; /* Not MOP V4 messages */
69 1.1 cjs int oflag = 0; /* print only once */
70 1.1 cjs int promisc = 1; /* Need promisc mode */
71 1.1 cjs
72 1.5 lukem int
73 1.1 cjs main(argc, argv)
74 1.1 cjs int argc;
75 1.1 cjs char **argv;
76 1.1 cjs {
77 1.1 cjs int op;
78 1.1 cjs char *interface;
79 1.1 cjs
80 1.8 christos mopInteractive = 1;
81 1.1 cjs
82 1.1 cjs opterr = 0;
83 1.5 lukem while ((op = getopt(argc, argv, "ado")) != -1) {
84 1.1 cjs switch (op) {
85 1.1 cjs case '3':
86 1.1 cjs Not3Flag++;
87 1.1 cjs break;
88 1.1 cjs case '4':
89 1.1 cjs Not4Flag++;
90 1.1 cjs break;
91 1.1 cjs case 'a':
92 1.1 cjs AllFlag++;
93 1.1 cjs break;
94 1.1 cjs case 'd':
95 1.1 cjs DebugFlag++;
96 1.1 cjs break;
97 1.1 cjs case 'o':
98 1.1 cjs oflag++;
99 1.1 cjs break;
100 1.1 cjs
101 1.1 cjs default:
102 1.1 cjs Usage();
103 1.1 cjs /* NOTREACHED */
104 1.1 cjs }
105 1.1 cjs }
106 1.1 cjs interface = argv[optind++];
107 1.1 cjs
108 1.1 cjs if ((AllFlag && interface) ||
109 1.1 cjs (!AllFlag && interface == 0) ||
110 1.1 cjs (Not3Flag && Not4Flag))
111 1.1 cjs Usage();
112 1.1 cjs
113 1.1 cjs if (AllFlag)
114 1.1 cjs deviceInitAll();
115 1.1 cjs else
116 1.1 cjs deviceInitOne(interface);
117 1.1 cjs
118 1.1 cjs Loop();
119 1.5 lukem /* NOTREACHED */
120 1.5 lukem return (0);
121 1.1 cjs }
122 1.1 cjs
123 1.1 cjs void
124 1.1 cjs Usage()
125 1.1 cjs {
126 1.7 cgd (void) fprintf(stderr, "usage: %s -a [ -3 | -4 ]\n", getprogname());
127 1.7 cgd (void) fprintf(stderr, " %s [ -3 | -4 ] interface\n",
128 1.7 cgd getprogname());
129 1.1 cjs exit(1);
130 1.1 cjs }
131 1.1 cjs
132 1.1 cjs /*
133 1.1 cjs * Process incomming packages.
134 1.1 cjs */
135 1.1 cjs void
136 1.1 cjs mopProcess(ii, pkt)
137 1.1 cjs struct if_info *ii;
138 1.1 cjs u_char *pkt;
139 1.1 cjs {
140 1.1 cjs u_char *dst, *src, *p, mopcode, tmpc, ilen;
141 1.1 cjs u_short *ptype, moplen, tmps, itype, len;
142 1.9 lukem int idx, i, device, trans;
143 1.1 cjs
144 1.1 cjs dst = pkt;
145 1.1 cjs src = pkt+6;
146 1.1 cjs ptype = (u_short *)(pkt+12);
147 1.9 lukem idx = 0;
148 1.1 cjs
149 1.1 cjs if (*ptype < 1600) {
150 1.1 cjs len = *ptype;
151 1.1 cjs trans = TRANS_8023;
152 1.1 cjs ptype = (u_short *)(pkt+20);
153 1.1 cjs p = pkt+22;
154 1.1 cjs if (Not4Flag) return;
155 1.1 cjs } else {
156 1.1 cjs len = 0;
157 1.1 cjs trans = TRANS_ETHER;
158 1.1 cjs p = pkt+14;
159 1.1 cjs if (Not3Flag) return;
160 1.1 cjs }
161 1.1 cjs
162 1.1 cjs /* Ignore our own messages */
163 1.1 cjs
164 1.1 cjs if (mopCmpEAddr(ii->eaddr,src) == 0) {
165 1.1 cjs return;
166 1.1 cjs }
167 1.1 cjs
168 1.1 cjs /* Just check multicast */
169 1.1 cjs
170 1.1 cjs if (mopCmpEAddr(rc_mcst,dst) != 0) {
171 1.1 cjs return;
172 1.1 cjs }
173 1.1 cjs
174 1.1 cjs switch (trans) {
175 1.1 cjs case TRANS_8023:
176 1.1 cjs moplen = len;
177 1.1 cjs break;
178 1.1 cjs default:
179 1.9 lukem moplen = mopGetShort(pkt,&idx);
180 1.1 cjs }
181 1.9 lukem mopcode = mopGetChar(p,&idx);
182 1.1 cjs
183 1.1 cjs /* Just process System Information */
184 1.1 cjs
185 1.1 cjs if (mopcode != MOP_K_CODE_SID) {
186 1.1 cjs return;
187 1.1 cjs }
188 1.1 cjs
189 1.9 lukem tmpc = mopGetChar(pkt,&idx); /* Reserved */
190 1.9 lukem tmps = mopGetShort(pkt,&idx); /* Receipt # */
191 1.1 cjs
192 1.1 cjs device = 0; /* Unknown Device */
193 1.1 cjs
194 1.9 lukem itype = mopGetShort(pkt,&idx);
195 1.1 cjs
196 1.9 lukem while (idx < (int)(moplen + 2)) {
197 1.9 lukem ilen = mopGetChar(pkt,&idx);
198 1.1 cjs switch (itype) {
199 1.1 cjs case 0:
200 1.9 lukem tmpc = mopGetChar(pkt,&idx);
201 1.9 lukem idx = idx + tmpc;
202 1.1 cjs break;
203 1.1 cjs case MOP_K_INFO_VER:
204 1.9 lukem idx = idx + 3;
205 1.1 cjs break;
206 1.1 cjs case MOP_K_INFO_MFCT:
207 1.9 lukem idx = idx + 2;
208 1.1 cjs break;
209 1.1 cjs case MOP_K_INFO_CNU:
210 1.9 lukem idx = idx + 6;
211 1.1 cjs break;
212 1.1 cjs case MOP_K_INFO_RTM:
213 1.9 lukem idx = idx + 2;
214 1.1 cjs break;
215 1.1 cjs case MOP_K_INFO_CSZ:
216 1.9 lukem idx = idx + 2;
217 1.1 cjs break;
218 1.1 cjs case MOP_K_INFO_RSZ:
219 1.9 lukem idx = idx + 2;
220 1.1 cjs break;
221 1.1 cjs case MOP_K_INFO_HWA:
222 1.9 lukem idx = idx + 6;
223 1.1 cjs break;
224 1.1 cjs case MOP_K_INFO_TIME:
225 1.9 lukem idx = idx + 10;
226 1.1 cjs break;
227 1.1 cjs case MOP_K_INFO_SOFD:
228 1.9 lukem device = mopGetChar(pkt,&idx);
229 1.1 cjs break;
230 1.1 cjs case MOP_K_INFO_SFID:
231 1.9 lukem tmpc = mopGetChar(pkt,&idx);
232 1.9 lukem if ((idx > 0) && (idx < 17))
233 1.9 lukem idx = idx + tmpc;
234 1.1 cjs break;
235 1.1 cjs case MOP_K_INFO_PRTY:
236 1.9 lukem idx = idx + 1;
237 1.1 cjs break;
238 1.1 cjs case MOP_K_INFO_DLTY:
239 1.9 lukem idx = idx + 1;
240 1.1 cjs break;
241 1.1 cjs case MOP_K_INFO_DLBSZ:
242 1.9 lukem idx = idx + 2;
243 1.1 cjs break;
244 1.1 cjs default:
245 1.1 cjs if (((device = NMA_C_SOFD_LCS) || /* DECserver 100 */
246 1.1 cjs (device = NMA_C_SOFD_DS2) || /* DECserver 200 */
247 1.1 cjs (device = NMA_C_SOFD_DP2) || /* DECserver 250 */
248 1.1 cjs (device = NMA_C_SOFD_DS3)) && /* DECserver 300 */
249 1.1 cjs ((itype > 101) && (itype < 107)))
250 1.1 cjs {
251 1.1 cjs switch (itype) {
252 1.1 cjs case 102:
253 1.9 lukem idx = idx + ilen;
254 1.1 cjs break;
255 1.1 cjs case 103:
256 1.9 lukem idx = idx + ilen;
257 1.1 cjs break;
258 1.1 cjs case 104:
259 1.9 lukem idx = idx + 2;
260 1.1 cjs break;
261 1.1 cjs case 105:
262 1.1 cjs (void)fprintf(stdout,"%x:%x:%x:%x:%x:%x\t",
263 1.1 cjs src[0],src[1],src[2],src[3],src[4],src[5]);
264 1.1 cjs for (i = 0; i < ilen; i++) {
265 1.9 lukem (void)fprintf(stdout, "%c",pkt[idx+i]);
266 1.1 cjs }
267 1.9 lukem idx = idx + ilen;
268 1.1 cjs (void)fprintf(stdout, "\n");
269 1.1 cjs break;
270 1.1 cjs case 106:
271 1.9 lukem idx = idx + ilen;
272 1.1 cjs break;
273 1.1 cjs };
274 1.1 cjs } else {
275 1.9 lukem idx = idx + ilen;
276 1.1 cjs };
277 1.1 cjs }
278 1.9 lukem itype = mopGetShort(pkt,&idx);
279 1.1 cjs }
280 1.1 cjs
281 1.1 cjs }
282 1.1 cjs
283