Home | History | Annotate | Line # | Download | only in mopchk
mopchk.c revision 1.1
      1 /*
      2  * Copyright (c) 1995-96 Mats O Jansson.  All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  * 3. All advertising materials mentioning features or use of this software
     13  *    must display the following acknowledgement:
     14  *	This product includes software developed by Mats O Jansson.
     15  * 4. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #ifndef LINT
     31 static char rcsid[] = "$Id: mopchk.c,v 1.1 1997/03/16 22:23:38 cjs Exp $";
     32 #endif
     33 
     34 /*
     35  * mopchk - MOP Check Utility
     36  *
     37  * Usage:	mopchk [-a] [-v] [filename...]
     38  */
     39 
     40 #include "os.h"
     41 #include "common/common.h"
     42 #include "common/mopdef.h"
     43 #include "common/device.h"
     44 #include "common/pf.h"
     45 #include "common/file.h"
     46 
     47 /*
     48  * The list of all interfaces that are being listened to.  rarp_loop()
     49  * "selects" on the descriptors in this list.
     50  */
     51 struct if_info *iflist;
     52 
     53 #ifdef NO__P
     54 void   Usage         (/* void */);
     55 void   mopProcess    (/* struct if_info *, u_char * */);
     56 #else
     57 void   Usage         __P((void));
     58 void   mopProcess    __P((struct if_info *, u_char *));
     59 #endif
     60 
     61 int     AllFlag = 0;		/* listen on "all" interfaces  */
     62 int	VersionFlag = 0;	/* Show version */
     63 int	promisc = 0;		/* promisc mode not needed */
     64 char	*Program;
     65 char	version[];
     66 
     67 void
     68 main(argc, argv)
     69 	int     argc;
     70 	char  **argv;
     71 {
     72 	int     op, i, fd;
     73 	char   *filename;
     74 	struct if_info *ii;
     75 	int	err, aout;
     76 
     77 	extern int optind, opterr;
     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