mopchk.c revision 1.14
1/* $OpenBSD: mopchk.c,v 1.14 2009/10/27 23:59:52 deraadt 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27/* 28 * mopchk - MOP Check Utility 29 * 30 * Usage: mopchk [-av] [file ...] 31 */ 32 33#include "os.h" 34#include "common/common.h" 35#include "common/mopdef.h" 36#include "common/device.h" 37#include "common/pf.h" 38#include "common/file.h" 39 40/* 41 * The list of all interfaces that are being listened to. 42 */ 43struct if_info *iflist; 44 45void Usage(void); 46void mopProcess(struct if_info *, u_char *); 47 48int AllFlag = 0; /* listen on "all" interfaces */ 49int VersionFlag = 0; /* Show version */ 50int promisc = 0; /* promisc mode not needed */ 51extern char *__progname; 52extern char version[]; 53 54int 55main(argc, argv) 56 int argc; 57 char **argv; 58{ 59 int op, i, fd; 60 char *filename, *p; 61 struct if_info *ii; 62 int err, aout; 63 64 /* All error reporting is done through syslogs. */ 65 openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON); 66 67 opterr = 0; 68 while ((op = getopt(argc, argv, "av")) != -1) { 69 switch (op) { 70 case 'a': 71 AllFlag++; 72 break; 73 case 'v': 74 VersionFlag++; 75 break; 76 default: 77 Usage(); 78 /* NOTREACHED */ 79 } 80 } 81 82 if (VersionFlag) 83 printf("%s: Version %s\n", __progname, version); 84 85 if (AllFlag) { 86 if (VersionFlag) 87 printf("\n"); 88 iflist = NULL; 89 deviceInitAll(); 90 if (iflist == NULL) { 91 printf("No interface\n"); 92 } else { 93 printf("Interface Address\n"); 94 p = NULL; 95 for (ii = iflist; ii; ii = ii->next) { 96 if (p != NULL) { 97 if (strcmp(p,ii->if_name) == 0) 98 continue; 99 } 100 printf("%-9s %x:%x:%x:%x:%x:%x\n", 101 ii->if_name, 102 ii->eaddr[0],ii->eaddr[1],ii->eaddr[2], 103 ii->eaddr[3],ii->eaddr[4],ii->eaddr[5]); 104 p = ii->if_name; 105 } 106 } 107 } 108 109 if (VersionFlag || AllFlag) 110 i = 1; 111 else 112 i = 0; 113 114 while (argc > optind) { 115 if (i) printf("\n"); 116 i++; 117 filename = argv[optind++]; 118 printf("Checking: %s\n",filename); 119 fd = open(filename, O_RDONLY, 0); 120 if (fd == -1) { 121 printf("Unknown file.\n"); 122 } else { 123 err = CheckAOutFile(fd); 124 if (err == 0) { 125 if (GetAOutFileInfo(fd, 0, 0, 0, 0, 0, 0, 0, 0, 126 &aout, INFO_PRINT) < 0) { 127 printf("Some failure in GetAOutFileInfo\n"); 128 aout = -1; 129 } 130 } else { 131 aout = -1; 132 } 133 if (aout == -1) 134 err = CheckMopFile(fd); 135 if (aout == -1 && err == 0) { 136 if (GetMopFileInfo(fd, 0, 0, INFO_PRINT) < 0) { 137 printf("Some failure in GetMopFileInfo\n"); 138 } 139 }; 140 } 141 } 142 return 0; 143} 144 145void 146Usage() 147{ 148 fprintf(stderr, "usage: %s [-av] [file ...]\n", __progname); 149 exit(1); 150} 151 152/* 153 * Process incomming packages, NOT. 154 */ 155/* ARGSUSED */ 156void 157mopProcess(ii, pkt) 158 struct if_info *ii; 159 u_char *pkt; 160{ 161} 162 163