moptrace.c revision 1.2 1 /* $NetBSD: moptrace.c,v 1.2 1997/03/25 03:08:02 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
19 *
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.
30 */
31
32 #ifndef LINT
33 static char rcsid[] = "$NetBSD: moptrace.c,v 1.2 1997/03/25 03:08:02 thorpej Exp $";
34 #endif
35
36 /*
37 * moptrace - MOP Trace Utility
38 *
39 * Usage: moptrace -a [ -d ] [ -3 | -4 ]
40 * moptrace [ -d ] [ -3 | -4 ] interface
41 */
42
43 #include "os.h"
44 #include "common/common.h"
45 #include "common/mopdef.h"
46 #include "common/device.h"
47 #include "common/print.h"
48 #include "common/pf.h"
49 #include "common/dl.h"
50 #include "common/rc.h"
51 #include "common/get.h"
52
53 /*
54 * The list of all interfaces that are being listened to.
55 * "selects" on the descriptors in this list.
56 */
57 struct if_info *iflist;
58
59 #ifdef NO__P
60 void Loop (/* void */);
61 void Usage (/* void */);
62 void mopProcess (/* struct if_info *, u_char * */);
63 #else
64 void Loop __P((void));
65 void Usage __P((void));
66 void mopProcess __P((struct if_info *, u_char *));
67 #endif
68
69 int AllFlag = 0; /* listen on "all" interfaces */
70 int DebugFlag = 0; /* print debugging messages */
71 int Not3Flag = 0; /* Ignore MOP V3 messages */
72 int Not4Flag = 0; /* Ignore MOP V4 messages */
73 int promisc = 1; /* Need promisc mode */
74 char *Program;
75
76 void
77 main(argc, argv)
78 int argc;
79 char **argv;
80 {
81 int op;
82 char *interface;
83
84 extern int optind, opterr;
85
86 if ((Program = strrchr(argv[0], '/')))
87 Program++;
88 else
89 Program = argv[0];
90
91 if (*Program == '-')
92 Program++;
93
94 /* All error reporting is done through syslogs. */
95 openlog(Program, LOG_PID | LOG_CONS, LOG_DAEMON);
96
97 opterr = 0;
98 while ((op = getopt(argc, argv, "34ad")) != EOF) {
99 switch (op) {
100 case '3':
101 Not3Flag++;
102 break;
103 case '4':
104 Not4Flag++;
105 break;
106 case 'a':
107 AllFlag++;
108 break;
109 case 'd':
110 DebugFlag++;
111 break;
112 default:
113 Usage();
114 /* NOTREACHED */
115 }
116 }
117
118 interface = argv[optind++];
119
120 if ((AllFlag && interface) ||
121 (!AllFlag && interface == 0) ||
122 (Not3Flag && Not4Flag))
123 Usage();
124
125 if (AllFlag)
126 deviceInitAll();
127 else
128 deviceInitOne(interface);
129
130 Loop();
131 }
132
133 void
134 Usage()
135 {
136 (void) fprintf(stderr, "usage: %s -a [ -d ] [ -3 | -4 ]\n",Program);
137 (void) fprintf(stderr, " %s [ -d ] [ -3 | -4 ] interface\n",
138 Program);
139 exit(1);
140 }
141
142 /*
143 * Process incoming packages.
144 */
145 void
146 mopProcess(ii, pkt)
147 struct if_info *ii;
148 u_char *pkt;
149 {
150 int trans;
151
152 /* We don't known which transport, Guess! */
153
154 trans = mopGetTrans(pkt, 0);
155
156 /* Ok, return if we don't want this message */
157
158 if ((trans == TRANS_ETHER) && Not3Flag) return;
159 if ((trans == TRANS_8023) && Not4Flag) return;
160
161 mopPrintHeader(stdout, pkt, trans);
162 mopPrintMopHeader(stdout, pkt, trans);
163
164 mopDumpDL(stdout, pkt, trans);
165 mopDumpRC(stdout, pkt, trans);
166
167 fprintf(stdout, "\n");
168 fflush(stdout);
169 }
170
171
172