From 90755c07f9f1703e99d77beeec791b48791f538d Mon Sep 17 00:00:00 2001 From: charnier Date: Wed, 22 Oct 1997 06:23:12 +0000 Subject: Use err(3). Add usage() and prototypes. Hide reference to trsp(8) that does not exist. --- usr.sbin/trpt/trpt.8 | 15 +++++---- usr.sbin/trpt/trpt.c | 94 +++++++++++++++++++++++++++------------------------- 2 files changed, 56 insertions(+), 53 deletions(-) (limited to 'usr.sbin/trpt') diff --git a/usr.sbin/trpt/trpt.8 b/usr.sbin/trpt/trpt.8 index 609e529..fbed94f 100644 --- a/usr.sbin/trpt/trpt.8 +++ b/usr.sbin/trpt/trpt.8 @@ -59,7 +59,7 @@ when a socket is marked for .Xr setsockopt 2 ) , and prints a readable description of these records. When no options are supplied, -.Nm trpt +.Nm prints all the trace records found in the system grouped according to .Tn TCP @@ -68,7 +68,7 @@ block .Pq Tn PCB . The following options may be used to alter this behavior. -.Bl -tag -width Ds +.Bl -tag -width indent .It Fl a In addition to the normal output, print the values of the source and destination @@ -88,13 +88,13 @@ In addition to the normal output, print a detailed description of the packet sequencing information. .It Fl t -in addition to the normal output, +In addition to the normal output, print the values for all timers at each point in the trace. .El .Pp The recommended use of -.Nm trpt +.Nm is as follows. Isolate the problem and enable debugging on the socket(s) involved in the connection. @@ -104,7 +104,7 @@ associated with the sockets using the option to .Xr netstat 1 . Then run -.Nm trpt +.Nm with the .Fl p option, supplying the associated @@ -129,8 +129,9 @@ arguments may be used to supplant the defaults. .El .Sh SEE ALSO .Xr netstat 1 , -.Xr setsockopt 2 , -.Xr trsp 8 +.Xr setsockopt 2 +.\".Xr setsockopt 2 , +.\".Xr trsp 8 .Sh DIAGNOSTICS .Bl -tag -width Ds .It Sy no namelist diff --git a/usr.sbin/trpt/trpt.c b/usr.sbin/trpt/trpt.c index 3bb58f6..2d604af 100644 --- a/usr.sbin/trpt/trpt.c +++ b/usr.sbin/trpt/trpt.c @@ -32,13 +32,17 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1983, 1988, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)trpt.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include @@ -70,10 +74,12 @@ static char sccsid[] = "@(#)trpt.c 8.1 (Berkeley) 6/6/93"; #include -#include -#include +#include #include #include +#include +#include +#include struct nlist nl[] = { #define N_TCP_DEBUG 0 @@ -87,15 +93,20 @@ static caddr_t tcp_pcbs[TCP_NDEBUG]; static n_time ntime; static int aflag, kflag, memf, follow, sflag, tflag; +void dotrace __P((caddr_t)); +void klseek __P((int, off_t, int)); +int numeric __P((caddr_t *, caddr_t *)); +void tcp_trace __P((short, short, struct tcpcb *, struct tcpcb *, + struct tcpiphdr *, int)); +static void usage __P((void)); + +int main(argc, argv) int argc; char **argv; { - extern char *optarg; - extern int optind; - int ch, i, jflag, npcbs, numeric(); - char *system, *core, *malloc(); - off_t lseek(); + int ch, i, jflag, npcbs; + char *system, *core; jflag = npcbs = 0; while ((ch = getopt(argc, argv, "afjp:st")) != -1) @@ -111,11 +122,8 @@ main(argc, argv) ++jflag; break; case 'p': - if (npcbs >= TCP_NDEBUG) { - fputs("trpt: too many pcb's specified\n", - stderr); - exit(1); - } + if (npcbs >= TCP_NDEBUG) + errx(1, "too many pcb's specified"); (void)sscanf(optarg, "%x", (int *)&tcp_pcbs[npcbs++]); break; case 's': @@ -126,9 +134,7 @@ main(argc, argv) break; case '?': default: - (void)fprintf(stderr, -"usage: trpt [-afjst] [-p hex-address] [system [core]]\n"); - exit(1); + usage(); } argc -= optind; argv += optind; @@ -151,30 +157,20 @@ main(argc, argv) else system = (char *)getbootfile(); - if (nlist(system, nl) < 0 || !nl[0].n_value) { - fprintf(stderr, "trpt: %s: no namelist\n", system); - exit(1); - } - if ((memf = open(core, O_RDONLY)) < 0) { - perror(core); - exit(2); - } - if (kflag) { - fputs("trpt: can't do core files yet\n", stderr); - exit(1); - } + if (nlist(system, nl) < 0 || !nl[0].n_value) + errx(1, "%s: no namelist", system); + if ((memf = open(core, O_RDONLY)) < 0) + err(2, "%s", core); + if (kflag) + errx(1, "can't do core files yet"); (void)klseek(memf, (off_t)nl[N_TCP_DEBX].n_value, L_SET); if (read(memf, (char *)&tcp_debx, sizeof(tcp_debx)) != - sizeof(tcp_debx)) { - perror("trpt: tcp_debx"); - exit(3); - } + sizeof(tcp_debx)) + err(3, "tcp_debx"); (void)klseek(memf, (off_t)nl[N_TCP_DEBUG].n_value, L_SET); if (read(memf, (char *)tcp_debug, sizeof(tcp_debug)) != - sizeof(tcp_debug)) { - perror("trpt: tcp_debug"); - exit(3); - } + sizeof(tcp_debug)) + err(3, "tcp_debug"); /* * If no control blocks have been specified, figure * out how many distinct one we have and summarize @@ -214,6 +210,15 @@ main(argc, argv) exit(0); } +static void +usage() +{ + (void)fprintf(stderr, + "usage: trpt [-afjst] [-p hex-address] [system [core]]\n"); + exit(1); +} + +void dotrace(tcpcb) register caddr_t tcpcb; { @@ -249,17 +254,13 @@ done: if (follow) { sleep(1); (void)klseek(memf, (off_t)nl[N_TCP_DEBX].n_value, L_SET); if (read(memf, (char *)&tcp_debx, sizeof(tcp_debx)) != - sizeof(tcp_debx)) { - perror("trpt: tcp_debx"); - exit(3); - } + sizeof(tcp_debx)) + err(3, "tcp_debx"); } while (tcp_debx == prev_debx); (void)klseek(memf, (off_t)nl[N_TCP_DEBUG].n_value, L_SET); if (read(memf, (char *)tcp_debug, sizeof(tcp_debug)) != - sizeof(tcp_debug)) { - perror("trpt: tcp_debug"); - exit(3); - } + sizeof(tcp_debug)) + err(3, "tcp_debug"); goto again; } } @@ -268,6 +269,7 @@ done: if (follow) { * Tcp debug routines */ /*ARGSUSED*/ +void tcp_trace(act, ostate, atp, tp, ti, req) short act, ostate; struct tcpcb *atp, *tp; @@ -362,17 +364,17 @@ tcp_trace(act, ostate, atp, tp, ti, req) } } +int numeric(c1, c2) caddr_t *c1, *c2; { return(*c1 - *c2); } +void klseek(fd, base, off) int fd, off; off_t base; { - off_t lseek(); - (void)lseek(fd, base, off); } -- cgit v1.1