Home | History | Annotate | Line # | Download | only in mopprobe
mopprobe.c revision 1.5
      1  1.5     lukem /*	$NetBSD: mopprobe.c,v 1.5 1997/10/16 23:25:24 lukem Exp $	*/
      2  1.2   thorpej 
      3  1.1       cjs /*
      4  1.1       cjs  * Copyright (c) 1993-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  * 3. All advertising materials mentioning features or use of this software
     15  1.1       cjs  *    must display the following acknowledgement:
     16  1.1       cjs  *	This product includes software developed by Mats O Jansson.
     17  1.1       cjs  * 4. The name of the author may not be used to endorse or promote products
     18  1.1       cjs  *    derived from this software without specific prior written permission.
     19  1.1       cjs  *
     20  1.1       cjs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1       cjs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1       cjs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1       cjs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1       cjs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1       cjs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1       cjs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1       cjs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1       cjs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1       cjs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1       cjs  */
     31  1.1       cjs 
     32  1.5     lukem #include <sys/cdefs.h>
     33  1.5     lukem #ifndef lint
     34  1.5     lukem __RCSID("$NetBSD: mopprobe.c,v 1.5 1997/10/16 23:25:24 lukem Exp $");
     35  1.1       cjs #endif
     36  1.1       cjs 
     37  1.1       cjs /*
     38  1.1       cjs  * mopprobe - MOP Probe Utility
     39  1.1       cjs  *
     40  1.1       cjs  * Usage:	mopprobe -a [ -3 | -4 ]
     41  1.1       cjs  *		mopprobe [ -3 | -4 ] interface
     42  1.1       cjs  */
     43  1.1       cjs 
     44  1.4  christos #include "os.h"
     45  1.5     lukem #include "cmp.h"
     46  1.5     lukem #include "common.h"
     47  1.5     lukem #include "device.h"
     48  1.5     lukem #include "get.h"
     49  1.5     lukem #include "mopdef.h"
     50  1.5     lukem #include "nmadef.h"
     51  1.5     lukem #include "pf.h"
     52  1.5     lukem #include "print.h"
     53  1.1       cjs 
     54  1.1       cjs /*
     55  1.1       cjs  * The list of all interfaces that are being listened to.  rarp_loop()
     56  1.1       cjs  * "selects" on the descriptors in this list.
     57  1.1       cjs  */
     58  1.1       cjs struct if_info *iflist;
     59  1.1       cjs 
     60  1.5     lukem void	Usage __P((void));
     61  1.5     lukem int	main __P((int, char **));
     62  1.5     lukem void	mopProcess __P((struct if_info *, u_char *));
     63  1.1       cjs 
     64  1.1       cjs int     AllFlag = 0;		/* listen on "all" interfaces  */
     65  1.1       cjs int     DebugFlag = 0;		/* print debugging messages    */
     66  1.1       cjs int	Not3Flag = 0;		/* Not MOP V3 messages         */
     67  1.1       cjs int	Not4Flag = 0;		/* Not MOP V4 messages         */
     68  1.1       cjs int     oflag = 0;		/* print only once             */
     69  1.1       cjs int	promisc = 1;		/* Need promisc mode           */
     70  1.1       cjs 
     71  1.5     lukem extern char *__progname;	/* from crt0.o */
     72  1.5     lukem 
     73  1.5     lukem int
     74  1.1       cjs main(argc, argv)
     75  1.1       cjs 	int     argc;
     76  1.1       cjs 	char  **argv;
     77  1.1       cjs {
     78  1.1       cjs 	int     op;
     79  1.1       cjs 	char   *interface;
     80  1.1       cjs 
     81  1.1       cjs 	/* All error reporting is done through syslogs. */
     82  1.5     lukem 	openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON);
     83  1.1       cjs 
     84  1.1       cjs 	opterr = 0;
     85  1.5     lukem 	while ((op = getopt(argc, argv, "ado")) != -1) {
     86  1.1       cjs 		switch (op) {
     87  1.1       cjs 		case '3':
     88  1.1       cjs 			Not3Flag++;
     89  1.1       cjs 			break;
     90  1.1       cjs 		case '4':
     91  1.1       cjs 			Not4Flag++;
     92  1.1       cjs 			break;
     93  1.1       cjs 		case 'a':
     94  1.1       cjs 			AllFlag++;
     95  1.1       cjs 			break;
     96  1.1       cjs 		case 'd':
     97  1.1       cjs 			DebugFlag++;
     98  1.1       cjs 			break;
     99  1.1       cjs 		case 'o':
    100  1.1       cjs 			oflag++;
    101  1.1       cjs 			break;
    102  1.1       cjs 
    103  1.1       cjs 		default:
    104  1.1       cjs 			Usage();
    105  1.1       cjs 			/* NOTREACHED */
    106  1.1       cjs 		}
    107  1.1       cjs 	}
    108  1.1       cjs 	interface = argv[optind++];
    109  1.1       cjs 
    110  1.1       cjs 	if ((AllFlag && interface) ||
    111  1.1       cjs 	    (!AllFlag && interface == 0) ||
    112  1.1       cjs 	    (Not3Flag && Not4Flag))
    113  1.1       cjs 		Usage();
    114  1.1       cjs 
    115  1.1       cjs 	if (AllFlag)
    116  1.1       cjs  		deviceInitAll();
    117  1.1       cjs 	else
    118  1.1       cjs 		deviceInitOne(interface);
    119  1.1       cjs 
    120  1.1       cjs 	Loop();
    121  1.5     lukem 	/* NOTREACHED */
    122  1.5     lukem 	return (0);
    123  1.1       cjs }
    124  1.1       cjs 
    125  1.1       cjs void
    126  1.1       cjs Usage()
    127  1.1       cjs {
    128  1.5     lukem 	(void) fprintf(stderr, "usage: %s -a [ -3 | -4 ]\n", __progname);
    129  1.5     lukem 	(void) fprintf(stderr, "       %s [ -3 | -4 ] interface\n", __progname);
    130  1.1       cjs 	exit(1);
    131  1.1       cjs }
    132  1.1       cjs 
    133  1.1       cjs /*
    134  1.1       cjs  * Process incomming packages.
    135  1.1       cjs  */
    136  1.1       cjs void
    137  1.1       cjs mopProcess(ii, pkt)
    138  1.1       cjs 	struct if_info *ii;
    139  1.1       cjs 	u_char *pkt;
    140  1.1       cjs {
    141  1.1       cjs 	u_char  *dst, *src, *p, mopcode, tmpc, ilen;
    142  1.1       cjs 	u_short *ptype, moplen, tmps, itype, len;
    143  1.1       cjs 	int	index, i, device, trans;
    144  1.1       cjs 
    145  1.1       cjs 	dst	= pkt;
    146  1.1       cjs 	src	= pkt+6;
    147  1.1       cjs 	ptype   = (u_short *)(pkt+12);
    148  1.1       cjs 	index   = 0;
    149  1.1       cjs 
    150  1.1       cjs 	if (*ptype < 1600) {
    151  1.1       cjs 		len = *ptype;
    152  1.1       cjs 		trans = TRANS_8023;
    153  1.1       cjs 		ptype = (u_short *)(pkt+20);
    154  1.1       cjs 		p = pkt+22;
    155  1.1       cjs 		if (Not4Flag) return;
    156  1.1       cjs 	} else {
    157  1.1       cjs 		len = 0;
    158  1.1       cjs 		trans = TRANS_ETHER;
    159  1.1       cjs 		p = pkt+14;
    160  1.1       cjs 		if (Not3Flag) return;
    161  1.1       cjs 	}
    162  1.1       cjs 
    163  1.1       cjs 	/* Ignore our own messages */
    164  1.1       cjs 
    165  1.1       cjs 	if (mopCmpEAddr(ii->eaddr,src) == 0) {
    166  1.1       cjs 		return;
    167  1.1       cjs 	}
    168  1.1       cjs 
    169  1.1       cjs 	/* Just check multicast */
    170  1.1       cjs 
    171  1.1       cjs 	if (mopCmpEAddr(rc_mcst,dst) != 0) {
    172  1.1       cjs 		return;
    173  1.1       cjs 	}
    174  1.1       cjs 
    175  1.1       cjs 	switch (trans) {
    176  1.1       cjs 	case TRANS_8023:
    177  1.1       cjs 		moplen = len;
    178  1.1       cjs 		break;
    179  1.1       cjs 	default:
    180  1.1       cjs 		moplen = mopGetShort(pkt,&index);
    181  1.1       cjs 	}
    182  1.1       cjs 	mopcode	= mopGetChar(p,&index);
    183  1.1       cjs 
    184  1.1       cjs 	/* Just process System Information */
    185  1.1       cjs 
    186  1.1       cjs 	if (mopcode != MOP_K_CODE_SID) {
    187  1.1       cjs 		return;
    188  1.1       cjs 	}
    189  1.1       cjs 
    190  1.1       cjs 	tmpc	= mopGetChar(pkt,&index);		/* Reserved  */
    191  1.1       cjs 	tmps	= mopGetShort(pkt,&index);		/* Receipt # */
    192  1.1       cjs 
    193  1.1       cjs 	device	= 0;					/* Unknown Device */
    194  1.1       cjs 
    195  1.1       cjs 	itype	= mopGetShort(pkt,&index);
    196  1.1       cjs 
    197  1.1       cjs 	while (index < (int)(moplen + 2)) {
    198  1.1       cjs 		ilen	= mopGetChar(pkt,&index);
    199  1.1       cjs 		switch (itype) {
    200  1.1       cjs 		case 0:
    201  1.1       cjs 			tmpc  = mopGetChar(pkt,&index);
    202  1.1       cjs 			index = index + tmpc;
    203  1.1       cjs 			break;
    204  1.1       cjs 	        case MOP_K_INFO_VER:
    205  1.1       cjs 			index = index + 3;
    206  1.1       cjs 			break;
    207  1.1       cjs 		case MOP_K_INFO_MFCT:
    208  1.1       cjs 			index = index + 2;
    209  1.1       cjs 			break;
    210  1.1       cjs 		case MOP_K_INFO_CNU:
    211  1.1       cjs 			index = index + 6;
    212  1.1       cjs 			break;
    213  1.1       cjs 		case MOP_K_INFO_RTM:
    214  1.1       cjs 			index = index + 2;
    215  1.1       cjs 			break;
    216  1.1       cjs 		case MOP_K_INFO_CSZ:
    217  1.1       cjs 			index = index + 2;
    218  1.1       cjs 			break;
    219  1.1       cjs 		case MOP_K_INFO_RSZ:
    220  1.1       cjs 			index = index + 2;
    221  1.1       cjs 			break;
    222  1.1       cjs 		case MOP_K_INFO_HWA:
    223  1.1       cjs 			index = index + 6;
    224  1.1       cjs 			break;
    225  1.1       cjs 		case MOP_K_INFO_TIME:
    226  1.1       cjs 			index = index + 10;
    227  1.1       cjs 			break;
    228  1.1       cjs 	        case MOP_K_INFO_SOFD:
    229  1.1       cjs 			device = mopGetChar(pkt,&index);
    230  1.1       cjs 			break;
    231  1.1       cjs 		case MOP_K_INFO_SFID:
    232  1.1       cjs 			tmpc = mopGetChar(pkt,&index);
    233  1.1       cjs 			if ((index > 0) && (index < 17))
    234  1.1       cjs 			  index = index + tmpc;
    235  1.1       cjs 			break;
    236  1.1       cjs 		case MOP_K_INFO_PRTY:
    237  1.1       cjs 			index = index + 1;
    238  1.1       cjs 			break;
    239  1.1       cjs 		case MOP_K_INFO_DLTY:
    240  1.1       cjs 			index = index + 1;
    241  1.1       cjs 			break;
    242  1.1       cjs 	        case MOP_K_INFO_DLBSZ:
    243  1.1       cjs 			index = index + 2;
    244  1.1       cjs 			break;
    245  1.1       cjs 		default:
    246  1.1       cjs 			if (((device = NMA_C_SOFD_LCS) ||   /* DECserver 100 */
    247  1.1       cjs 			     (device = NMA_C_SOFD_DS2) ||   /* DECserver 200 */
    248  1.1       cjs 			     (device = NMA_C_SOFD_DP2) ||   /* DECserver 250 */
    249  1.1       cjs 			     (device = NMA_C_SOFD_DS3)) &&  /* DECserver 300 */
    250  1.1       cjs 			    ((itype > 101) && (itype < 107)))
    251  1.1       cjs 			{
    252  1.1       cjs 				switch (itype) {
    253  1.1       cjs 				case 102:
    254  1.1       cjs 					index = index + ilen;
    255  1.1       cjs 					break;
    256  1.1       cjs 				case 103:
    257  1.1       cjs 					index = index + ilen;
    258  1.1       cjs 					break;
    259  1.1       cjs 				case 104:
    260  1.1       cjs 					index = index + 2;
    261  1.1       cjs 					break;
    262  1.1       cjs 				case 105:
    263  1.1       cjs 					(void)fprintf(stdout,"%x:%x:%x:%x:%x:%x\t",
    264  1.1       cjs 						      src[0],src[1],src[2],src[3],src[4],src[5]);
    265  1.1       cjs 					for (i = 0; i < ilen; i++) {
    266  1.1       cjs 					  (void)fprintf(stdout, "%c",pkt[index+i]);
    267  1.1       cjs 					}
    268  1.1       cjs 					index = index + ilen;
    269  1.1       cjs 					(void)fprintf(stdout, "\n");
    270  1.1       cjs 					break;
    271  1.1       cjs 				case 106:
    272  1.1       cjs 					index = index + ilen;
    273  1.1       cjs 					break;
    274  1.1       cjs 				};
    275  1.1       cjs 			} else {
    276  1.1       cjs 				index = index + ilen;
    277  1.1       cjs 			};
    278  1.1       cjs 		}
    279  1.1       cjs 		itype = mopGetShort(pkt,&index);
    280  1.1       cjs 	}
    281  1.1       cjs 
    282  1.1       cjs }
    283  1.1       cjs 
    284