mopchk.c revision 1.7 1 /* $NetBSD: mopchk.c,v 1.7 2001/01/11 01:42:50 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1995-96 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: mopchk.c,v 1.7 2001/01/11 01:42:50 lukem Exp $");
35 #endif
36
37 /*
38 * mopchk - MOP Check Utility
39 *
40 * Usage: mopchk [-a] [-v] [filename...]
41 */
42
43 #include "os.h"
44 #include "common.h"
45 #include "device.h"
46 #include "file.h"
47 #include "mopdef.h"
48 #include "pf.h"
49
50 /*
51 * The list of all interfaces that are being listened to. rarp_loop()
52 * "selects" on the descriptors in this list.
53 */
54 struct if_info *iflist;
55
56 void Usage __P((void));
57 int main __P((int, char **));
58 void mopProcess __P((struct if_info *, u_char *));
59
60 int AllFlag = 0; /* listen on "all" interfaces */
61 int VersionFlag = 0; /* Show version */
62 int promisc = 0; /* promisc mode not needed */
63
64 extern char *__progname; /* from crt0.o */
65 extern char version[];
66
67 int
68 main(argc, argv)
69 int argc;
70 char **argv;
71 {
72 int op, i, fd;
73 char *filename;
74 struct if_info *ii;
75 int err, aout;
76
77 /* All error reporting is done through syslogs. */
78 openlog("mopchk", LOG_PID, LOG_DAEMON);
79
80 opterr = 0;
81 while ((op = getopt(argc, argv, "av")) != -1) {
82 switch (op) {
83 case 'a':
84 AllFlag++;
85 break;
86 case 'v':
87 VersionFlag++;
88 break;
89 default:
90 Usage();
91 /* NOTREACHED */
92 }
93 }
94
95 if (VersionFlag)
96 printf("%s: Version %s\n", __progname, version);
97
98 if (AllFlag) {
99 if (VersionFlag)
100 printf("\n");
101 iflist = NULL;
102 deviceInitAll();
103 if (iflist == NULL)
104 printf("No interface\n");
105 else {
106 printf("Interface Address\n");
107 for (ii = iflist; ii; ii = ii->next)
108 printf("%-9s %x:%x:%x:%x:%x:%x\n",
109 ii->if_name, ii->eaddr[0], ii->eaddr[1],
110 ii->eaddr[2], ii->eaddr[3], ii->eaddr[4],
111 ii->eaddr[5]);
112 }
113 }
114
115 if (VersionFlag || AllFlag)
116 i = 1;
117 else
118 i = 0;
119
120 while (argc > optind) {
121 if (i) printf("\n");
122 i++;
123 filename = argv[optind++];
124 printf("Checking: %s\n", filename);
125 fd = open(filename, O_RDONLY, 0);
126 if (fd == -1)
127 printf("Unknown file.\n");
128 else {
129 err = CheckAOutFile(fd);
130 if (err == 0) {
131 if (GetAOutFileInfo(fd, 0, 0, 0, 0,
132 0, 0, 0, 0, &aout) < 0) {
133 printf(
134 "Some failure in GetAOutFileInfo\n");
135 aout = -1;
136 }
137 } else
138 aout = -1;
139 if (aout == -1)
140 err = CheckMopFile(fd);
141 if (aout == -1 && err == 0)
142 if (GetMopFileInfo(fd, 0, 0) < 0)
143 printf(
144 "Some failure in GetMopFileInfo\n");
145 }
146 }
147 return (0);
148 }
149
150 void
151 Usage()
152 {
153 (void) fprintf(stderr, "usage: %s [-a] [-v] [filename...]\n",
154 __progname);
155 exit(1);
156 }
157
158 /*
159 * Process incomming packages.
160 * Doesn't actually do anything for mopchk(1)
161 */
162 void
163 mopProcess(ii, pkt)
164 struct if_info *ii;
165 u_char *pkt;
166 {
167 }
168