moptrace.c revision 1.9 1 /* $NetBSD: moptrace.c,v 1.9 2003/04/20 00:20:29 christos 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 #include <sys/cdefs.h>
33 #ifndef lint
34 __RCSID("$NetBSD: moptrace.c,v 1.9 2003/04/20 00:20:29 christos Exp $");
35 #endif
36
37 /*
38 * moptrace - MOP Trace Utility
39 *
40 * Usage: moptrace -a [ -d ] [ -3 | -4 ]
41 * moptrace [ -d ] [ -3 | -4 ] interface
42 */
43
44 #include "os.h"
45 #include "common.h"
46 #include "device.h"
47 #include "dl.h"
48 #include "get.h"
49 #include "mopdef.h"
50 #include "pf.h"
51 #include "print.h"
52 #include "rc.h"
53 #include "log.h"
54
55 /*
56 * The list of all interfaces that are being listened to.
57 * "selects" on the descriptors in this list.
58 */
59 struct if_info *iflist;
60
61 void Usage __P((void));
62 int main __P((int, char **));
63 void mopProcess __P((struct if_info *, u_char *));
64
65 int AllFlag = 0; /* listen on "all" interfaces */
66 int DebugFlag = 0; /* print debugging messages */
67 int Not3Flag = 0; /* Ignore MOP V3 messages */
68 int Not4Flag = 0; /* Ignore MOP V4 messages */
69 int promisc = 1; /* Need promisc mode */
70
71 int
72 main(argc, argv)
73 int argc;
74 char **argv;
75 {
76 int op;
77 char *interface;
78
79 mopInteractive = 1;
80 opterr = 0;
81 while ((op = getopt(argc, argv, "34ad")) != -1) {
82 switch (op) {
83 case '3':
84 Not3Flag++;
85 break;
86 case '4':
87 Not4Flag++;
88 break;
89 case 'a':
90 AllFlag++;
91 break;
92 case 'd':
93 DebugFlag++;
94 break;
95 default:
96 Usage();
97 /* NOTREACHED */
98 }
99 }
100
101 interface = argv[optind++];
102
103 if ((AllFlag && interface) ||
104 (!AllFlag && interface == 0) ||
105 (Not3Flag && Not4Flag))
106 Usage();
107
108 if (AllFlag)
109 deviceInitAll();
110 else
111 deviceInitOne(interface);
112
113 Loop();
114 /* NOTREACHED */
115 return (0);
116 }
117
118 void
119 Usage()
120 {
121 (void) fprintf(stderr, "usage: %s -a [ -d ] [ -3 | -4 ]\n",
122 getprogname());
123 (void) fprintf(stderr, " %s [ -d ] [ -3 | -4 ] interface\n",
124 getprogname());
125 exit(1);
126 }
127
128 /*
129 * Process incoming packages.
130 */
131 void
132 mopProcess(ii, pkt)
133 struct if_info *ii;
134 u_char *pkt;
135 {
136 int trans;
137
138 /* We don't known which transport, Guess! */
139
140 trans = mopGetTrans(pkt, 0);
141
142 /* Ok, return if we don't want this message */
143
144 if ((trans == TRANS_ETHER) && Not3Flag) return;
145 if ((trans == TRANS_8023) && Not4Flag) return;
146
147 mopPrintHeader(stdout, pkt, trans);
148 mopPrintMopHeader(stdout, pkt, trans);
149
150 mopDumpDL(stdout, pkt, trans);
151 mopDumpRC(stdout, pkt, trans);
152
153 fprintf(stdout, "\n");
154 fflush(stdout);
155 }
156