* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
static char sccsid
[] = "@(#)trpt.c 5.2 (Berkeley) %G%";
#include <sys/socketvar.h>
#include <netinet/in_pcb.h>
#include <netinet/in_systm.h>
#include <netinet/ip_var.h>
#include <netinet/tcp_fsm.h>
#include <netinet/tcp_seq.h>
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
#include <netinet/tcpip.h>
#include <netinet/tcp_debug.h>
struct tcp_debug tcp_debug
[TCP_NDEBUG
];
caddr_t tcp_pcbs
[TCP_NDEBUG
];
int i
, mask
= 0, npcbs
= 0;
char *system
= "/vmunix", *core
= "/dev/kmem";
if (argc
> 0 && !strcmp(*argv
, "-a")) {
if (argc
> 0 && !strcmp(*argv
, "-f")) {
follow
++, argc
--, argv
++;
if (argc
> 0 && !strcmp(*argv
, "-s")) {
if (argc
> 0 && !strcmp(*argv
, "-t")) {
if (argc
> 0 && !strcmp(*argv
, "-j")) {
if (argc
> 0 && !strcmp(*argv
, "-p")) {
fprintf(stderr
, "-p: missing tcpcb address\n");
if (npcbs
>= TCP_NDEBUG
) {
fprintf(stderr
, "-p: too many pcb's specified\n");
sscanf(*argv
, "%x", &tcp_pcbs
[npcbs
++]);
(void) nlist(system
, nl
);
if (nl
[0].n_value
== 0) {
fprintf(stderr
, "trpt: %s: no namelist\n", system
);
fprintf(stderr
, "trpt: "); perror(core
);
nl
[0].n_value
&= 0x7fffffff;
nl
[1].n_value
&= 0x7fffffff;
(void) lseek(0, nl
[1].n_value
, 0);
if (read(0, &tcp_debx
, sizeof (tcp_debx
)) != sizeof (tcp_debx
)) {
fprintf(stderr
, "trpt: "); perror("tcp_debx");
(void) lseek(0, nl
[0].n_value
, 0);
if (read(0, tcp_debug
, sizeof (tcp_debug
)) != sizeof (tcp_debug
)) {
fprintf(stderr
, "trpt: "); perror("tcp_debug");
* 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
for (i
= 0; i
< TCP_NDEBUG
; i
++) {
register struct tcp_debug
*td
= &tcp_debug
[i
];
for (j
= 0; j
< npcbs
; j
++)
if (tcp_pcbs
[j
] == td
->td_tcb
)
tcp_pcbs
[npcbs
++] = td
->td_tcb
;
qsort(tcp_pcbs
, npcbs
, sizeof (caddr_t
), numeric
);
for (i
= 0; i
< npcbs
; i
++) {
printf("%s%x", cp
, tcp_pcbs
[i
]);
for (i
= 0; i
< npcbs
; i
++) {
printf("\n%x:\n", tcp_pcbs
[i
]);
register struct tcp_debug
*td
;
int prev_debx
= tcp_debx
;
tcp_debx
= TCP_NDEBUG
- 1;
for (i
= prev_debx
% TCP_NDEBUG
; i
< TCP_NDEBUG
; i
++) {
if (tcpcb
&& td
->td_tcb
!= tcpcb
)
ntime
= ntohl(td
->td_time
);
tcp_trace(td
->td_act
, td
->td_ostate
, td
->td_tcb
, &td
->td_cb
,
for (i
= 0; i
<= tcp_debx
% TCP_NDEBUG
; i
++) {
if (tcpcb
&& td
->td_tcb
!= tcpcb
)
ntime
= ntohl(td
->td_time
);
tcp_trace(td
->td_act
, td
->td_ostate
, td
->td_tcb
, &td
->td_cb
,
prev_debx
= tcp_debx
+ 1;
if (prev_debx
>= TCP_NDEBUG
)
(void) lseek(0, nl
[1].n_value
, 0);
if (read(0, &tcp_debx
, sizeof(tcp_debx
)) != sizeof(tcp_debx
)) {
fprintf(stderr
, "trpt: "); perror("tcp_debx");
} while (tcp_debx
== prev_debx
);
(void) lseek(0, nl
[0].n_value
, 0);
if (read(0, tcp_debug
, sizeof(tcp_debug
)) != sizeof(tcp_debug
)) {
fprintf(stderr
, "trpt: "); perror("tcp_debug");
tcp_trace(act
, ostate
, atp
, tp
, ti
, req
)
int len
, flags
, win
, timer
;
printf("%s:%s ", tcpstates
[ostate
], tanames
[act
]);
printf("(src=%s,%d, ", inet_ntoa(ti
->ti_src
),
printf("dst=%s,%d)", inet_ntoa(ti
->ti_dst
),
len
-= sizeof (struct tcphdr
);
printf("[%x..%x)", seq
, seq
+len
);
#define pf(f) { if (ti->ti_flags&TH_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
pf(SYN
); pf(ACK
); pf(FIN
); pf(RST
); pf(PUSH
); pf(URG
);
printf("%s", prurequests
[req
]);
if (req
== PRU_SLOWTIMO
|| req
== PRU_FASTTIMO
)
printf("<%s>", tcptimers
[timer
]);
printf(" -> %s", tcpstates
[tp
->t_state
]);
/* print out internal state of tp !?! */
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
,
printf("\tsnd_wl1 %x snd_wl2 %x snd_wnd %x\n", tp
->snd_wl1
,
tp
->snd_wl2
, tp
->snd_wnd
);
for (i
= 0; i
< TCPT_NTIMERS
; i
++) {
printf("%s%s=%d", cp
, tcptimers
[i
], tp
->t_timer
[i
]);
printf(" (t_rxtshft=%d)", tp
->t_rxtshift
);
printf("%03d ", (ms
/10) % 1000);