mopchk.c revision 1.11
1/*	$OpenBSD: mopchk.c,v 1.11 2006/04/17 10:30:31 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 const char rcsid[] = "$OpenBSD: mopchk.c,v 1.11 2006/04/17 10:30:31 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 */
56extern char *__progname;
57extern char version[];
58
59int
60main(argc, argv)
61	int     argc;
62	char  **argv;
63{
64	int     op, i, fd;
65	char   *filename, *p;
66	struct if_info *ii;
67	int	err, aout;
68
69	/* All error reporting is done through syslogs. */
70	openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON);
71
72	opterr = 0;
73	while ((op = getopt(argc, argv, "av")) != -1) {
74		switch (op) {
75		case 'a':
76			AllFlag++;
77			break;
78		case 'v':
79			VersionFlag++;
80			break;
81		default:
82			Usage();
83			/* NOTREACHED */
84		}
85	}
86
87	if (VersionFlag)
88		printf("%s: Version %s\n", __progname, version);
89
90	if (AllFlag) {
91		if (VersionFlag)
92			printf("\n");
93		iflist = NULL;
94		deviceInitAll();
95		if (iflist == NULL) {
96			printf("No interface\n");
97		} else {
98			printf("Interface Address\n");
99			p = NULL;
100			for (ii = iflist; ii; ii = ii->next) {
101				if (p != NULL) {
102					if (strcmp(p,ii->if_name) == 0)
103						continue;
104				}
105				printf("%-9s %x:%x:%x:%x:%x:%x\n",
106				       ii->if_name,
107				       ii->eaddr[0],ii->eaddr[1],ii->eaddr[2],
108				       ii->eaddr[3],ii->eaddr[4],ii->eaddr[5]);
109				p = ii->if_name;
110			}
111		}
112	}
113
114	if (VersionFlag || AllFlag)
115		i = 1;
116	else
117		i = 0;
118
119	while (argc > optind) {
120		if (i)	printf("\n");
121		i++;
122		filename = argv[optind++];
123		printf("Checking: %s\n",filename);
124		fd = open(filename, O_RDONLY, 0);
125		if (fd == -1) {
126			printf("Unknown file.\n");
127		} else {
128			err = CheckAOutFile(fd);
129			if (err == 0) {
130				if (GetAOutFileInfo(fd, 0, 0, 0, 0,
131						    0, 0, 0, 0, &aout) < 0) {
132					printf("Some failure in GetAOutFileInfo\n");
133					aout = -1;
134				}
135			} else {
136				aout = -1;
137			}
138			if (aout == -1)
139				err = CheckMopFile(fd);
140			if (aout == -1 && err == 0) {
141				if (GetMopFileInfo(fd, 0, 0) < 0) {
142					printf("Some failure in GetMopFileInfo\n");
143				}
144			};
145		}
146	}
147	return 0;
148}
149
150void
151Usage()
152{
153	fprintf(stderr, "usage: %s [-a] [-v] [filename...]\n", __progname);
154	exit(1);
155}
156
157/*
158 * Process incomming packages, NOT.
159 */
160/* ARGSUSED */
161void
162mopProcess(ii, pkt)
163	struct if_info *ii;
164	u_char *pkt;
165{
166}
167
168