*/
#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>
#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 cc, count, bits;
struct sockaddr from;
int fromlen = sizeof(from);
- struct timeval notime;
+ struct timeval shorttime;
if (argc < 2) {
usage:
}
argc--, argv++;
}
- count = argc;
while (argc > 0) {
query(*argv);
+ count++;
argv++, argc--;
}
* may be more than one packet per host.
*/
bits = 1 << s;
- bzero(¬ime, sizeof(notime));
+ bzero(&shorttime, sizeof(shorttime));
+ shorttime.tv_usec = STIME;
signal(SIGALRM, timeout);
alarm(WTIME);
while ((count > 0 && !timedout) ||
- select(20, &bits, 0, 0, ¬ime) > 0) {
+ select(20, &bits, 0, 0, &shorttime) > 0) {
cc = recvfrom(s, packet, sizeof (packet), 0,
&from, &fromlen);
if (cc <= 0) {
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;
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) {
- 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;
} 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++;
}
}