Home | History | Annotate | Line # | Download | only in mopchk
mopchk.c revision 1.10
      1 /*	$NetBSD: mopchk.c,v 1.10 2003/04/20 00:19:56 christos 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  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Mats O Jansson.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #ifndef lint
     34 __RCSID("$NetBSD: mopchk.c,v 1.10 2003/04/20 00:19:56 christos Exp $");
     35 #endif
     36 
     37 /*
     38  * mopchk - MOP Check Utility
     39  *
     40  * Usage:	mopchk [-a] [-v] [filename...]
     41  */
     42 
     43 #include "os.h"
     44 #include "common.h"
     45 #include "device.h"
     46 #include "file.h"
     47 #include "mopdef.h"
     48 #include "pf.h"
     49 #include "log.h"
     50 
     51 /*
     52  * The list of all interfaces that are being listened to.  rarp_loop()
     53  * "selects" on the descriptors in this list.
     54  */
     55 struct if_info *iflist;
     56 
     57 void	Usage __P((void));
     58 int	main __P((int, char **));
     59 void	mopProcess __P((struct if_info *, u_char *));
     60 
     61 int     AllFlag = 0;		/* listen on "all" interfaces  */
     62 int	VersionFlag = 0;	/* Show version */
     63 int	promisc = 0;		/* promisc mode not needed */
     64 
     65 extern char	version[];
     66 
     67 int
     68 main(argc, argv)
     69 	int     argc;
     70 	char  **argv;
     71 {
     72 	struct dllist dl;
     73 	int     op, i;
     74 	char   *filename;
     75 	struct if_info *ii;
     76 	int	err;
     77 
     78 	mopInteractive = 1;
     79 
     80 	opterr = 0;
     81 	while ((op = getopt(argc, argv, "av")) != -1) {
     82 		switch (op) {
     83 		case 'a':
     84 			AllFlag++;
     85 			break;
     86 		case 'v':
     87 			VersionFlag++;
     88 			break;
     89 		default:
     90 			Usage();
     91 			/* NOTREACHED */
     92 		}
     93 	}
     94 
     95 	if (VersionFlag)
     96 		printf("%s: Version %s\n", getprogname(), version);
     97 
     98 	if (AllFlag) {
     99 		if (VersionFlag)
    100 			printf("\n");
    101 		iflist = NULL;
    102 		deviceInitAll();
    103 		if (iflist == NULL)
    104 			printf("No interface\n");
    105 		else {
    106 			printf("Interface Address\n");
    107 			for (ii = iflist; ii; ii = ii->next)
    108 				printf("%-9s %x:%x:%x:%x:%x:%x\n",
    109 				    ii->if_name, ii->eaddr[0], ii->eaddr[1],
    110 				    ii->eaddr[2], ii->eaddr[3], ii->eaddr[4],
    111 				    ii->eaddr[5]);
    112 		}
    113 	}
    114 
    115 	if (VersionFlag || AllFlag)
    116 		i = 1;
    117 	else
    118 		i = 0;
    119 
    120 	while (argc > optind) {
    121 		if (i)	printf("\n");
    122 		i++;
    123 		filename = argv[optind++];
    124 		printf("Checking: %s\n", filename);
    125 		dl.ldfd = open(filename, O_RDONLY, 0);
    126 		if (dl.ldfd == -1)
    127 			printf("Unknown file.\n");
    128 		else {
    129 			if ((err = CheckElfFile(dl.ldfd)) == 0) {
    130 				if (GetElfFileInfo(&dl) < 0) {
    131 					printf(
    132 					"Some failure in GetElfFileInfo\n");
    133 				}
    134 			} else if ((err = CheckAOutFile(dl.ldfd)) == 0) {
    135 				if (GetAOutFileInfo(&dl) < 0) {
    136 					printf(
    137 					"Some failure in GetAOutFileInfo\n");
    138 				}
    139 			} else if ((err = CheckMopFile(dl.ldfd)) == 0) {
    140 				if (GetMopFileInfo(&dl) < 0) {
    141 					printf(
    142 					    "Some failure in GetMopFileInfo\n");
    143 				}
    144 			}
    145 		}
    146 		(void) close(dl.ldfd);
    147 	}
    148 	return (0);
    149 }
    150 
    151 void
    152 Usage()
    153 {
    154 	(void) fprintf(stderr, "usage: %s [-a] [-v] [filename...]\n",
    155 	    getprogname());
    156 	exit(1);
    157 }
    158 
    159 /*
    160  * Process incomming packages.
    161  * Doesn't actually do anything for mopchk(1)
    162  */
    163 void
    164 mopProcess(ii, pkt)
    165 	struct if_info *ii;
    166 	u_char *pkt;
    167 {
    168 }
    169