Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / mopd / moptrace / moptrace.c
blob79a44301796c41650d47911ab058759adcaf3d0d
1 /* $NetBSD: moptrace.c,v 1.9 2003/04/20 00:20:29 christos Exp $ */
3 /*
4 * Copyright (c) 1993-95 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
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.
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>
28 #ifndef lint
29 __RCSID("$NetBSD: moptrace.c,v 1.9 2003/04/20 00:20:29 christos Exp $");
30 #endif
33 * moptrace - MOP Trace Utility
35 * Usage: moptrace -a [ -d ] [ -3 | -4 ]
36 * moptrace [ -d ] [ -3 | -4 ] interface
39 #include "os.h"
40 #include "common.h"
41 #include "device.h"
42 #include "dl.h"
43 #include "get.h"
44 #include "mopdef.h"
45 #include "pf.h"
46 #include "print.h"
47 #include "rc.h"
48 #include "log.h"
51 * The list of all interfaces that are being listened to.
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; /* Ignore MOP V3 messages */
63 int Not4Flag = 0; /* Ignore MOP V4 messages */
64 int promisc = 1; /* Need promisc mode */
66 int
67 main(argc, argv)
68 int argc;
69 char **argv;
71 int op;
72 char *interface;
74 mopInteractive = 1;
75 opterr = 0;
76 while ((op = getopt(argc, argv, "34ad")) != -1) {
77 switch (op) {
78 case '3':
79 Not3Flag++;
80 break;
81 case '4':
82 Not4Flag++;
83 break;
84 case 'a':
85 AllFlag++;
86 break;
87 case 'd':
88 DebugFlag++;
89 break;
90 default:
91 Usage();
92 /* NOTREACHED */
96 interface = argv[optind++];
98 if ((AllFlag && interface) ||
99 (!AllFlag && interface == 0) ||
100 (Not3Flag && Not4Flag))
101 Usage();
103 if (AllFlag)
104 deviceInitAll();
105 else
106 deviceInitOne(interface);
108 Loop();
109 /* NOTREACHED */
110 return (0);
113 void
114 Usage()
116 (void) fprintf(stderr, "usage: %s -a [ -d ] [ -3 | -4 ]\n",
117 getprogname());
118 (void) fprintf(stderr, " %s [ -d ] [ -3 | -4 ] interface\n",
119 getprogname());
120 exit(1);
124 * Process incoming packages.
126 void
127 mopProcess(ii, pkt)
128 struct if_info *ii;
129 u_char *pkt;
131 int trans;
133 /* We don't known which transport, Guess! */
135 trans = mopGetTrans(pkt, 0);
137 /* Ok, return if we don't want this message */
139 if ((trans == TRANS_ETHER) && Not3Flag) return;
140 if ((trans == TRANS_8023) && Not4Flag) return;
142 mopPrintHeader(stdout, pkt, trans);
143 mopPrintMopHeader(stdout, pkt, trans);
145 mopDumpDL(stdout, pkt, trans);
146 mopDumpRC(stdout, pkt, trans);
148 fprintf(stdout, "\n");
149 fflush(stdout);