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