moptrace.c revision 1.7 1 /* $NetBSD: moptrace.c,v 1.7 2001/02/19 23:22:45 cgd 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.7 2001/02/19 23:22:45 cgd 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
54 /*
55 * The list of all interfaces that are being listened to.
56 * "selects" on the descriptors in this list.
57 */
58 struct if_info *iflist;
59
60 void Usage __P((void));
61 int main __P((int, char **));
62 void mopProcess __P((struct if_info *, u_char *));
63
64 int AllFlag = 0; /* listen on "all" interfaces */
65 int DebugFlag = 0; /* print debugging messages */
66 int Not3Flag = 0; /* Ignore MOP V3 messages */
67 int Not4Flag = 0; /* Ignore MOP V4 messages */
68 int promisc = 1; /* Need promisc mode */
69
70 int
71 main(argc, argv)
72 int argc;
73 char **argv;
74 {
75 int op;
76 char *interface;
77
78 /* All error reporting is done through syslogs. */
79 openlog("moptrace", LOG_PID, LOG_DAEMON);
80
81 opterr = 0;
82 while ((op = getopt(argc, argv, "34ad")) != -1) {
83 switch (op) {
84 case '3':
85 Not3Flag++;
86 break;
87 case '4':
88 Not4Flag++;
89 break;
90 case 'a':
91 AllFlag++;
92 break;
93 case 'd':
94 DebugFlag++;
95 break;
96 default:
97 Usage();
98 /* NOTREACHED */
99 }
100 }
101
102 interface = argv[optind++];
103
104 if ((AllFlag && interface) ||
105 (!AllFlag && interface == 0) ||
106 (Not3Flag && Not4Flag))
107 Usage();
108
109 if (AllFlag)
110 deviceInitAll();
111 else
112 deviceInitOne(interface);
113
114 Loop();
115 /* NOTREACHED */
116 return (0);
117 }
118
119 void
120 Usage()
121 {
122 (void) fprintf(stderr, "usage: %s -a [ -d ] [ -3 | -4 ]\n",
123 getprogname());
124 (void) fprintf(stderr, " %s [ -d ] [ -3 | -4 ] interface\n",
125 getprogname());
126 exit(1);
127 }
128
129 /*
130 * Process incoming packages.
131 */
132 void
133 mopProcess(ii, pkt)
134 struct if_info *ii;
135 u_char *pkt;
136 {
137 int trans;
138
139 /* We don't known which transport, Guess! */
140
141 trans = mopGetTrans(pkt, 0);
142
143 /* Ok, return if we don't want this message */
144
145 if ((trans == TRANS_ETHER) && Not3Flag) return;
146 if ((trans == TRANS_8023) && Not4Flag) return;
147
148 mopPrintHeader(stdout, pkt, trans);
149 mopPrintMopHeader(stdout, pkt, trans);
150
151 mopDumpDL(stdout, pkt, trans);
152 mopDumpRC(stdout, pkt, trans);
153
154 fprintf(stdout, "\n");
155 fflush(stdout);
156 }
157