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