moptrace.c 4.1 KB

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