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