1 #ifndef lint 2 static char sccsid[] = "@(#)trpt.c 4.1 82/04/02"; 3 #endif 4 5 #include <sys/param.h> 6 #include <sys/socket.h> 7 #include <sys/socketvar.h> 8 #define PRUREQUESTS 9 #include <sys/protosw.h> 10 #include <net/in.h> 11 #include <net/route.h> 12 #include <net/in_pcb.h> 13 #include <net/in_systm.h> 14 #include <net/if.h> 15 #include <net/ip.h> 16 #include <net/ip_var.h> 17 #include <net/tcp.h> 18 #define TCPSTATES 19 #include <net/tcp_fsm.h> 20 #include <net/tcp_seq.h> 21 #define TCPTIMERS 22 #include <net/tcp_timer.h> 23 #include <net/tcp_var.h> 24 #include <net/tcpip.h> 25 #define TANAMES 26 #include <net/tcp_debug.h> 27 #include <errno.h> 28 29 #include <nlist.h> 30 31 n_time ntime; 32 int sflag; 33 struct nlist nl[] = { 34 { "_tcp_debug" }, 35 { "_tcp_debx" }, 36 0 37 }; 38 struct tcp_debug tcp_debug[TCP_NDEBUG]; 39 int tcp_debx; 40 41 main(argc, argv) 42 int argc; 43 char **argv; 44 { 45 int i; 46 47 argc--, argv++; 48 again: 49 if (argc > 0 && !strcmp(*argv, "-s")) { 50 sflag++, argc--, argv++; 51 goto again; 52 } 53 nlist(argc > 0 ? *argv : "/vmunix", nl); 54 if (nl[0].n_value == 0) { 55 printf("no namelist\n"); 56 exit(1); 57 } 58 close(0); 59 open(argc > 1 ? argv[1] : "/dev/kmem", 0); 60 if (argc > 1) { 61 nl[0].n_value &= 0x7fffffff; 62 nl[1].n_value &= 0x7fffffff; 63 } 64 lseek(0, nl[1].n_value, 0); 65 read(0, &tcp_debx, sizeof (tcp_debx)); 66 printf("tcp_debx=%d\n", tcp_debx); 67 lseek(0, nl[0].n_value, 0); 68 read(0, tcp_debug, sizeof (tcp_debug)); 69 for (i = tcp_debx % TCP_NDEBUG; i < TCP_NDEBUG; i++) { 70 struct tcp_debug *td = &tcp_debug[i]; 71 ntime = td->td_time; 72 #if vax 73 ntime = ntohl(ntime); 74 #endif 75 tcp_trace(td->td_act, td->td_ostate, td->td_tcb, &td->td_cb, 76 &td->td_ti, td->td_req); 77 } 78 for (i = 0; i < tcp_debx % TCP_NDEBUG; i++) { 79 struct tcp_debug *td = &tcp_debug[i]; 80 ntime = td->td_time; 81 #if vax 82 ntime = ntohl(ntime); 83 #endif 84 tcp_trace(td->td_act, td->td_ostate, td->td_tcb, &td->td_cb, 85 &td->td_ti, td->td_req); 86 } 87 exit(0); 88 } 89 90 /* 91 * Tcp debug routines 92 */ 93 tcp_trace(act, ostate, atp, tp, ti, req) 94 short act, ostate; 95 struct tcpcb *atp, *tp; 96 struct tcpiphdr *ti; 97 int req; 98 { 99 tcp_seq seq, ack; 100 int len, flags, win; 101 char *cp; 102 103 ptime(ntime); 104 printf("%x %s:%s ", ((int)atp)&0xfffff, 105 tcpstates[ostate], tanames[act]); 106 switch (act) { 107 108 case TA_INPUT: 109 case TA_OUTPUT: 110 seq = ti->ti_seq; 111 ack = ti->ti_ack; 112 len = ti->ti_len; 113 win = ti->ti_win; 114 #if vax 115 if (act == TA_OUTPUT) { 116 seq = ntohl(seq); 117 ack = ntohl(ack); 118 len = ntohs(len); 119 win = ntohs(win); 120 } 121 #endif 122 if (act == TA_OUTPUT) 123 len -= sizeof (struct tcphdr); 124 if (len) 125 printf("[%x..%x)", seq, seq+len); 126 else 127 printf("%x", seq); 128 printf("@%x", ack); 129 if (win) 130 printf("(win=%d)", win); 131 flags = ti->ti_flags; 132 if (flags) { 133 char *cp = "<"; 134 #define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } } 135 pf(SYN); pf(ACK); pf(FIN); pf(RST); pf(URG); 136 printf(">"); 137 } 138 break; 139 140 case TA_USER: 141 printf("%s", prurequests[req&0xff]); 142 if (req >> 8) 143 printf("<%s>", tcptimers[req>>8]); 144 break; 145 } 146 printf(" -> %s", tcpstates[tp->t_state]); 147 /* print out internal state of tp !?! */ 148 printf("\n"); 149 if (sflag) { 150 printf("\trcv_nxt %x rcv_wnd %d snd_una %x snd_nxt %x snd_max %x\n", 151 tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt, tp->snd_max); 152 printf("\tsnd_wl1 %x snd_wl2 %x snd_wnd %x\n", tp->snd_wl1, tp->snd_wl2, tp->snd_wnd); 153 } 154 } 155 156 ptime(ms) 157 int ms; 158 { 159 160 printf("%03d ", (ms/10) % 1000); 161 } 162