|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)route.c 4.6 83/05/30"; ! 3: #endif ! 4: ! 5: #include <sys/types.h> ! 6: #include <sys/socket.h> ! 7: #include <sys/mbuf.h> ! 8: ! 9: #include <net/if.h> ! 10: #define KERNEL /* to get routehash and RTHASHSIZ */ ! 11: #include <net/route.h> ! 12: #include <netinet/in.h> ! 13: ! 14: #include <netdb.h> ! 15: ! 16: extern int kmem; ! 17: extern int nflag; ! 18: extern char *routename(); ! 19: ! 20: /* ! 21: * Definitions for showing gateway flags. ! 22: */ ! 23: struct bits { ! 24: short b_mask; ! 25: char b_val; ! 26: } bits[] = { ! 27: { RTF_UP, 'U' }, ! 28: { RTF_GATEWAY, 'G' }, ! 29: { RTF_HOST, 'H' }, ! 30: { 0 } ! 31: }; ! 32: ! 33: /* ! 34: * Print routing tables. ! 35: */ ! 36: routepr(hostaddr, netaddr) ! 37: off_t hostaddr, netaddr; ! 38: { ! 39: struct mbuf mb; ! 40: register struct rtentry *rt; ! 41: register struct mbuf *m; ! 42: register struct bits *p; ! 43: struct netent *np; ! 44: struct hostent *hp; ! 45: char name[16], *flags; ! 46: struct mbuf *routehash[RTHASHSIZ]; ! 47: struct ifnet ifnet; ! 48: int first = 1, i, doinghost = 1; ! 49: ! 50: if (hostaddr == 0) { ! 51: printf("rthost: symbol not in namelist\n"); ! 52: return; ! 53: } ! 54: if (netaddr == 0) { ! 55: printf("rtnet: symbol not in namelist\n"); ! 56: return; ! 57: } ! 58: klseek(kmem, hostaddr, 0); ! 59: read(kmem, routehash, sizeof (routehash)); ! 60: printf("Routing tables\n"); ! 61: printf("%-15.15s %-15.15s %-8.8s %-6.6s %-10.10s %s\n", ! 62: "Destination", "Gateway", ! 63: "Flags", "Refcnt", "Use", "Interface"); ! 64: again: ! 65: for (i = 0; i < RTHASHSIZ; i++) { ! 66: if (routehash[i] == 0) ! 67: continue; ! 68: m = routehash[i]; ! 69: while (m) { ! 70: struct sockaddr_in *sin; ! 71: ! 72: klseek(kmem, m, 0); ! 73: read(kmem, &mb, sizeof (mb)); ! 74: rt = mtod(&mb, struct rtentry *); ! 75: sin = (struct sockaddr_in *)&rt->rt_dst; ! 76: printf("%-15.15s ", ! 77: sin->sin_addr.s_addr ? ! 78: routename(sin->sin_addr) : "default"); ! 79: sin = (struct sockaddr_in *)&rt->rt_gateway; ! 80: printf("%-15.15s ", routename(sin->sin_addr)); ! 81: for (flags = name, p = bits; p->b_mask; p++) ! 82: if (p->b_mask & rt->rt_flags) ! 83: *flags++ = p->b_val; ! 84: *flags = '\0'; ! 85: printf("%-8.8s %-6d %-10d ", name, ! 86: rt->rt_refcnt, rt->rt_use); ! 87: if (rt->rt_ifp == 0) { ! 88: putchar('\n'); ! 89: m = mb.m_next; ! 90: continue; ! 91: } ! 92: klseek(kmem, rt->rt_ifp, 0); ! 93: read(kmem, &ifnet, sizeof (ifnet)); ! 94: klseek(kmem, (int)ifnet.if_name, 0); ! 95: read(kmem, name, 16); ! 96: printf("%s%d\n", name, ifnet.if_unit); ! 97: m = mb.m_next; ! 98: } ! 99: } ! 100: if (doinghost) { ! 101: klseek(kmem, netaddr, 0); ! 102: read(kmem, routehash, sizeof (routehash)); ! 103: doinghost = 0; ! 104: goto again; ! 105: } ! 106: } ! 107: ! 108: char * ! 109: routename(in) ! 110: struct in_addr in; ! 111: { ! 112: char *cp = 0; ! 113: static char line[50]; ! 114: int lna, net; ! 115: ! 116: net = inet_netof(in); ! 117: lna = inet_lnaof(in); ! 118: if (!nflag) { ! 119: if (lna == INADDR_ANY) { ! 120: struct netent *np = getnetbyaddr(net, AF_INET); ! 121: ! 122: if (np) ! 123: cp = np->n_name; ! 124: } else { ! 125: struct hostent *hp; ! 126: ! 127: hp = gethostbyaddr(&in, sizeof (struct in_addr), ! 128: AF_INET); ! 129: if (hp) ! 130: cp = hp->h_name; ! 131: } ! 132: } ! 133: if (cp) ! 134: strcpy(line, cp); ! 135: else { ! 136: u_char *ucp = (u_char *)∈ ! 137: if (lna == INADDR_ANY) ! 138: sprintf(line, "%u.%u.%u", ucp[0], ucp[1], ucp[2]); ! 139: else ! 140: sprintf(line, "%u.%u.%u.%u", ucp[0], ucp[1], ! 141: ucp[2], ucp[3]); ! 142: } ! 143: return (line); ! 144: } ! 145: ! 146: /* ! 147: * Print routing statistics ! 148: */ ! 149: rt_stats(off) ! 150: off_t off; ! 151: { ! 152: struct rtstat rtstat; ! 153: ! 154: if (off == 0) { ! 155: printf("rtstat: symbol not in namelist\n"); ! 156: return; ! 157: } ! 158: klseek(kmem, off, 0); ! 159: read(kmem, (char *)&rtstat, sizeof (rtstat)); ! 160: printf("routing:\n"); ! 161: printf("\t%d bad routing redirect%s\n", ! 162: rtstat.rts_badredirect, plural(rtstat.rts_badredirect)); ! 163: printf("\t%d dynamically created route%s\n", ! 164: rtstat.rts_dynamic, plural(rtstat.rts_dynamic)); ! 165: printf("\t%d new gateway%s due to redirects\n", ! 166: rtstat.rts_newgateway, plural(rtstat.rts_newgateway)); ! 167: printf("\t%d destination%s found unreachable\n", ! 168: rtstat.rts_unreach, plural(rtstat.rts_unreach)); ! 169: printf("\t%d use%s of a wildcard route\n", ! 170: rtstat.rts_wildcard, plural(rtstat.rts_wildcard)); ! 171: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.