+
+/*
+ * Return the name of the network whose address is given.
+ * The address is assumed to be that of a net or subnet, not a host.
+ */
+char *
+netname(in, mask)
+ struct in_addr in;
+ u_long mask;
+{
+ char *cp = 0;
+ static char line[50];
+ struct netent *np = 0;
+ u_long net;
+ register i;
+ int subnetshift;
+
+ in.s_addr = ntohl(in.s_addr);
+ if (!nflag && in.s_addr) {
+ if (mask == 0) {
+ if (IN_CLASSA(i)) {
+ mask = IN_CLASSA_NET;
+ subnetshift = 8;
+ } else if (IN_CLASSB(i)) {
+ mask = IN_CLASSB_NET;
+ subnetshift = 8;
+ } else {
+ mask = IN_CLASSC_NET;
+ subnetshift = 4;
+ }
+ /*
+ * If there are more bits than the standard mask
+ * would suggest, subnets must be in use.
+ * Guess at the subnet mask, assuming reasonable
+ * width subnet fields.
+ */
+ while (in.s_addr &~ mask)
+ mask = (long)mask >> subnetshift;
+ }
+ net = in.s_addr & mask;
+ while ((mask & 1) == 0)
+ mask >>= 1, net >>= 1;
+ np = getnetbyaddr(net, AF_INET);
+ if (np)
+ cp = np->n_name;
+ }
+ if (cp)
+ strcpy(line, cp);
+ else if ((in.s_addr & 0xffffff) == 0)
+ sprintf(line, "%u", C(in.s_addr >> 24));
+ else if ((in.s_addr & 0xffff) == 0)
+ sprintf(line, "%u.%u", C(in.s_addr >> 24) , C(in.s_addr >> 16));
+ else if ((in.s_addr & 0xff) == 0)
+ sprintf(line, "%u.%u.%u", C(in.s_addr >> 24),
+ C(in.s_addr >> 16), C(in.s_addr >> 8));
+ else
+ sprintf(line, "%u.%u.%u.%u", C(in.s_addr >> 24),
+ C(in.s_addr >> 16), C(in.s_addr >> 8), C(in.s_addr));
+ return (line);
+}
+
+/*
+ * Print routing statistics
+ */
+rt_stats(off)
+ off_t off;
+{
+ struct rtstat rtstat;
+
+ if (off == 0) {
+ printf("rtstat: symbol not in namelist\n");
+ return;
+ }
+ klseek(kmem, off, 0);
+ read(kmem, (char *)&rtstat, sizeof (rtstat));
+ printf("routing:\n");
+ printf("\t%d bad routing redirect%s\n",
+ rtstat.rts_badredirect, plural(rtstat.rts_badredirect));
+ printf("\t%d dynamically created route%s\n",
+ rtstat.rts_dynamic, plural(rtstat.rts_dynamic));
+ printf("\t%d new gateway%s due to redirects\n",
+ rtstat.rts_newgateway, plural(rtstat.rts_newgateway));
+ printf("\t%d destination%s found unreachable\n",
+ rtstat.rts_unreach, plural(rtstat.rts_unreach));
+ printf("\t%d use%s of a wildcard route\n",
+ rtstat.rts_wildcard, plural(rtstat.rts_wildcard));
+}
+short ns_bh[] = {-1,-1,-1};
+
+char *
+ns_print(sns)
+struct sockaddr_ns *sns;
+{
+ register struct ns_addr *dna = &sns->sns_addr;
+ long net = ntohl(ns_netof(*dna));
+ static char mybuf[50];
+ register char *p = mybuf;
+ short port = dna->x_port;
+
+ sprintf(p,"%lx:", net);
+
+ while(*p)p++; /* find end of string */
+
+ if (strncmp(ns_bh,dna->x_host.c_host,6)==0)
+ sprintf(p,"any");
+ else
+ sprintf(p,"%x.%x.%x.%x.%x.%x",
+ dna->x_host.c_host[0], dna->x_host.c_host[1],
+ dna->x_host.c_host[2], dna->x_host.c_host[3],
+ dna->x_host.c_host[4], dna->x_host.c_host[5]);
+ if (port) {
+ while(*p)p++; /* find end of string */
+ sprintf(p,":%x",ntohs(port));
+ }
+ return(mybuf);
+}
+char *
+ns_phost(sns)
+struct sockaddr_ns *sns;
+{
+ register struct ns_addr *dna = &sns->sns_addr;
+ long net = ntohl(ns_netof(*dna));
+ static char mybuf[50];
+ register char *p = mybuf;
+ if (strncmp(ns_bh,dna->x_host.c_host,6)==0)
+ sprintf(p,"any");
+ else
+ sprintf(p,"%x,%x,%x",
+ dna->x_host.s_host[0], dna->x_host.s_host[1],
+ dna->x_host.s_host[2]);
+ return(mybuf);
+}