Home | History | Annotate | Line # | Download | only in mopchk
mopchk.c revision 1.12
      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  */
     50 struct if_info *iflist;
     51 
     52 void	Usage __P((void));
     53 int	main __P((int, char **));
     54 void	mopProcess __P((struct if_info *, u_char *));
     55 
     56 int     AllFlag = 0;		/* listen on "all" interfaces  */
     57 int	VersionFlag = 0;	/* Show version */
     58 int	promisc = 0;		/* promisc mode not needed */
     59 
     60 extern char	version[];
     61 
     62 int
     63 main(argc, argv)
     64 	int     argc;
     65 	char  **argv;
     66 {
     67 	struct dllist dl;
     68 	int     op, i;
     69 	char   *filename;
     70 	struct if_info *ii;
     71 	int	error;
     72 
     73 	mopInteractive = 1;
     74 
     75 	opterr = 0;
     76 	while ((op = getopt(argc, argv, "av")) != -1) {
     77 		switch (op) {
     78 		case 'a':
     79 			AllFlag++;
     80 			break;
     81 		case 'v':
     82 			VersionFlag++;
     83 			break;
     84 		default:
     85 			Usage();
     86 			/* NOTREACHED */
     87 		}
     88 	}
     89 
     90 	if (VersionFlag)
     91 		printf("%s: Version %s\n", getprogname(), version);
     92 
     93 	if (AllFlag) {
     94 		if (VersionFlag)
     95 			printf("\n");
     96 		iflist = NULL;
     97 		deviceInitAll();
     98 		if (iflist == NULL)
     99 			printf("No interface\n");
    100 		else {
    101 			printf("Interface Address\n");
    102 			for (ii = iflist; ii; ii = ii->next)
    103 				printf("%-9s %x:%x:%x:%x:%x:%x\n",
    104 				    ii->if_name, ii->eaddr[0], ii->eaddr[1],
    105 				    ii->eaddr[2], ii->eaddr[3], ii->eaddr[4],
    106 				    ii->eaddr[5]);
    107 		}
    108 	}
    109 
    110 	if (VersionFlag || AllFlag)
    111 		i = 1;
    112 	else
    113 		i = 0;
    114 
    115 	while (argc > optind) {
    116 		if (i)	printf("\n");
    117 		i++;
    118 		filename = argv[optind++];
    119 		printf("Checking: %s\n", filename);
    120 		dl.ldfd = open(filename, O_RDONLY, 0);
    121 		if (dl.ldfd == -1)
    122 			printf("Unknown file.\n");
    123 		else {
    124 			if ((error = CheckElfFile(dl.ldfd)) == 0) {
    125 				if (GetElfFileInfo(&dl) < 0) {
    126 					printf(
    127 					"Some failure in GetElfFileInfo\n");
    128 				}
    129 			} else if ((error = CheckAOutFile(dl.ldfd)) == 0) {
    130 				if (GetAOutFileInfo(&dl) < 0) {
    131 					printf(
    132 					"Some failure in GetAOutFileInfo\n");
    133 				}
    134 			} else if ((error = CheckMopFile(dl.ldfd)) == 0) {
    135 				if (GetMopFileInfo(&dl) < 0) {
    136 					printf(
    137 					    "Some failure in GetMopFileInfo\n");
    138 				}
    139 			}
    140 		}
    141 		(void) close(dl.ldfd);
    142 	}
    143 	return (0);
    144 }
    145 
    146 void
    147 Usage()
    148 {
    149 	(void) fprintf(stderr, "usage: %s [-a] [-v] [filename...]\n",
    150 	    getprogname());
    151 	exit(1);
    152 }
    153 
    154 /*
    155  * Process incomming packages.
    156  * Doesn't actually do anything for mopchk(1)
    157  */
    158 void
    159 mopProcess(ii, pkt)
    160 	struct if_info *ii;
    161 	u_char *pkt;
    162 {
    163 }
    164