X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/ed06dc421f25110ac09976d941bda546e23594c3..23c416d72c5edfbbee1f873bd3acf490546ec770:/usr/src/usr.sbin/trpt/trpt.c diff --git a/usr/src/usr.sbin/trpt/trpt.c b/usr/src/usr.sbin/trpt/trpt.c index 1bad807733..a34543a19c 100644 --- a/usr/src/usr.sbin/trpt/trpt.c +++ b/usr/src/usr.sbin/trpt/trpt.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)trpt.c 4.5 83/01/18"; +static char sccsid[] = "@(#)trpt.c 4.10 %G%"; #endif #include @@ -33,35 +33,56 @@ static char sccsid[] = "@(#)trpt.c 4.5 83/01/18"; n_time ntime; int sflag; +int tflag; +int jflag; +int aflag; +int numeric(); struct nlist nl[] = { { "_tcp_debug" }, { "_tcp_debx" }, 0 }; struct tcp_debug tcp_debug[TCP_NDEBUG]; +caddr_t tcp_pcbs[TCP_NDEBUG]; int tcp_debx; +char *ntoa(); main(argc, argv) int argc; char **argv; { - int i, mask = 0; - caddr_t tcpcb = 0; + int i, mask = 0, npcbs = 0; char *system = "/vmunix", *core = "/dev/kmem"; argc--, argv++; again: + if (argc > 0 && !strcmp(*argv, "-a")) { + aflag++, argc--, argv++; + goto again; + } if (argc > 0 && !strcmp(*argv, "-s")) { sflag++, argc--, argv++; goto again; } + if (argc > 0 && !strcmp(*argv, "-t")) { + tflag++, argc--, argv++; + goto again; + } + if (argc > 0 && !strcmp(*argv, "-j")) { + jflag++, argc--, argv++; + goto again; + } if (argc > 0 && !strcmp(*argv, "-p")) { + argc--, argv++; if (argc < 1) { fprintf(stderr, "-p: missing tcpcb address\n"); exit(1); } - argc--, argv++; - sscanf(*argv, "%x", &tcpcb); + if (npcbs >= TCP_NDEBUG) { + fprintf(stderr, "-p: too many pcb's specified\n"); + exit(1); + } + sscanf(*argv, "%x", &tcp_pcbs[npcbs++]); argc--, argv++; goto again; } @@ -100,25 +121,67 @@ again: fprintf(stderr, "trpt: "); perror("tcp_debug"); exit(3); } - for (i = tcp_debx % TCP_NDEBUG; i < TCP_NDEBUG; i++) { - struct tcp_debug *td = &tcp_debug[i]; + /* + * If no control blocks have been specified, figure + * out how many distinct one we have and summarize + * them in tcp_pcbs for sorting the trace records + * below. + */ + if (npcbs == 0) { + for (i = 0; i < TCP_NDEBUG; i++) { + register int j; + register struct tcp_debug *td = &tcp_debug[i]; + + if (td->td_tcb == 0) + continue; + for (j = 0; j < npcbs; j++) + if (tcp_pcbs[j] == td->td_tcb) + break; + if (j >= npcbs) + tcp_pcbs[npcbs++] = td->td_tcb; + } + } + qsort(tcp_pcbs, npcbs, sizeof (caddr_t), numeric); + if (jflag) { + char *cp = ""; + + for (i = 0; i < npcbs; i++) { + printf("%s%x", cp, tcp_pcbs[i]); + cp = ", "; + } + if (*cp) + putchar('\n'); + exit(0); + } + for (i = 0; i < npcbs; i++) { + printf("\n%x:\n", tcp_pcbs[i]); + dotrace(tcp_pcbs[i]); + } + exit(0); +} +dotrace(tcpcb) + register caddr_t tcpcb; +{ + register int i; + register struct tcp_debug *td; + + for (i = 0; i < tcp_debx % TCP_NDEBUG; i++) { + td = &tcp_debug[i]; if (tcpcb && td->td_tcb != tcpcb) continue; ntime = ntohl(td->td_time); tcp_trace(td->td_act, td->td_ostate, td->td_tcb, &td->td_cb, &td->td_ti, td->td_req); } - for (i = 0; i < tcp_debx % TCP_NDEBUG; i++) { - struct tcp_debug *td = &tcp_debug[i]; - + for (i = tcp_debx % TCP_NDEBUG; i < TCP_NDEBUG; i++) { + td = &tcp_debug[i]; if (tcpcb && td->td_tcb != tcpcb) continue; ntime = ntohl(td->td_time); tcp_trace(td->td_act, td->td_ostate, td->td_tcb, &td->td_cb, &td->td_ti, td->td_req); } - exit(0); } /* @@ -135,12 +198,18 @@ tcp_trace(act, ostate, atp, tp, ti, req) char *cp; ptime(ntime); - printf("%x %s:%s ", ((int)atp)&0xfffff, - tcpstates[ostate], tanames[act]); + printf("%s:%s ", tcpstates[ostate], tanames[act]); switch (act) { case TA_INPUT: case TA_OUTPUT: + case TA_DROP: + if (aflag) { + printf("(src=%s,%d, ", ntoa(ti->ti_src), + ntohs(ti->ti_sport)); + printf("dst=%s,%d)", ntoa(ti->ti_dst), + ntohs(ti->ti_dport)); + } seq = ti->ti_seq; ack = ti->ti_ack; len = ti->ti_len; @@ -159,7 +228,7 @@ tcp_trace(act, ostate, atp, tp, ti, req) printf("%x", seq); printf("@%x", ack); if (win) - printf("(win=%d)", win); + printf("(win=%x)", win); flags = ti->ti_flags; if (flags) { char *cp = "<"; @@ -181,12 +250,28 @@ tcp_trace(act, ostate, atp, tp, ti, req) /* print out internal state of tp !?! */ printf("\n"); if (sflag) { - printf("\trcv_nxt %x rcv_wnd %d snd_una %x snd_nxt %x snd_max %x\n", + printf("\trcv_nxt %x rcv_wnd %x snd_una %x snd_nxt %x snd_max %x\n", tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt, tp->snd_max); printf("\tsnd_wl1 %x snd_wl2 %x snd_wnd %x\n", tp->snd_wl1, tp->snd_wl2, tp->snd_wnd); } + /* print out timers? */ + if (tflag) { + char *cp = "\t"; + register int i; + + for (i = 0; i < TCPT_NTIMERS; i++) { + if (tp->t_timer[i] == 0) + continue; + printf("%s%s=%d", cp, tcptimers[i], tp->t_timer[i]); + if (i == TCPT_REXMT) + printf(" (t_rxtshft=%d)", tp->t_rxtshift); + cp = ", "; + } + if (*cp != '\t') + putchar('\n'); + } } ptime(ms) @@ -195,3 +280,28 @@ ptime(ms) printf("%03d ", (ms/10) % 1000); } + +numeric(c1, c2) + caddr_t *c1, *c2; +{ + + return (*c1 - *c2); +} + +/* + * Convert network-format internet address + * to base 256 d.d.d.d representation. + */ +char * +ntoa(in) + struct in_addr in; +{ + static char b[18]; + register char *p; + + in.s_addr = ntohl(in.s_addr); + p = (char *)∈ +#define UC(b) (((int)b)&0xff) + sprintf(b, "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); + return (b); +}