delay deletion from internal tables when cur router deletes
[unix-history] / usr / src / sbin / routed / query / query.c
index 17eac42..fe7adc3 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)query.c    5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)query.c    5.7 (Berkeley) %G%";
 #endif not lint
 
 #include <sys/param.h>
 #endif not lint
 
 #include <sys/param.h>
@@ -18,7 +18,8 @@ static char sccsid[] = "@(#)query.c   5.5 (Berkeley) %G%";
 #include <netdb.h>
 #include <protocols/routed.h>
 
 #include <netdb.h>
 #include <protocols/routed.h>
 
-#define        WTIME   5               /* Time to wait for responses */
+#define        WTIME   5               /* Time to wait for all responses */
+#define        STIME   500000          /* usec to wait for another response */
 
 int    s;
 int    timedout, timeout();
 
 int    s;
 int    timedout, timeout();
@@ -33,7 +34,7 @@ main(argc, argv)
        int cc, count, bits;
        struct sockaddr from;
        int fromlen = sizeof(from);
        int cc, count, bits;
        struct sockaddr from;
        int fromlen = sizeof(from);
-       struct timeval notime;
+       struct timeval shorttime;
        
        if (argc < 2) {
 usage:
        
        if (argc < 2) {
 usage:
@@ -57,9 +58,9 @@ usage:
                }
                argc--, argv++;
        }
                }
                argc--, argv++;
        }
-       count = argc;
        while (argc > 0) {
                query(*argv);
        while (argc > 0) {
                query(*argv);
+               count++;
                argv++, argc--;
        }
 
                argv++, argc--;
        }
 
@@ -68,11 +69,12 @@ usage:
         * may be more than one packet per host.
         */
        bits = 1 << s;
         * may be more than one packet per host.
         */
        bits = 1 << s;
-       bzero(&notime, sizeof(notime));
+       bzero(&shorttime, sizeof(shorttime));
+       shorttime.tv_usec = STIME;
        signal(SIGALRM, timeout);
        alarm(WTIME);
        while ((count > 0 && !timedout) ||
        signal(SIGALRM, timeout);
        alarm(WTIME);
        while ((count > 0 && !timedout) ||
-           select(20, &bits, 0, 0, &notime) > 0) {
+           select(20, &bits, 0, 0, &shorttime) > 0) {
                cc = recvfrom(s, packet, sizeof (packet), 0,
                  &from, &fromlen);
                if (cc <= 0) {
                cc = recvfrom(s, packet, sizeof (packet), 0,
                  &from, &fromlen);
                if (cc <= 0) {
@@ -132,7 +134,7 @@ rip_input(from, size)
        int size;
 {
        register struct rip *msg = (struct rip *)packet;
        int size;
 {
        register struct rip *msg = (struct rip *)packet;
-       struct netinfo *n;
+       register struct netinfo *n;
        char *name;
        int lna, net, subnet;
        struct hostent *hp;
        char *name;
        int lna, net, subnet;
        struct hostent *hp;
@@ -152,22 +154,27 @@ rip_input(from, size)
        size -= sizeof (int);
        n = msg->rip_nets;
        while (size > 0) {
        size -= sizeof (int);
        n = msg->rip_nets;
        while (size > 0) {
-               register struct sockaddr_in *sin;
+           if (size < sizeof (struct netinfo))
+                   break;
+           if (msg->rip_vers > 0) {
+                   n->rip_dst.sa_family =
+                           ntohs(n->rip_dst.sa_family);
+                   n->rip_metric = ntohl(n->rip_metric);
+           }
+           switch (n->rip_dst.sa_family) {
+
+           case AF_INET:
+               { register struct sockaddr_in *sin;
 
 
-               if (size < sizeof (struct netinfo))
-                       break;
-               if (msg->rip_vers > 0) {
-                       n->rip_dst.sa_family =
-                               ntohs(n->rip_dst.sa_family);
-                       n->rip_metric = ntohl(n->rip_metric);
-               }
                sin = (struct sockaddr_in *)&n->rip_dst;
                net = inet_netof(sin->sin_addr);
                subnet = inet_subnetof(sin->sin_addr);
                lna = inet_lnaof(sin->sin_addr);
                name = "???";
                if (!nflag) {
                sin = (struct sockaddr_in *)&n->rip_dst;
                net = inet_netof(sin->sin_addr);
                subnet = inet_subnetof(sin->sin_addr);
                lna = inet_lnaof(sin->sin_addr);
                name = "???";
                if (!nflag) {
-                       if (lna == INADDR_ANY) {
+                       if (sin->sin_addr.s_addr == 0)
+                               name = "default";
+                       else if (lna == INADDR_ANY) {
                                np = getnetbyaddr(net, AF_INET);
                                if (np)
                                        name = np->n_name;
                                np = getnetbyaddr(net, AF_INET);
                                if (np)
                                        name = np->n_name;
@@ -195,7 +202,21 @@ rip_input(from, size)
                } else
                        printf("\t%s, metric %d\n",
                                inet_ntoa(sin->sin_addr), n->rip_metric);
                } else
                        printf("\t%s, metric %d\n",
                                inet_ntoa(sin->sin_addr), n->rip_metric);
-               size -= sizeof (struct netinfo), n++;
+               break;
+               }
+
+           default:
+               { u_short *p = (u_short *)n->rip_dst.sa_data;
+
+               printf("\t(af %d) %x %x %x %x %x %x %x, metric %d\n",
+                   p[0], p[1], p[2], p[3], p[4], p[5], p[6],
+                   n->rip_dst.sa_family,
+                   n->rip_metric);
+               break;
+               }
+                       
+           }
+           size -= sizeof (struct netinfo), n++;
        }
 }
 
        }
 }