Home | History | Annotate | Line # | Download | only in moptrace
moptrace.c revision 1.8
      1 /*	$NetBSD: moptrace.c,v 1.8 2003/04/20 00:19:05 christos 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.8 2003/04/20 00:19:05 christos 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 int
     71 main(argc, argv)
     72 	int     argc;
     73 	char  **argv;
     74 {
     75 	int     op;
     76 	char   *interface;
     77 
     78 	mopInteractive = 1;
     79 	opterr = 0;
     80 	while ((op = getopt(argc, argv, "34ad")) != -1) {
     81 		switch (op) {
     82 		case '3':
     83 			Not3Flag++;
     84 			break;
     85 		case '4':
     86 			Not4Flag++;
     87 			break;
     88 		case 'a':
     89 			AllFlag++;
     90 			break;
     91 		case 'd':
     92 			DebugFlag++;
     93 			break;
     94 		default:
     95 			Usage();
     96 			/* NOTREACHED */
     97 		}
     98 	}
     99 
    100 	interface = argv[optind++];
    101 
    102 	if ((AllFlag && interface) ||
    103 	    (!AllFlag && interface == 0) ||
    104 	    (Not3Flag && Not4Flag))
    105 		Usage();
    106 
    107 	if (AllFlag)
    108  		deviceInitAll();
    109 	else
    110 		deviceInitOne(interface);
    111 
    112 	Loop();
    113 	/* NOTREACHED */
    114 	return (0);
    115 }
    116 
    117 void
    118 Usage()
    119 {
    120 	(void) fprintf(stderr, "usage: %s -a [ -d ] [ -3 | -4 ]\n",
    121 		       getprogname());
    122 	(void) fprintf(stderr, "       %s [ -d ] [ -3 | -4 ] interface\n",
    123 		       getprogname());
    124 	exit(1);
    125 }
    126 
    127 /*
    128  * Process incoming packages.
    129  */
    130 void
    131 mopProcess(ii, pkt)
    132 	struct if_info *ii;
    133 	u_char *pkt;
    134 {
    135 	int	 trans;
    136 
    137 	/* We don't known which transport, Guess! */
    138 
    139 	trans = mopGetTrans(pkt, 0);
    140 
    141 	/* Ok, return if we don't want this message */
    142 
    143 	if ((trans == TRANS_ETHER) && Not3Flag) return;
    144 	if ((trans == TRANS_8023) && Not4Flag)	return;
    145 
    146 	mopPrintHeader(stdout, pkt, trans);
    147 	mopPrintMopHeader(stdout, pkt, trans);
    148 
    149 	mopDumpDL(stdout, pkt, trans);
    150 	mopDumpRC(stdout, pkt, trans);
    151 
    152 	fprintf(stdout, "\n");
    153 	fflush(stdout);
    154 }
    155