Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Jul 2002 15:45:21 -0700
From:      Alfred Perlstein <bright@mu.org>
To:        bde@freebsd.org
Cc:        audit@freebsd.org
Subject:   trpt cleanup
Message-ID:  <20020711224521.GD97638@elvis.mu.org>

next in thread | raw e-mail | index | archive | help
please review


Index: Makefile
===================================================================
RCS file: /home/ncvs/src/usr.sbin/trpt/Makefile,v
retrieving revision 1.6
diff -u -r1.6 Makefile
--- Makefile	20 Jul 2001 06:20:25 -0000	1.6
+++ Makefile	11 Jul 2002 22:32:33 -0000
@@ -2,6 +2,7 @@
 # $FreeBSD: src/usr.sbin/trpt/Makefile,v 1.6 2001/07/20 06:20:25 obrien Exp $
 
 PROG=	trpt
+WARNS?=	4
 MAN=	trpt.8
 BINGRP=	kmem
 BINMODE= 2555
Index: trpt.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/trpt/trpt.c,v
retrieving revision 1.15
diff -u -r1.15 trpt.c
--- trpt.c	15 May 2002 09:36:46 -0000	1.15
+++ trpt.c	11 Jul 2002 22:43:55 -0000
@@ -82,34 +82,38 @@
 #include <paths.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
-struct nlist nl[] = {
+struct nlist nl[3];
 #define	N_TCP_DEBUG	0
-	{ "_tcp_debug" },
 #define	N_TCP_DEBX	1
-	{ "_tcp_debx" },
-	{ "" },
-};
 
 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((const void *, const void *));
-void tcp_trace __P((short, short, struct tcpcb *, struct tcpcb *,
-			int, void *, struct tcphdr *, int));
-static void usage __P((void));
+void dotrace(caddr_t);
+void klseek(int, off_t, int);
+int numeric(const void *, const void *);
+void tcp_trace(short, short, struct tcpcb *, struct tcpcb *,
+			int, void *, struct tcphdr *, int);
+static void usage(void);
 
 int
-main(argc, argv)
-	int argc;
-	char **argv;
+main(int argc, char **argv)
 {
 	int ch, i, jflag, npcbs;
-	char *system, *core;
+	const char *syst;
+	const char *core;
+	char debug[] = "_tcp_debug";
+	char debx[] = "_tcp_debx";
+	char empty[] = "";
+
+	bzero(nl, sizeof(nl));
+	nl[0].n_name = debug;
+	nl[1].n_name = debx;
+	nl[2].n_name = empty;
 
 	jflag = npcbs = 0;
 	while ((ch = getopt(argc, argv, "afjp:st")) != -1)
@@ -144,7 +148,7 @@
 
 	core = _PATH_KMEM;
 	if (argc > 0) {
-		system = *argv;
+		syst = *argv;
 		argc--, argv++;
 		if (argc > 0) {
 			core = *argv;
@@ -158,10 +162,10 @@
 		setgid(getgid());
 	}
 	else
-		system = (char *)getbootfile();
+		syst = getbootfile();
 
-	if (nlist(system, nl) < 0 || !nl[0].n_value)
-		errx(1, "%s: no namelist", system);
+	if (nlist(syst, nl) < 0 || !nl[0].n_value)
+		errx(1, "%s: no namelist", syst);
 	if ((memf = open(core, O_RDONLY)) < 0)
 		err(2, "%s", core);
 	setgid(getgid());
@@ -200,7 +204,7 @@
 	qsort(tcp_pcbs, npcbs, sizeof(caddr_t), numeric);
 	if (jflag) {
 		for (i = 0;;) {
-			printf("%x", tcp_pcbs[i]);
+			printf("%p", tcp_pcbs[i]);
 			if (++i == npcbs)
 				break;
 			fputs(", ", stdout);
@@ -314,7 +318,7 @@
 void
 tcp_trace(act, ostate, atp, tp, family, ip, th, req)
 	short act, ostate;
-	struct tcpcb *atp, *tp;
+	struct tcpcb *atp __unused, *tp;
 	int family;
 	void *ip;
 	struct tcphdr *th;
@@ -347,7 +351,7 @@
 #else
 	ip4 = (struct ip *)ip;
 #endif
-	printf("%03ld %s:%s ",(ntime/10) % 1000, tcpstates[ostate],
+	printf("%03ld %s:%s ", (long)((ntime/10) % 1000), tcpstates[ostate],
 	    tanames[act]);
 	switch (act) {
 	case TA_INPUT:
@@ -394,15 +398,15 @@
 		if (act == TA_OUTPUT)
 			len -= sizeof(struct tcphdr);
 		if (len)
-			printf("[%lx..%lx)", seq, seq + len);
+			printf("[%lx..%lx)", (long)seq, (long)(seq + len));
 		else
-			printf("%lx", seq);
-		printf("@%lx", ack);
+			printf("%lx", (long)seq);
+		printf("@%lx", (long)ack);
 		if (win)
 			printf("(win=%x)", win);
 		flags = th->th_flags;
 		if (flags) {
-			register char *cp = "<";
+			const char *cp = "<";
 #define	pf(flag, string) { \
 	if (th->th_flags&flag) { \
 		(void)printf("%s%s", cp, string); \
@@ -431,10 +435,12 @@
 	printf("\n");
 	if (sflag) {
 		printf("\trcv_nxt %lx rcv_wnd %x snd_una %lx snd_nxt %lx snd_max %lx\n",
-		    tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt,
-		    tp->snd_max);
-		printf("\tsnd_wl1 %lx snd_wl2 %lx snd_wnd %x\n", tp->snd_wl1,
-		    tp->snd_wl2, tp->snd_wnd);
+		    (long)tp->rcv_nxt, (int)tp->rcv_wnd,
+		    (long)tp->snd_una, (long)tp->snd_nxt,
+		    (long)tp->snd_max);
+		printf("\tsnd_wl1 %lx snd_wl2 %lx snd_wnd %x\n",
+		    (long)tp->snd_wl1,
+		    (long)tp->snd_wl2, (int)tp->snd_wnd);
 	}
 	/* print out timers? */
 #if 0


-- 
-Alfred Perlstein [alfred@freebsd.org]
'Instead of asking why a piece of software is using "1970s technology,"
 start asking why software is ignoring 30 years of accumulated wisdom.'
Tax deductible donations for FreeBSD: http://www.freebsdfoundation.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020711224521.GD97638>