1 /* $NetBSD: mopprobe.c,v 1.4 1997/04/17 21:09:27 christos Exp $ */
4 * Copyright (c) 1993-96 Mats O Jansson. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Mats O Jansson.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 /*__RCSID("$NetBSD: mopprobe.c,v 1.4 1997/04/17 21:09:27 christos Exp $");*/
38 * mopprobe - MOP Probe Utility
40 * Usage: mopprobe -a [ -3 | -4 ]
41 * mopprobe [ -3 | -4 ] interface
45 #include "common/cmp.h"
46 #include "common/common.h"
47 #include "common/device.h"
48 #include "common/get.h"
49 #include "common/mopdef.h"
50 #include "common/nmadef.h"
51 #include "common/pf.h"
52 #include "common/print.h"
55 * The list of all interfaces that are being listened to. rarp_loop()
56 * "selects" on the descriptors in this list.
58 struct if_info
*iflist
;
60 void Usage
__P((void));
61 int main
__P((int, char **));
62 void mopProcess
__P((struct if_info
*, u_char
*));
64 int AllFlag
= 0; /* listen on "all" interfaces */
65 int DebugFlag
= 0; /* print debugging messages */
66 int Not3Flag
= 0; /* Not MOP V3 messages */
67 int Not4Flag
= 0; /* Not MOP V4 messages */
68 int oflag
= 0; /* print only once */
69 int promisc
= 1; /* Need promisc mode */
71 extern char *__progname
; /* from crt0.o */
81 /* All error reporting is done through syslogs. */
82 openlog(__progname
, LOG_PID
| LOG_CONS
, LOG_DAEMON
);
85 while ((op
= getopt(argc
, argv
, "ado")) != -1) {
108 interface
= argv
[optind
++];
110 if ((AllFlag
&& interface
) ||
111 (!AllFlag
&& interface
== 0) ||
112 (Not3Flag
&& Not4Flag
))
118 deviceInitOne(interface
);
128 (void) fprintf(stderr
, "usage: %s -a [ -3 | -4 ]\n", __progname
);
129 (void) fprintf(stderr
, " %s [ -3 | -4 ] interface\n", __progname
);
134 * Process incomming packages.
141 u_char
*dst
, *src
, *p
, mopcode
, tmpc
, ilen
;
142 u_short
*ptype
, moplen
, tmps
, itype
, len
;
143 int index
, i
, device
, trans
;
147 ptype
= (u_short
*)(pkt
+12);
153 ptype
= (u_short
*)(pkt
+20);
155 if (Not4Flag
) return;
160 if (Not3Flag
) return;
163 /* Ignore our own messages */
165 if (mopCmpEAddr(ii
->eaddr
,src
) == 0) {
169 /* Just check multicast */
171 if (mopCmpEAddr(rc_mcst
,dst
) != 0) {
180 moplen
= mopGetShort(pkt
,&index
);
182 mopcode
= mopGetChar(p
,&index
);
184 /* Just process System Information */
186 if (mopcode
!= MOP_K_CODE_SID
) {
190 tmpc
= mopGetChar(pkt
,&index
); /* Reserved */
191 tmps
= mopGetShort(pkt
,&index
); /* Receipt # */
193 device
= 0; /* Unknown Device */
195 itype
= mopGetShort(pkt
,&index
);
197 while (index
< (int)(moplen
+ 2)) {
198 ilen
= mopGetChar(pkt
,&index
);
201 tmpc
= mopGetChar(pkt
,&index
);
202 index
= index
+ tmpc
;
207 case MOP_K_INFO_MFCT
:
225 case MOP_K_INFO_TIME
:
228 case MOP_K_INFO_SOFD
:
229 device
= mopGetChar(pkt
,&index
);
231 case MOP_K_INFO_SFID
:
232 tmpc
= mopGetChar(pkt
,&index
);
233 if ((index
> 0) && (index
< 17))
234 index
= index
+ tmpc
;
236 case MOP_K_INFO_PRTY
:
239 case MOP_K_INFO_DLTY
:
242 case MOP_K_INFO_DLBSZ
:
246 if (((device
= NMA_C_SOFD_LCS
) || /* DECserver 100 */
247 (device
= NMA_C_SOFD_DS2
) || /* DECserver 200 */
248 (device
= NMA_C_SOFD_DP2
) || /* DECserver 250 */
249 (device
= NMA_C_SOFD_DS3
)) && /* DECserver 300 */
250 ((itype
> 101) && (itype
< 107)))
254 index
= index
+ ilen
;
257 index
= index
+ ilen
;
263 (void)fprintf(stdout
,"%x:%x:%x:%x:%x:%x\t",
264 src
[0],src
[1],src
[2],src
[3],src
[4],src
[5]);
265 for (i
= 0; i
< ilen
; i
++) {
266 (void)fprintf(stdout
, "%c",pkt
[index
+i
]);
268 index
= index
+ ilen
;
269 (void)fprintf(stdout
, "\n");
272 index
= index
+ ilen
;
276 index
= index
+ ilen
;
279 itype
= mopGetShort(pkt
,&index
);