Home | History | Annotate | Line # | Download | only in mopchk
mopchk.c revision 1.5
      1 /*	$NetBSD: mopchk.c,v 1.5 1997/10/16 07:36:50 lukem 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.5 1997/10/16 07:36:50 lukem 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 extern 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 	if ((Program = strrchr(argv[0], '/')))
     80 		Program++;
     81 	else
     82 		Program = argv[0];
     83 	if (*Program == '-')
     84 		Program++;
     85 
     86 	/* All error reporting is done through syslogs. */
     87 	openlog(Program, LOG_PID | LOG_CONS, LOG_DAEMON);
     88 
     89 	opterr = 0;
     90 	while ((op = getopt(argc, argv, "av")) != EOF) {
     91 		switch (op) {
     92 		case 'a':
     93 			AllFlag++;
     94 			break;
     95 		case 'v':
     96 			VersionFlag++;
     97 			break;
     98 		default:
     99 			Usage();
    100 			/* NOTREACHED */
    101 		}
    102 	}
    103 
    104 	if (VersionFlag)
    105 		printf("%s: Version %s\n",Program,version);
    106 
    107 	if (AllFlag) {
    108 		if (VersionFlag)
    109 			printf("\n");
    110 		iflist = NULL;
    111 		deviceInitAll();
    112 		if (iflist == NULL) {
    113 			printf("No interface\n");
    114 		} else {
    115 			printf("Interface Address\n");
    116 			for (ii = iflist; ii; ii = ii->next) {
    117 				printf("%-9s %x:%x:%x:%x:%x:%x\n",
    118 				       ii->if_name,
    119 				       ii->eaddr[0],ii->eaddr[1],ii->eaddr[2],
    120 				       ii->eaddr[3],ii->eaddr[4],ii->eaddr[5]);
    121 			}
    122 		}
    123 	}
    124 
    125 	if (VersionFlag || AllFlag)
    126 		i = 1;
    127 	else
    128 		i = 0;
    129 
    130 	while (argc > optind) {
    131 		if (i)	printf("\n");
    132 		i++;
    133 		filename = argv[optind++];
    134 		printf("Checking: %s\n",filename);
    135 		fd = open(filename, O_RDONLY, 0);
    136 		if (fd == -1) {
    137 			printf("Unknown file.\n");
    138 		} else {
    139 			err = CheckAOutFile(fd);
    140 			if (err == 0) {
    141 				if (GetAOutFileInfo(fd, 0, 0, 0, 0,
    142 						    0, 0, 0, 0, &aout) < 0) {
    143 					printf("Some failure in GetAOutFileInfo\n");
    144 					aout = -1;
    145 				}
    146 			} else {
    147 				aout = -1;
    148 			}
    149 			if (aout == -1)
    150 				err = CheckMopFile(fd);
    151 			if (aout == -1 && err == 0) {
    152 				if (GetMopFileInfo(fd, 0, 0) < 0) {
    153 					printf("Some failure in GetMopFileInfo\n");
    154 				}
    155 			};
    156 		}
    157 	}
    158 
    159 }
    160 
    161 void
    162 Usage()
    163 {
    164 	(void) fprintf(stderr, "usage: %d [-a] [-v] [filename...]\n",Program);
    165 	exit(1);
    166 }
    167 
    168 /*
    169  * Process incomming packages, NOT.
    170  */
    171 void
    172 mopProcess(ii, pkt)
    173 	struct if_info *ii;
    174 	u_char *pkt;
    175 {
    176 }
    177 
    178