add stdout tracing of all packets
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Tue, 1 Feb 1983 06:18:41 +0000 (22:18 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Tue, 1 Feb 1983 06:18:41 +0000 (22:18 -0800)
SCCS-vsn: sbin/routed/main.c 4.3
SCCS-vsn: sbin/routed/trace.h 4.2

usr/src/sbin/routed/main.c
usr/src/sbin/routed/trace.h

index 21f4c27..82fba42 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)main.c     4.2 %G%";
+static char sccsid[] = "@(#)main.c     4.3 %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -29,21 +29,6 @@ main(argc, argv)
 #endif
        
        argv0 = argv;
 #endif
        
        argv0 = argv;
-#ifndef DEBUG
-       if (fork())
-               exit(0);
-       for (cc = 0; cc < 10; cc++)
-               (void) close(cc);
-       (void) open("/", 0);
-       (void) dup2(0, 1);
-       (void) dup2(0, 2);
-       { int t = open("/dev/tty", 2);
-         if (t >= 0) {
-               ioctl(t, TIOCNOTTY, (char *)0);
-               (void) close(t);
-         }
-       }
-#endif
        sp = getservbyname("router", "udp");
        if (sp == NULL) {
                fprintf(stderr, "routed: router/udp: unknown service\n");
        sp = getservbyname("router", "udp");
        if (sp == NULL) {
                fprintf(stderr, "routed: router/udp: unknown service\n");
@@ -64,19 +49,42 @@ main(argc, argv)
 #endif
        argv++, argc--;
        while (argc > 0 && **argv == '-') {
 #endif
        argv++, argc--;
        while (argc > 0 && **argv == '-') {
-               if (!strcmp(*argv, "-s") == 0) {
+               if (strcmp(*argv, "-s") == 0) {
                        supplier = 1;
                        argv++, argc--;
                        continue;
                }
                        supplier = 1;
                        argv++, argc--;
                        continue;
                }
-               if (!strcmp(*argv, "-q") == 0) {
+               if (strcmp(*argv, "-q") == 0) {
                        supplier = 0;
                        argv++, argc--;
                        continue;
                }
                        supplier = 0;
                        argv++, argc--;
                        continue;
                }
-               fprintf(stderr, "usage: routed [ -s ] [ -q ]\n");
+               if (strcmp(*argv, "-t") == 0) {
+                       tracepackets++;
+                       argv++, argc--;
+                       continue;
+               }
+               fprintf(stderr, "usage: routed [ -s ] [ -q ] [ -t ]\n");
                exit(1);
        }
                exit(1);
        }
+#ifndef DEBUG
+       if (!tracepackets) {
+               int t;
+
+               if (fork())
+                       exit(0);
+               for (cc = 0; cc < 10; cc++)
+                       (void) close(cc);
+               (void) open("/", 0);
+               (void) dup2(0, 1);
+               (void) dup2(0, 2);
+               t = open("/dev/tty", 2);
+               if (t >= 0) {
+                       ioctl(t, TIOCNOTTY, (char *)0);
+                       (void) close(t);
+               }
+       }
+#endif
        /*
         * Any extra argument is considered
         * a tracing log file.
        /*
         * Any extra argument is considered
         * a tracing log file.
index 15880ba..0ee3ebb 100644 (file)
@@ -1,4 +1,4 @@
-/*     trace.h 4.1     83/01/11        */
+/*     trace.h 4.2     83/01/31        */
 
 /*
  * Routing table management daemon.
 
 /*
  * Routing table management daemon.
@@ -30,21 +30,27 @@ struct      ifdebug {
 /*
  * Packet tracing stuff.
  */
 /*
  * Packet tracing stuff.
  */
+int    tracepackets;           /* watch packets as they go by */
 int    tracing;                /* on/off */
 FILE   *ftrace;                /* output trace file */
 int    tracing;                /* on/off */
 FILE   *ftrace;                /* output trace file */
+
 #define        TRACE_ACTION(action, route) { \
          if (tracing) \
                traceaction(ftrace, "action", route); \
        }
 #define        TRACE_ACTION(action, route) { \
          if (tracing) \
                traceaction(ftrace, "action", route); \
        }
-#define        TRACE_INPUT(ifp, from, size) { \
+#define        TRACE_INPUT(ifp, src, size) { \
          if (tracing) { \
          if (tracing) { \
-               ifp = if_iflookup(from); \
+               ifp = if_iflookup(src); \
                if (ifp) \
                if (ifp) \
-                       trace(&ifp->int_input, from, packet, size, \
+                       trace(&ifp->int_input, src, packet, size, \
                                ifp->int_metric); \
          } \
                                ifp->int_metric); \
          } \
+         if (tracepackets) \
+               dumppacket(stdout, "from", src, packet, size); \
        }
        }
-#define        TRACE_OUTPUT(ifp, to, size) { \
+#define        TRACE_OUTPUT(ifp, dst, size) { \
          if (tracing) \
          if (tracing) \
-               trace(&ifp->int_output, to, packet, size, ifp->int_metric); \
+               trace(&ifp->int_output, dst, packet, size, ifp->int_metric); \
+         if (tracepackets) \
+               dumppacket(stdout, "to", dst, packet, size); \
        }
        }