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