mopchk.c revision 1.7
1/* $OpenBSD: mopchk.c,v 1.7 2002/06/10 21:05:25 maja 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 33static char rcsid[] = "$OpenBSD: mopchk.c,v 1.7 2002/06/10 21:05:25 maja 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 */ 53struct if_info *iflist; 54 55void Usage(void); 56void mopProcess(struct if_info *, u_char *); 57 58int AllFlag = 0; /* listen on "all" interfaces */ 59int VersionFlag = 0; /* Show version */ 60int promisc = 0; /* promisc mode not needed */ 61char *Program; 62extern char version[]; 63 64int 65main(argc, argv) 66 int argc; 67 char **argv; 68{ 69 int op, i, fd; 70 char *filename; 71 struct if_info *ii; 72 int err, aout; 73 74 extern int optind, opterr; 75 76 if ((Program = strrchr(argv[0], '/'))) 77 Program++; 78 else 79 Program = argv[0]; 80 if (*Program == '-') 81 Program++; 82 83 /* All error reporting is done through syslogs. */ 84 openlog(Program, LOG_PID | LOG_CONS, LOG_DAEMON); 85 86 opterr = 0; 87 while ((op = getopt(argc, argv, "av")) != -1) { 88 switch (op) { 89 case 'a': 90 AllFlag++; 91 break; 92 case 'v': 93 VersionFlag++; 94 break; 95 default: 96 Usage(); 97 /* NOTREACHED */ 98 } 99 } 100 101 if (VersionFlag) 102 printf("%s: Version %s\n",Program,version); 103 104 if (AllFlag) { 105 if (VersionFlag) 106 printf("\n"); 107 iflist = NULL; 108 deviceInitAll(); 109 if (iflist == NULL) { 110 printf("No interface\n"); 111 } else { 112 printf("Interface Address\n"); 113 for (ii = iflist; ii; ii = ii->next) { 114 printf("%-9s %x:%x:%x:%x:%x:%x\n", 115 ii->if_name, 116 ii->eaddr[0],ii->eaddr[1],ii->eaddr[2], 117 ii->eaddr[3],ii->eaddr[4],ii->eaddr[5]); 118 } 119 } 120 } 121 122 if (VersionFlag || AllFlag) 123 i = 1; 124 else 125 i = 0; 126 127 while (argc > optind) { 128 if (i) printf("\n"); 129 i++; 130 filename = argv[optind++]; 131 printf("Checking: %s\n",filename); 132 fd = open(filename, O_RDONLY, 0); 133 if (fd == -1) { 134 printf("Unknown file.\n"); 135 } else { 136 err = CheckAOutFile(fd); 137 if (err == 0) { 138 if (GetAOutFileInfo(fd, 0, 0, 0, 0, 139 0, 0, 0, 0, &aout) < 0) { 140 printf("Some failure in GetAOutFileInfo\n"); 141 aout = -1; 142 } 143 } else { 144 aout = -1; 145 } 146 if (aout == -1) 147 err = CheckMopFile(fd); 148 if (aout == -1 && err == 0) { 149 if (GetMopFileInfo(fd, 0, 0) < 0) { 150 printf("Some failure in GetMopFileInfo\n"); 151 } 152 }; 153 } 154 } 155 return 0; 156} 157 158void 159Usage() 160{ 161 (void) fprintf(stderr, "usage: %d [-a] [-v] [filename...]\n",Program); 162 exit(1); 163} 164 165/* 166 * Process incomming packages, NOT. 167 */ 168void 169mopProcess(ii, pkt) 170 struct if_info *ii; 171 u_char *pkt; 172{ 173} 174 175