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