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