1/*	$NetBSD: mopchk.c,v 1.12 2009/10/20 00:51:13 snj 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#include <sys/cdefs.h>
28#ifndef lint
29__RCSID("$NetBSD: mopchk.c,v 1.12 2009/10/20 00:51:13 snj Exp $");
30#endif
31
32/*
33 * mopchk - MOP Check Utility
34 *
35 * Usage:	mopchk [-a] [-v] [filename...]
36 */
37
38#include "os.h"
39#include "common.h"
40#include "device.h"
41#include "file.h"
42#include "mopdef.h"
43#include "pf.h"
44#include "log.h"
45
46/*
47 * The list of all interfaces that are being listened to.  rarp_loop()
48 * "selects" on the descriptors in this list.
49 */
50struct if_info *iflist;
51
52__dead static void	Usage(void);
53void	mopProcess(struct if_info *, u_char *);
54
55int     AllFlag = 0;		/* listen on "all" interfaces  */
56int	VersionFlag = 0;	/* Show version */
57int	promisc = 0;		/* promisc mode not needed */
58
59extern char	version[];
60
61int
62main(int argc, char  **argv)
63{
64	struct dllist dl;
65	int     op, i;
66	char   *filename;
67	struct if_info *ii;
68	int	error;
69
70	mopInteractive = 1;
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", getprogname(), 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			for (ii = iflist; ii; ii = ii->next)
100				printf("%-9s %x:%x:%x:%x:%x:%x\n",
101				    ii->if_name, ii->eaddr[0], ii->eaddr[1],
102				    ii->eaddr[2], ii->eaddr[3], ii->eaddr[4],
103				    ii->eaddr[5]);
104		}
105	}
106
107	if (VersionFlag || AllFlag)
108		i = 1;
109	else
110		i = 0;
111
112	while (argc > optind) {
113		if (i)	printf("\n");
114		i++;
115		filename = argv[optind++];
116		printf("Checking: %s\n", filename);
117		dl.ldfd = open(filename, O_RDONLY, 0);
118		if (dl.ldfd == -1)
119			printf("Unknown file.\n");
120		else {
121			if ((error = CheckElfFile(dl.ldfd)) == 0) {
122				if (GetElfFileInfo(&dl) < 0) {
123					printf(
124					"Some failure in GetElfFileInfo\n");
125				}
126			} else if ((error = CheckAOutFile(dl.ldfd)) == 0) {
127				if (GetAOutFileInfo(&dl) < 0) {
128					printf(
129					"Some failure in GetAOutFileInfo\n");
130				}
131			} else if ((error = CheckMopFile(dl.ldfd)) == 0) {
132				if (GetMopFileInfo(&dl) < 0) {
133					printf(
134					    "Some failure in GetMopFileInfo\n");
135				}
136			}
137		}
138		(void) close(dl.ldfd);
139	}
140	return (0);
141}
142
143static void
144Usage(void)
145{
146	(void) fprintf(stderr, "usage: %s [-a] [-v] [filename...]\n",
147	    getprogname());
148	exit(1);
149}
150
151/*
152 * Process incomming packages.
153 * Doesn't actually do anything for mopchk(1)
154 */
155void
156mopProcess(struct if_info *ii, u_char *pkt)
157{
158}
159