From: Bill Joy Date: Sat, 3 Apr 1982 01:29:14 +0000 (-0800) Subject: date and time created 82/04/02 10:29:14 by wnj X-Git-Tag: BSD-4_1c_2-Snapshot-Development~3691 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/9a3a7863a8cbf0bb84f892cbd0e2ef624e8fc8a1 date and time created 82/04/02 10:29:14 by wnj SCCS-vsn: usr.sbin/trpt/trpt.c 4.1 --- diff --git a/usr/src/usr.sbin/trpt/trpt.c b/usr/src/usr.sbin/trpt/trpt.c new file mode 100644 index 0000000000..a050c4a8a4 --- /dev/null +++ b/usr/src/usr.sbin/trpt/trpt.c @@ -0,0 +1,161 @@ +#ifndef lint +static char sccsid[] = "@(#)trpt.c 4.1 82/04/02"; +#endif + +#include +#include +#include +#define PRUREQUESTS +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define TCPSTATES +#include +#include +#define TCPTIMERS +#include +#include +#include +#define TANAMES +#include +#include + +#include + +n_time ntime; +int sflag; +struct nlist nl[] = { + { "_tcp_debug" }, + { "_tcp_debx" }, + 0 +}; +struct tcp_debug tcp_debug[TCP_NDEBUG]; +int tcp_debx; + +main(argc, argv) + int argc; + char **argv; +{ + int i; + + argc--, argv++; +again: + if (argc > 0 && !strcmp(*argv, "-s")) { + sflag++, argc--, argv++; + goto again; + } + nlist(argc > 0 ? *argv : "/vmunix", nl); + if (nl[0].n_value == 0) { + printf("no namelist\n"); + exit(1); + } + close(0); + open(argc > 1 ? argv[1] : "/dev/kmem", 0); + if (argc > 1) { + nl[0].n_value &= 0x7fffffff; + nl[1].n_value &= 0x7fffffff; + } + lseek(0, nl[1].n_value, 0); + read(0, &tcp_debx, sizeof (tcp_debx)); + printf("tcp_debx=%d\n", tcp_debx); + lseek(0, nl[0].n_value, 0); + read(0, tcp_debug, sizeof (tcp_debug)); + for (i = tcp_debx % TCP_NDEBUG; i < TCP_NDEBUG; i++) { + struct tcp_debug *td = &tcp_debug[i]; + ntime = td->td_time; +#if vax + ntime = ntohl(ntime); +#endif + 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]; + ntime = td->td_time; +#if vax + ntime = ntohl(ntime); +#endif + tcp_trace(td->td_act, td->td_ostate, td->td_tcb, &td->td_cb, + &td->td_ti, td->td_req); + } + exit(0); +} + +/* + * Tcp debug routines + */ +tcp_trace(act, ostate, atp, tp, ti, req) + short act, ostate; + struct tcpcb *atp, *tp; + struct tcpiphdr *ti; + int req; +{ + tcp_seq seq, ack; + int len, flags, win; + char *cp; + + ptime(ntime); + printf("%x %s:%s ", ((int)atp)&0xfffff, + tcpstates[ostate], tanames[act]); + switch (act) { + + case TA_INPUT: + case TA_OUTPUT: + seq = ti->ti_seq; + ack = ti->ti_ack; + len = ti->ti_len; + win = ti->ti_win; +#if vax + if (act == TA_OUTPUT) { + seq = ntohl(seq); + ack = ntohl(ack); + len = ntohs(len); + win = ntohs(win); + } +#endif + if (act == TA_OUTPUT) + len -= sizeof (struct tcphdr); + if (len) + printf("[%x..%x)", seq, seq+len); + else + printf("%x", seq); + printf("@%x", ack); + if (win) + printf("(win=%d)", win); + flags = ti->ti_flags; + if (flags) { + char *cp = "<"; +#define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } } + pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(URG); + printf(">"); + } + break; + + case TA_USER: + printf("%s", prurequests[req&0xff]); + if (req >> 8) + printf("<%s>", tcptimers[req>>8]); + break; + } + printf(" -> %s", tcpstates[tp->t_state]); + /* 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", + 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); + } +} + +ptime(ms) + int ms; +{ + + printf("%03d ", (ms/10) % 1000); +}