]>
git.saurik.com Git - apple/network_cmds.git/blob - trpt.tproj/trpt.c
b9f4a75da7eea6b9c67de34a066ad772c4f24193
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1983, 1988, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 #include <sys/cdefs.h>
59 __unused
static char copyright
[] =
60 "@(#) Copyright (c) 1983, 1988, 1993\n\
61 The Regents of the University of California. All rights reserved.\n";
65 __unused
static char sccsid
[] = "@(#)trpt.c 8.1 (Berkeley) 6/6/93";
68 #include <sys/param.h>
73 #include <machine/pte.h>
74 #include <sys/vmmac.h>
76 #include <sys/socket.h>
77 #include <sys/socketvar.h>
79 #include <sys/protosw.h>
82 #include <net/route.h>
85 #include <netinet/in.h>
86 #include <netinet/in_systm.h>
87 #include <netinet/ip.h>
88 #include <netinet/in_pcb.h>
89 #include <netinet/ip_var.h>
90 #include <netinet/tcp.h>
92 #include <netinet/tcp_fsm.h>
93 #include <netinet/tcp_seq.h>
95 #include <netinet/tcp_timer.h>
96 #include <netinet/tcp_var.h>
97 #include <netinet/tcpip.h>
99 #include <netinet/tcp_debug.h>
101 #include <arpa/inet.h>
110 struct tcp_debug tcp_debug
[TCP_NDEBUG
];
113 struct nlist nl
[] = {
114 #define N_TCP_DEBUG 0
128 static struct pte
*Sysmap
;
130 static caddr_t tcp_pcbs
[TCP_NDEBUG
];
132 static int aflag
, kflag
, memf
, follow
, sflag
, tflag
;
134 void klseek(int, off_t
, int);
135 void dotrace(caddr_t
);
136 void tcp_trace(short, short, struct tcpcb
*, struct tcpcb
*, struct tcpiphdr
*, int);
145 int ch
, i
, jflag
, npcbs
, numeric();
150 while ((ch
= getopt(argc
, argv
, "afjp:st")) != EOF
)
163 if (npcbs
>= TCP_NDEBUG
) {
164 fputs("trpt: too many pcb's specified\n",
168 (void)sscanf(optarg
, "%x", (int *)&tcp_pcbs
[npcbs
++]);
178 (void)fprintf(stderr
,
179 "usage: trpt [-afjst] [-p hex-address] [system [core]]\n");
195 * Discard setgid privileges if not the running kernel so that
196 * bad guys can't print interesting stuff from kernel memory.
203 if (nlist(system
, nl
) < 0 || !nl
[0].n_value
) {
204 fprintf(stderr
, "trpt: %s: no namelist\n", system
);
207 if ((memf
= open(core
, O_RDONLY
)) < 0) {
213 fputs("trpt: can't do core files yet\n", stderr
);
218 Sysmap
= (struct pte
*)
219 malloc((u_int
)(nl
[N_SYSSIZE
].n_value
* sizeof(struct pte
)));
221 fputs("trpt: can't get memory for Sysmap.\n", stderr
);
224 off
= nl
[N_SYSMAP
].n_value
& ~KERNBASE
;
225 (void)lseek(memf
, off
, L_SET
);
226 (void)read(memf
, (char *)Sysmap
,
227 (int)(nl
[N_SYSSIZE
].n_value
* sizeof(struct pte
)));
230 (void)klseek(memf
, (off_t
)nl
[N_TCP_DEBX
].n_value
, L_SET
);
231 if (read(memf
, (char *)&tcp_debx
, sizeof(tcp_debx
)) !=
233 perror("trpt: tcp_debx");
236 (void)klseek(memf
, (off_t
)nl
[N_TCP_DEBUG
].n_value
, L_SET
);
237 if (read(memf
, (char *)tcp_debug
, sizeof(tcp_debug
)) !=
239 perror("trpt: tcp_debug");
243 * If no control blocks have been specified, figure
244 * out how many distinct one we have and summarize
245 * them in tcp_pcbs for sorting the trace records
249 for (i
= 0; i
< TCP_NDEBUG
; i
++) {
250 register struct tcp_debug
*td
= &tcp_debug
[i
];
255 for (j
= 0; j
< npcbs
; j
++)
256 if (tcp_pcbs
[j
] == td
->td_tcb
)
259 tcp_pcbs
[npcbs
++] = td
->td_tcb
;
264 qsort(tcp_pcbs
, npcbs
, sizeof(caddr_t
), numeric
);
267 printf("%x", (int)tcp_pcbs
[i
]);
274 else for (i
= 0; i
< npcbs
; i
++) {
275 printf("\n%x:\n", (int)tcp_pcbs
[i
]);
276 dotrace(tcp_pcbs
[i
]);
283 register caddr_t tcpcb
;
285 register struct tcp_debug
*td
;
287 int prev_debx
= tcp_debx
;
289 again
: if (--tcp_debx
< 0)
290 tcp_debx
= TCP_NDEBUG
- 1;
291 for (i
= prev_debx
% TCP_NDEBUG
; i
< TCP_NDEBUG
; i
++) {
293 if (tcpcb
&& td
->td_tcb
!= tcpcb
)
295 ntime
= ntohl(td
->td_time
);
296 tcp_trace(td
->td_act
, td
->td_ostate
, (struct tcpcb
*)td
->td_tcb
, &td
->td_cb
,
297 (struct tcpiphdr
*)&td
->td_ti
.ti_t
, td
->td_req
);
301 for (i
= 0; i
<= tcp_debx
% TCP_NDEBUG
; i
++) {
303 if (tcpcb
&& td
->td_tcb
!= tcpcb
)
305 ntime
= ntohl(td
->td_time
);
306 tcp_trace(td
->td_act
, td
->td_ostate
, (struct tcpcb
*)td
->td_tcb
, &td
->td_cb
,
307 (struct tcpiphdr
*)&td
->td_ti
.ti_t
, td
->td_req
);
310 prev_debx
= tcp_debx
+ 1;
311 if (prev_debx
>= TCP_NDEBUG
)
315 (void)klseek(memf
, (off_t
)nl
[N_TCP_DEBX
].n_value
, L_SET
);
316 if (read(memf
, (char *)&tcp_debx
, sizeof(tcp_debx
)) !=
318 perror("trpt: tcp_debx");
321 } while (tcp_debx
== prev_debx
);
322 (void)klseek(memf
, (off_t
)nl
[N_TCP_DEBUG
].n_value
, L_SET
);
323 if (read(memf
, (char *)tcp_debug
, sizeof(tcp_debug
)) !=
325 perror("trpt: tcp_debug");
337 tcp_trace(act
, ostate
, atp
, tp
, ti
, req
)
339 struct tcpcb
*atp
, *tp
;
344 int flags
, len
, win
, timer
;
346 printf("%03u %s:%s ",(ntime
/10) % 1000, tcpstates
[ostate
],
353 printf("(src=%s,%u, ",
354 inet_ntoa(ti
->ti_src
), ntohs(ti
->ti_sport
));
356 inet_ntoa(ti
->ti_dst
), ntohs(ti
->ti_dport
));
362 if (act
== TA_OUTPUT
) {
368 if (act
== TA_OUTPUT
)
369 len
-= sizeof(struct tcphdr
);
371 printf("[%x..%x)", seq
, seq
+ len
);
376 printf("(win=%x)", win
);
377 flags
= ti
->ti_flags
;
379 register char *cp
= "<";
380 #define pf(flag, string) { \
381 if (ti->ti_flags&flag) { \
382 (void)printf("%s%s", cp, string); \
398 printf("%s", prurequests
[req
]);
399 if (req
== PRU_SLOWTIMO
|| req
== PRU_FASTTIMO
)
400 printf("<%s>", tcptimers
[timer
]);
403 printf(" -> %s", tcpstates
[tp
->t_state
]);
404 /* print out internal state of tp !?! */
407 printf("\trcv_nxt %x rcv_wnd %x snd_una %x snd_nxt %x snd_max %x\n",
408 tp
->rcv_nxt
, tp
->rcv_wnd
, tp
->snd_una
, tp
->snd_nxt
,
410 printf("\tsnd_wl1 %x snd_wl2 %x snd_wnd %x\n", tp
->snd_wl1
,
411 tp
->snd_wl2
, tp
->snd_wnd
);
413 /* print out timers? */
415 register char *cp
= "\t";
418 for (i
= 0; i
< TCPT_NTIMERS
; i
++) {
419 if (tp
->t_timer
[i
] == 0)
421 printf("%s%s=%d", cp
, tcptimers
[i
], tp
->t_timer
[i
]);
423 printf(" (t_rxtshft=%d)", tp
->t_rxtshift
);
439 klseek(fd
, base
, off
)
446 if (kflag
) { /* get kernel pte */
448 base
= ctob(Sysmap
[btop(base
)].pg_pfnum
) + (base
& PGOFSET
);
451 (void)lseek(fd
, base
, off
);