Home | History | Annotate | Line # | Download | only in moptrace
moptrace.c revision 1.1
      1  1.1  cjs /*
      2  1.1  cjs  * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
      3  1.1  cjs  *
      4  1.1  cjs  * Redistribution and use in source and binary forms, with or without
      5  1.1  cjs  * modification, are permitted provided that the following conditions
      6  1.1  cjs  * are met:
      7  1.1  cjs  * 1. Redistributions of source code must retain the above copyright
      8  1.1  cjs  *    notice, this list of conditions and the following disclaimer.
      9  1.1  cjs  * 2. Redistributions in binary form must reproduce the above copyright
     10  1.1  cjs  *    notice, this list of conditions and the following disclaimer in the
     11  1.1  cjs  *    documentation and/or other materials provided with the distribution.
     12  1.1  cjs  * 3. All advertising materials mentioning features or use of this software
     13  1.1  cjs  *    must display the following acknowledgement:
     14  1.1  cjs  *	This product includes software developed by Mats O Jansson.
     15  1.1  cjs  * 4. The name of the author may not be used to endorse or promote products
     16  1.1  cjs  *    derived from this software without specific prior written permission.
     17  1.1  cjs  *
     18  1.1  cjs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  cjs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  cjs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  cjs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  cjs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1  cjs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  cjs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  cjs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  cjs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1  cjs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  cjs  */
     29  1.1  cjs 
     30  1.1  cjs #ifndef LINT
     31  1.1  cjs static char rcsid[] = "$Id: moptrace.c,v 1.1 1997/03/16 22:23:39 cjs Exp $";
     32  1.1  cjs #endif
     33  1.1  cjs 
     34  1.1  cjs /*
     35  1.1  cjs  * moptrace - MOP Trace Utility
     36  1.1  cjs  *
     37  1.1  cjs  * Usage:	moptrace -a [ -d ] [ -3 | -4 ]
     38  1.1  cjs  *		moptrace [ -d ] [ -3 | -4 ] interface
     39  1.1  cjs  */
     40  1.1  cjs 
     41  1.1  cjs #include "os.h"
     42  1.1  cjs #include "common/common.h"
     43  1.1  cjs #include "common/mopdef.h"
     44  1.1  cjs #include "common/device.h"
     45  1.1  cjs #include "common/print.h"
     46  1.1  cjs #include "common/pf.h"
     47  1.1  cjs #include "common/dl.h"
     48  1.1  cjs #include "common/rc.h"
     49  1.1  cjs #include "common/get.h"
     50  1.1  cjs 
     51  1.1  cjs /*
     52  1.1  cjs  * The list of all interfaces that are being listened to.
     53  1.1  cjs  * "selects" on the descriptors in this list.
     54  1.1  cjs  */
     55  1.1  cjs struct if_info *iflist;
     56  1.1  cjs 
     57  1.1  cjs #ifdef NO__P
     58  1.1  cjs void   Loop	     (/* void */);
     59  1.1  cjs void   Usage         (/* void */);
     60  1.1  cjs void   mopProcess    (/* struct if_info *, u_char * */);
     61  1.1  cjs #else
     62  1.1  cjs void   Loop	     __P((void));
     63  1.1  cjs void   Usage         __P((void));
     64  1.1  cjs void   mopProcess    __P((struct if_info *, u_char *));
     65  1.1  cjs #endif
     66  1.1  cjs 
     67  1.1  cjs int     AllFlag = 0;		/* listen on "all" interfaces  */
     68  1.1  cjs int     DebugFlag = 0;		/* print debugging messages    */
     69  1.1  cjs int	Not3Flag = 0;		/* Ignore MOP V3 messages      */
     70  1.1  cjs int	Not4Flag = 0;		/* Ignore MOP V4 messages      */
     71  1.1  cjs int	promisc = 1;		/* Need promisc mode           */
     72  1.1  cjs char	*Program;
     73  1.1  cjs 
     74  1.1  cjs void
     75  1.1  cjs main(argc, argv)
     76  1.1  cjs 	int     argc;
     77  1.1  cjs 	char  **argv;
     78  1.1  cjs {
     79  1.1  cjs 	int     op;
     80  1.1  cjs 	char   *interface;
     81  1.1  cjs 
     82  1.1  cjs 	extern int optind, opterr;
     83  1.1  cjs 
     84  1.1  cjs 	if ((Program = strrchr(argv[0], '/')))
     85  1.1  cjs 		Program++;
     86  1.1  cjs 	else
     87  1.1  cjs 		Program = argv[0];
     88  1.1  cjs 
     89  1.1  cjs 	if (*Program == '-')
     90  1.1  cjs 		Program++;
     91  1.1  cjs 
     92  1.1  cjs 	/* All error reporting is done through syslogs. */
     93  1.1  cjs 	openlog(Program, LOG_PID | LOG_CONS, LOG_DAEMON);
     94  1.1  cjs 
     95  1.1  cjs 	opterr = 0;
     96  1.1  cjs 	while ((op = getopt(argc, argv, "34ad")) != EOF) {
     97  1.1  cjs 		switch (op) {
     98  1.1  cjs 		case '3':
     99  1.1  cjs 			Not3Flag++;
    100  1.1  cjs 			break;
    101  1.1  cjs 		case '4':
    102  1.1  cjs 			Not4Flag++;
    103  1.1  cjs 			break;
    104  1.1  cjs 		case 'a':
    105  1.1  cjs 			AllFlag++;
    106  1.1  cjs 			break;
    107  1.1  cjs 		case 'd':
    108  1.1  cjs 			DebugFlag++;
    109  1.1  cjs 			break;
    110  1.1  cjs 		default:
    111  1.1  cjs 			Usage();
    112  1.1  cjs 			/* NOTREACHED */
    113  1.1  cjs 		}
    114  1.1  cjs 	}
    115  1.1  cjs 
    116  1.1  cjs 	interface = argv[optind++];
    117  1.1  cjs 
    118  1.1  cjs 	if ((AllFlag && interface) ||
    119  1.1  cjs 	    (!AllFlag && interface == 0) ||
    120  1.1  cjs 	    (Not3Flag && Not4Flag))
    121  1.1  cjs 		Usage();
    122  1.1  cjs 
    123  1.1  cjs 	if (AllFlag)
    124  1.1  cjs  		deviceInitAll();
    125  1.1  cjs 	else
    126  1.1  cjs 		deviceInitOne(interface);
    127  1.1  cjs 
    128  1.1  cjs 	Loop();
    129  1.1  cjs }
    130  1.1  cjs 
    131  1.1  cjs void
    132  1.1  cjs Usage()
    133  1.1  cjs {
    134  1.1  cjs 	(void) fprintf(stderr, "usage: %s -a [ -d ] [ -3 | -4 ]\n",Program);
    135  1.1  cjs 	(void) fprintf(stderr, "       %s [ -d ] [ -3 | -4 ] interface\n",
    136  1.1  cjs 		       Program);
    137  1.1  cjs 	exit(1);
    138  1.1  cjs }
    139  1.1  cjs 
    140  1.1  cjs /*
    141  1.1  cjs  * Process incoming packages.
    142  1.1  cjs  */
    143  1.1  cjs void
    144  1.1  cjs mopProcess(ii, pkt)
    145  1.1  cjs 	struct if_info *ii;
    146  1.1  cjs 	u_char *pkt;
    147  1.1  cjs {
    148  1.1  cjs 	int	 trans;
    149  1.1  cjs 
    150  1.1  cjs 	/* We don't known which transport, Guess! */
    151  1.1  cjs 
    152  1.1  cjs 	trans = mopGetTrans(pkt, 0);
    153  1.1  cjs 
    154  1.1  cjs 	/* Ok, return if we don't want this message */
    155  1.1  cjs 
    156  1.1  cjs 	if ((trans == TRANS_ETHER) && Not3Flag) return;
    157  1.1  cjs 	if ((trans == TRANS_8023) && Not4Flag)	return;
    158  1.1  cjs 
    159  1.1  cjs 	mopPrintHeader(stdout, pkt, trans);
    160  1.1  cjs 	mopPrintMopHeader(stdout, pkt, trans);
    161  1.1  cjs 
    162  1.1  cjs 	mopDumpDL(stdout, pkt, trans);
    163  1.1  cjs 	mopDumpRC(stdout, pkt, trans);
    164  1.1  cjs 
    165  1.1  cjs 	fprintf(stdout, "\n");
    166  1.1  cjs 	fflush(stdout);
    167  1.1  cjs }
    168  1.1  cjs 
    169  1.1  cjs 
    170