+/*
+ * 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));
+}
+
+/*
+ * Return the possible subnetwork number from an internet address.
+ * If the address is of the form of a subnet address (most significant
+ * bit of the host part is set), believe the subnet exists.
+ * Otherwise, return the network number.
+ * SHOULD FIND OUT WHETHER THIS IS A LOCAL NETWORK BEFORE LOOKING
+ * INSIDE OF THE HOST PART. We can only believe this if we have other
+ * information (e.g., we can find a name for this number).
+ */
+inet_subnetof(in)
+ struct in_addr in;
+{
+ register u_long i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i)) {
+ if (IN_SUBNETA(i))
+ return ((i & IN_CLASSA_SUBNET) >> IN_CLASSA_SUBNSHIFT);
+ else
+ return ((i & IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
+ } else if (IN_CLASSB(i)) {
+ if (IN_SUBNETB(i))
+ return ((i & IN_CLASSB_SUBNET) >> IN_CLASSB_SUBNSHIFT);
+ else
+ return ((i & IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
+ } else
+ return ((i & IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
+}