1 /* $NetBSD: mopprobe.c,v 1.5 1997/10/16 23:25:24 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1993-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 #include <sys/cdefs.h> 33 #ifndef lint 34 __RCSID("$NetBSD: mopprobe.c,v 1.5 1997/10/16 23:25:24 lukem Exp $"); 35 #endif 36 37 /* 38 * mopprobe - MOP Probe Utility 39 * 40 * Usage: mopprobe -a [ -3 | -4 ] 41 * mopprobe [ -3 | -4 ] interface 42 */ 43 44 #include "os.h" 45 #include "cmp.h" 46 #include "common.h" 47 #include "device.h" 48 #include "get.h" 49 #include "mopdef.h" 50 #include "nmadef.h" 51 #include "pf.h" 52 #include "print.h" 53 54 /* 55 * The list of all interfaces that are being listened to. rarp_loop() 56 * "selects" on the descriptors in this list. 57 */ 58 struct if_info *iflist; 59 60 void Usage __P((void)); 61 int main __P((int, char **)); 62 void mopProcess __P((struct if_info *, u_char *)); 63 64 int AllFlag = 0; /* listen on "all" interfaces */ 65 int DebugFlag = 0; /* print debugging messages */ 66 int Not3Flag = 0; /* Not MOP V3 messages */ 67 int Not4Flag = 0; /* Not MOP V4 messages */ 68 int oflag = 0; /* print only once */ 69 int promisc = 1; /* Need promisc mode */ 70 71 extern char *__progname; /* from crt0.o */ 72 73 int 74 main(argc, argv) 75 int argc; 76 char **argv; 77 { 78 int op; 79 char *interface; 80 81 /* All error reporting is done through syslogs. */ 82 openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON); 83 84 opterr = 0; 85 while ((op = getopt(argc, argv, "ado")) != -1) { 86 switch (op) { 87 case '3': 88 Not3Flag++; 89 break; 90 case '4': 91 Not4Flag++; 92 break; 93 case 'a': 94 AllFlag++; 95 break; 96 case 'd': 97 DebugFlag++; 98 break; 99 case 'o': 100 oflag++; 101 break; 102 103 default: 104 Usage(); 105 /* NOTREACHED */ 106 } 107 } 108 interface = argv[optind++]; 109 110 if ((AllFlag && interface) || 111 (!AllFlag && interface == 0) || 112 (Not3Flag && Not4Flag)) 113 Usage(); 114 115 if (AllFlag) 116 deviceInitAll(); 117 else 118 deviceInitOne(interface); 119 120 Loop(); 121 /* NOTREACHED */ 122 return (0); 123 } 124 125 void 126 Usage() 127 { 128 (void) fprintf(stderr, "usage: %s -a [ -3 | -4 ]\n", __progname); 129 (void) fprintf(stderr, " %s [ -3 | -4 ] interface\n", __progname); 130 exit(1); 131 } 132 133 /* 134 * Process incomming packages. 135 */ 136 void 137 mopProcess(ii, pkt) 138 struct if_info *ii; 139 u_char *pkt; 140 { 141 u_char *dst, *src, *p, mopcode, tmpc, ilen; 142 u_short *ptype, moplen, tmps, itype, len; 143 int index, i, device, trans; 144 145 dst = pkt; 146 src = pkt+6; 147 ptype = (u_short *)(pkt+12); 148 index = 0; 149 150 if (*ptype < 1600) { 151 len = *ptype; 152 trans = TRANS_8023; 153 ptype = (u_short *)(pkt+20); 154 p = pkt+22; 155 if (Not4Flag) return; 156 } else { 157 len = 0; 158 trans = TRANS_ETHER; 159 p = pkt+14; 160 if (Not3Flag) return; 161 } 162 163 /* Ignore our own messages */ 164 165 if (mopCmpEAddr(ii->eaddr,src) == 0) { 166 return; 167 } 168 169 /* Just check multicast */ 170 171 if (mopCmpEAddr(rc_mcst,dst) != 0) { 172 return; 173 } 174 175 switch (trans) { 176 case TRANS_8023: 177 moplen = len; 178 break; 179 default: 180 moplen = mopGetShort(pkt,&index); 181 } 182 mopcode = mopGetChar(p,&index); 183 184 /* Just process System Information */ 185 186 if (mopcode != MOP_K_CODE_SID) { 187 return; 188 } 189 190 tmpc = mopGetChar(pkt,&index); /* Reserved */ 191 tmps = mopGetShort(pkt,&index); /* Receipt # */ 192 193 device = 0; /* Unknown Device */ 194 195 itype = mopGetShort(pkt,&index); 196 197 while (index < (int)(moplen + 2)) { 198 ilen = mopGetChar(pkt,&index); 199 switch (itype) { 200 case 0: 201 tmpc = mopGetChar(pkt,&index); 202 index = index + tmpc; 203 break; 204 case MOP_K_INFO_VER: 205 index = index + 3; 206 break; 207 case MOP_K_INFO_MFCT: 208 index = index + 2; 209 break; 210 case MOP_K_INFO_CNU: 211 index = index + 6; 212 break; 213 case MOP_K_INFO_RTM: 214 index = index + 2; 215 break; 216 case MOP_K_INFO_CSZ: 217 index = index + 2; 218 break; 219 case MOP_K_INFO_RSZ: 220 index = index + 2; 221 break; 222 case MOP_K_INFO_HWA: 223 index = index + 6; 224 break; 225 case MOP_K_INFO_TIME: 226 index = index + 10; 227 break; 228 case MOP_K_INFO_SOFD: 229 device = mopGetChar(pkt,&index); 230 break; 231 case MOP_K_INFO_SFID: 232 tmpc = mopGetChar(pkt,&index); 233 if ((index > 0) && (index < 17)) 234 index = index + tmpc; 235 break; 236 case MOP_K_INFO_PRTY: 237 index = index + 1; 238 break; 239 case MOP_K_INFO_DLTY: 240 index = index + 1; 241 break; 242 case MOP_K_INFO_DLBSZ: 243 index = index + 2; 244 break; 245 default: 246 if (((device = NMA_C_SOFD_LCS) || /* DECserver 100 */ 247 (device = NMA_C_SOFD_DS2) || /* DECserver 200 */ 248 (device = NMA_C_SOFD_DP2) || /* DECserver 250 */ 249 (device = NMA_C_SOFD_DS3)) && /* DECserver 300 */ 250 ((itype > 101) && (itype < 107))) 251 { 252 switch (itype) { 253 case 102: 254 index = index + ilen; 255 break; 256 case 103: 257 index = index + ilen; 258 break; 259 case 104: 260 index = index + 2; 261 break; 262 case 105: 263 (void)fprintf(stdout,"%x:%x:%x:%x:%x:%x\t", 264 src[0],src[1],src[2],src[3],src[4],src[5]); 265 for (i = 0; i < ilen; i++) { 266 (void)fprintf(stdout, "%c",pkt[index+i]); 267 } 268 index = index + ilen; 269 (void)fprintf(stdout, "\n"); 270 break; 271 case 106: 272 index = index + ilen; 273 break; 274 }; 275 } else { 276 index = index + ilen; 277 }; 278 } 279 itype = mopGetShort(pkt,&index); 280 } 281 282 } 283 284