Home | History | Annotate | Line # | Download | only in moptrace
moptrace.c revision 1.5
      1 /*	$NetBSD: moptrace.c,v 1.5 1997/10/16 23:25:28 lukem Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993-95 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: moptrace.c,v 1.5 1997/10/16 23:25:28 lukem Exp $");
     35 #endif
     36 
     37 /*
     38  * moptrace - MOP Trace Utility
     39  *
     40  * Usage:	moptrace -a [ -d ] [ -3 | -4 ]
     41  *		moptrace [ -d ] [ -3 | -4 ] interface
     42  */
     43 
     44 #include "os.h"
     45 #include "common.h"
     46 #include "device.h"
     47 #include "dl.h"
     48 #include "get.h"
     49 #include "mopdef.h"
     50 #include "pf.h"
     51 #include "print.h"
     52 #include "rc.h"
     53 
     54 /*
     55  * The list of all interfaces that are being listened to.
     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;		/* Ignore MOP V3 messages      */
     67 int	Not4Flag = 0;		/* Ignore MOP V4 messages      */
     68 int	promisc = 1;		/* Need promisc mode           */
     69 
     70 extern char *__progname;	/* from crt0.o */
     71 
     72 int
     73 main(argc, argv)
     74 	int     argc;
     75 	char  **argv;
     76 {
     77 	int     op;
     78 	char   *interface;
     79 
     80 	/* All error reporting is done through syslogs. */
     81 	openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON);
     82 
     83 	opterr = 0;
     84 	while ((op = getopt(argc, argv, "34ad")) != -1) {
     85 		switch (op) {
     86 		case '3':
     87 			Not3Flag++;
     88 			break;
     89 		case '4':
     90 			Not4Flag++;
     91 			break;
     92 		case 'a':
     93 			AllFlag++;
     94 			break;
     95 		case 'd':
     96 			DebugFlag++;
     97 			break;
     98 		default:
     99 			Usage();
    100 			/* NOTREACHED */
    101 		}
    102 	}
    103 
    104 	interface = argv[optind++];
    105 
    106 	if ((AllFlag && interface) ||
    107 	    (!AllFlag && interface == 0) ||
    108 	    (Not3Flag && Not4Flag))
    109 		Usage();
    110 
    111 	if (AllFlag)
    112  		deviceInitAll();
    113 	else
    114 		deviceInitOne(interface);
    115 
    116 	Loop();
    117 	/* NOTREACHED */
    118 	return (0);
    119 }
    120 
    121 void
    122 Usage()
    123 {
    124 	(void) fprintf(stderr, "usage: %s -a [ -d ] [ -3 | -4 ]\n", __progname);
    125 	(void) fprintf(stderr, "       %s [ -d ] [ -3 | -4 ] interface\n",
    126 		       __progname);
    127 	exit(1);
    128 }
    129 
    130 /*
    131  * Process incoming packages.
    132  */
    133 void
    134 mopProcess(ii, pkt)
    135 	struct if_info *ii;
    136 	u_char *pkt;
    137 {
    138 	int	 trans;
    139 
    140 	/* We don't known which transport, Guess! */
    141 
    142 	trans = mopGetTrans(pkt, 0);
    143 
    144 	/* Ok, return if we don't want this message */
    145 
    146 	if ((trans == TRANS_ETHER) && Not3Flag) return;
    147 	if ((trans == TRANS_8023) && Not4Flag)	return;
    148 
    149 	mopPrintHeader(stdout, pkt, trans);
    150 	mopPrintMopHeader(stdout, pkt, trans);
    151 
    152 	mopDumpDL(stdout, pkt, trans);
    153 	mopDumpRC(stdout, pkt, trans);
    154 
    155 	fprintf(stdout, "\n");
    156 	fflush(stdout);
    157 }
    158