1 /* $NetBSD: mopprobe.c,v 1.9 2009/04/17 04:16:57 lukem 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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
29 __RCSID("$NetBSD: mopprobe.c,v 1.9 2009/04/17 04:16:57 lukem Exp $");
33 * mopprobe - MOP Probe Utility
35 * Usage: mopprobe -a [ -3 | -4 ]
36 * mopprobe [ -3 | -4 ] interface
51 * The list of all interfaces that are being listened to. rarp_loop()
52 * "selects" on the descriptors in this list.
54 struct if_info
*iflist
;
56 void Usage
__P((void));
57 int main
__P((int, char **));
58 void mopProcess
__P((struct if_info
*, u_char
*));
60 int AllFlag
= 0; /* listen on "all" interfaces */
61 int DebugFlag
= 0; /* print debugging messages */
62 int Not3Flag
= 0; /* Not MOP V3 messages */
63 int Not4Flag
= 0; /* Not MOP V4 messages */
64 int oflag
= 0; /* print only once */
65 int promisc
= 1; /* Need promisc mode */
78 while ((op
= getopt(argc
, argv
, "ado")) != -1) {
101 interface
= argv
[optind
++];
103 if ((AllFlag
&& interface
) ||
104 (!AllFlag
&& interface
== 0) ||
105 (Not3Flag
&& Not4Flag
))
111 deviceInitOne(interface
);
121 (void) fprintf(stderr
, "usage: %s -a [ -3 | -4 ]\n", getprogname());
122 (void) fprintf(stderr
, " %s [ -3 | -4 ] interface\n",
128 * Process incomming packages.
135 u_char
*dst
, *src
, *p
, mopcode
, tmpc
, ilen
;
136 u_short
*ptype
, moplen
, tmps
, itype
, len
;
137 int idx
, i
, device
, trans
;
141 ptype
= (u_short
*)(pkt
+12);
147 ptype
= (u_short
*)(pkt
+20);
149 if (Not4Flag
) return;
154 if (Not3Flag
) return;
157 /* Ignore our own messages */
159 if (mopCmpEAddr(ii
->eaddr
,src
) == 0) {
163 /* Just check multicast */
165 if (mopCmpEAddr(rc_mcst
,dst
) != 0) {
174 moplen
= mopGetShort(pkt
,&idx
);
176 mopcode
= mopGetChar(p
,&idx
);
178 /* Just process System Information */
180 if (mopcode
!= MOP_K_CODE_SID
) {
184 tmpc
= mopGetChar(pkt
,&idx
); /* Reserved */
185 tmps
= mopGetShort(pkt
,&idx
); /* Receipt # */
187 device
= 0; /* Unknown Device */
189 itype
= mopGetShort(pkt
,&idx
);
191 while (idx
< (int)(moplen
+ 2)) {
192 ilen
= mopGetChar(pkt
,&idx
);
195 tmpc
= mopGetChar(pkt
,&idx
);
201 case MOP_K_INFO_MFCT
:
219 case MOP_K_INFO_TIME
:
222 case MOP_K_INFO_SOFD
:
223 device
= mopGetChar(pkt
,&idx
);
225 case MOP_K_INFO_SFID
:
226 tmpc
= mopGetChar(pkt
,&idx
);
227 if ((idx
> 0) && (idx
< 17))
230 case MOP_K_INFO_PRTY
:
233 case MOP_K_INFO_DLTY
:
236 case MOP_K_INFO_DLBSZ
:
240 if (((device
= NMA_C_SOFD_LCS
) || /* DECserver 100 */
241 (device
= NMA_C_SOFD_DS2
) || /* DECserver 200 */
242 (device
= NMA_C_SOFD_DP2
) || /* DECserver 250 */
243 (device
= NMA_C_SOFD_DS3
)) && /* DECserver 300 */
244 ((itype
> 101) && (itype
< 107)))
257 (void)fprintf(stdout
,"%x:%x:%x:%x:%x:%x\t",
258 src
[0],src
[1],src
[2],src
[3],src
[4],src
[5]);
259 for (i
= 0; i
< ilen
; i
++) {
260 (void)fprintf(stdout
, "%c",pkt
[idx
+i
]);
263 (void)fprintf(stdout
, "\n");
273 itype
= mopGetShort(pkt
,&idx
);