Home | History | Annotate | Line # | Download | only in mopchk
mopchk.c revision 1.4
      1 /*	$NetBSD: mopchk.c,v 1.4 1997/04/17 21:09:12 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 #ifndef LINT
     33 static char rcsid[] = "$NetBSD: mopchk.c,v 1.4 1997/04/17 21:09:12 christos Exp $";
     34 #endif
     35 
     36 /*
     37  * mopchk - MOP Check Utility
     38  *
     39  * Usage:	mopchk [-a] [-v] [filename...]
     40  */
     41 
     42 #include "os.h"
     43 #include "common/common.h"
     44 #include "common/mopdef.h"
     45 #include "common/device.h"
     46 #include "common/pf.h"
     47 #include "common/file.h"
     48 
     49 /*
     50  * The list of all interfaces that are being listened to.  rarp_loop()
     51  * "selects" on the descriptors in this list.
     52  */
     53 struct if_info *iflist;
     54 
     55 #ifdef NO__P
     56 void   Usage         (/* void */);
     57 void   mopProcess    (/* struct if_info *, u_char * */);
     58 #else
     59 void   Usage         __P((void));
     60 void   mopProcess    __P((struct if_info *, u_char *));
     61 #endif
     62 
     63 int     AllFlag = 0;		/* listen on "all" interfaces  */
     64 int	VersionFlag = 0;	/* Show version */
     65 int	promisc = 0;		/* promisc mode not needed */
     66 char	*Program;
     67 char	version[];
     68 
     69 void
     70 main(argc, argv)
     71 	int     argc;
     72 	char  **argv;
     73 {
     74 	int     op, i, fd;
     75 	char   *filename;
     76 	struct if_info *ii;
     77 	int	err, aout;
     78 
     79 	extern int optind, opterr;
     80 
     81 	if ((Program = strrchr(argv[0], '/')))
     82 		Program++;
     83 	else
     84 		Program = argv[0];
     85 	if (*Program == '-')
     86 		Program++;
     87 
     88 	/* All error reporting is done through syslogs. */
     89 	openlog(Program, LOG_PID | LOG_CONS, LOG_DAEMON);
     90 
     91 	opterr = 0;
     92 	while ((op = getopt(argc, argv, "av")) != EOF) {
     93 		switch (op) {
     94 		case 'a':
     95 			AllFlag++;
     96 			break;
     97 		case 'v':
     98 			VersionFlag++;
     99 			break;
    100 		default:
    101 			Usage();
    102 			/* NOTREACHED */
    103 		}
    104 	}
    105 
    106 	if (VersionFlag)
    107 		printf("%s: Version %s\n",Program,version);
    108 
    109 	if (AllFlag) {
    110 		if (VersionFlag)
    111 			printf("\n");
    112 		iflist = NULL;
    113 		deviceInitAll();
    114 		if (iflist == NULL) {
    115 			printf("No interface\n");
    116 		} else {
    117 			printf("Interface Address\n");
    118 			for (ii = iflist; ii; ii = ii->next) {
    119 				printf("%-9s %x:%x:%x:%x:%x:%x\n",
    120 				       ii->if_name,
    121 				       ii->eaddr[0],ii->eaddr[1],ii->eaddr[2],
    122 				       ii->eaddr[3],ii->eaddr[4],ii->eaddr[5]);
    123 			}
    124 		}
    125 	}
    126 
    127 	if (VersionFlag || AllFlag)
    128 		i = 1;
    129 	else
    130 		i = 0;
    131 
    132 	while (argc > optind) {
    133 		if (i)	printf("\n");
    134 		i++;
    135 		filename = argv[optind++];
    136 		printf("Checking: %s\n",filename);
    137 		fd = open(filename, O_RDONLY, 0);
    138 		if (fd == -1) {
    139 			printf("Unknown file.\n");
    140 		} else {
    141 			err = CheckAOutFile(fd);
    142 			if (err == 0) {
    143 				if (GetAOutFileInfo(fd, 0, 0, 0, 0,
    144 						    0, 0, 0, 0, &aout) < 0) {
    145 					printf("Some failure in GetAOutFileInfo\n");
    146 					aout = -1;
    147 				}
    148 			} else {
    149 				aout = -1;
    150 			}
    151 			if (aout == -1)
    152 				err = CheckMopFile(fd);
    153 			if (aout == -1 && err == 0) {
    154 				if (GetMopFileInfo(fd, 0, 0) < 0) {
    155 					printf("Some failure in GetMopFileInfo\n");
    156 				}
    157 			};
    158 		}
    159 	}
    160 
    161 }
    162 
    163 void
    164 Usage()
    165 {
    166 	(void) fprintf(stderr, "usage: %d [-a] [-v] [filename...]\n",Program);
    167 	exit(1);
    168 }
    169 
    170 /*
    171  * Process incomming packages, NOT.
    172  */
    173 void
    174 mopProcess(ii, pkt)
    175 	struct if_info *ii;
    176 	u_char *pkt;
    177 {
    178 }
    179 
    180