trpt(8): Sprinkle style(9) and adddress warnings
Update function definitions to post-ISO style; remove deprecated "register" keyword. Correct indentation. Sprinkle 'static' on file-local variables. Appease warnings at WARNS=6, for both Clang and GCC. Sponsored by: Dell EMC Isilon
This commit is contained in:
parent
ea4fe1da62
commit
808c12715c
@ -8,10 +8,12 @@ MAN= trpt.8
|
|||||||
BINGRP= kmem
|
BINGRP= kmem
|
||||||
BINMODE= 2555
|
BINMODE= 2555
|
||||||
|
|
||||||
WARNS?= 4
|
|
||||||
|
|
||||||
.if ${MK_INET6_SUPPORT} != "no"
|
.if ${MK_INET6_SUPPORT} != "no"
|
||||||
CFLAGS+= -DINET6
|
CFLAGS+= -DINET6
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
|
||||||
|
# Several included system headers tickle this warning in ways that are
|
||||||
|
# difficult to work around in this program.
|
||||||
|
CFLAGS+= -Wno-missing-variable-declarations
|
||||||
|
@ -79,12 +79,13 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <nlist.h>
|
#include <nlist.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
struct nlist nl[3];
|
static struct nlist nl[3];
|
||||||
#define N_TCP_DEBUG 0
|
#define N_TCP_DEBUG 0
|
||||||
#define N_TCP_DEBX 1
|
#define N_TCP_DEBX 1
|
||||||
|
|
||||||
@ -92,10 +93,10 @@ static caddr_t tcp_pcbs[TCP_NDEBUG];
|
|||||||
static n_time ntime;
|
static n_time ntime;
|
||||||
static int aflag, kflag, memf, follow, sflag;
|
static int aflag, kflag, memf, follow, sflag;
|
||||||
|
|
||||||
void dotrace(caddr_t);
|
static void dotrace(caddr_t);
|
||||||
void klseek(int, off_t, int);
|
static void klseek(int, off_t, int);
|
||||||
int numeric(const void *, const void *);
|
static int numeric(const void *, const void *);
|
||||||
void tcp_trace(short, short, struct tcpcb *, int, void *, struct tcphdr *, int);
|
static void tcp_trace(short, short, struct tcpcb *, int, void *, struct tcphdr *, int);
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -150,8 +151,7 @@ main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
if (setgid(getgid()) != 0)
|
if (setgid(getgid()) != 0)
|
||||||
err(1, "setgid");
|
err(1, "setgid");
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
syst = getbootfile();
|
syst = getbootfile();
|
||||||
|
|
||||||
if (nlist(syst, nl) < 0 || !nl[0].n_value)
|
if (nlist(syst, nl) < 0 || !nl[0].n_value)
|
||||||
@ -178,8 +178,8 @@ main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
if (!npcbs) {
|
if (!npcbs) {
|
||||||
for (i = 0; i < TCP_NDEBUG; i++) {
|
for (i = 0; i < TCP_NDEBUG; i++) {
|
||||||
register struct tcp_debug *td = &tcp_debug[i];
|
struct tcp_debug *td = &tcp_debug[i];
|
||||||
register int j;
|
int j;
|
||||||
|
|
||||||
if (td->td_tcb == 0)
|
if (td->td_tcb == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -201,31 +201,31 @@ main(int argc, char **argv)
|
|||||||
fputs(", ", stdout);
|
fputs(", ", stdout);
|
||||||
}
|
}
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
} else
|
||||||
else for (i = 0; i < npcbs; i++) {
|
for (i = 0; i < npcbs; i++) {
|
||||||
printf("\n%p:\n", tcp_pcbs[i]);
|
printf("\n%p:\n", tcp_pcbs[i]);
|
||||||
dotrace(tcp_pcbs[i]);
|
dotrace(tcp_pcbs[i]);
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage()
|
usage(void)
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"usage: trpt [-afjs] [-p hex-address] [system [core]]\n");
|
"usage: trpt [-afjs] [-p hex-address] [system [core]]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
dotrace(tcpcb)
|
dotrace(caddr_t tcpcb)
|
||||||
register caddr_t tcpcb;
|
|
||||||
{
|
{
|
||||||
register struct tcp_debug *td;
|
struct tcp_debug *td;
|
||||||
register int i;
|
int i;
|
||||||
int prev_debx = tcp_debx, family;
|
int prev_debx = tcp_debx, family;
|
||||||
|
|
||||||
again: if (--tcp_debx < 0)
|
again:
|
||||||
|
if (--tcp_debx < 0)
|
||||||
tcp_debx = TCP_NDEBUG - 1;
|
tcp_debx = TCP_NDEBUG - 1;
|
||||||
for (i = prev_debx % TCP_NDEBUG; i < TCP_NDEBUG; i++) {
|
for (i = prev_debx % TCP_NDEBUG; i < TCP_NDEBUG; i++) {
|
||||||
td = &tcp_debug[i];
|
td = &tcp_debug[i];
|
||||||
@ -237,17 +237,17 @@ again: if (--tcp_debx < 0)
|
|||||||
#else
|
#else
|
||||||
family = AF_INET;
|
family = AF_INET;
|
||||||
#endif
|
#endif
|
||||||
switch(family) {
|
switch (family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
tcp_trace(td->td_act, td->td_ostate,
|
tcp_trace(td->td_act, td->td_ostate, &td->td_cb,
|
||||||
&td->td_cb, td->td_family, &td->td_ti.ti_i,
|
td->td_family, &td->td_ti.ti_i, &td->td_ti.ti_t,
|
||||||
&td->td_ti.ti_t, td->td_req);
|
td->td_req);
|
||||||
break;
|
break;
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
tcp_trace(td->td_act, td->td_ostate,
|
tcp_trace(td->td_act, td->td_ostate, &td->td_cb,
|
||||||
&td->td_cb, td->td_family, &td->td_ti6.ip6,
|
td->td_family, &td->td_ti6.ip6, &td->td_ti6.th,
|
||||||
&td->td_ti6.th, td->td_req);
|
td->td_req);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -264,22 +264,23 @@ again: if (--tcp_debx < 0)
|
|||||||
#else
|
#else
|
||||||
family = AF_INET;
|
family = AF_INET;
|
||||||
#endif
|
#endif
|
||||||
switch(family) {
|
switch (family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
tcp_trace(td->td_act, td->td_ostate,
|
tcp_trace(td->td_act, td->td_ostate, &td->td_cb,
|
||||||
&td->td_cb, td->td_family, &td->td_ti.ti_i,
|
td->td_family, &td->td_ti.ti_i, &td->td_ti.ti_t,
|
||||||
&td->td_ti.ti_t, td->td_req);
|
td->td_req);
|
||||||
break;
|
break;
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
tcp_trace(td->td_act, td->td_ostate,
|
tcp_trace(td->td_act, td->td_ostate, &td->td_cb,
|
||||||
&td->td_cb, td->td_family, &td->td_ti6.ip6,
|
td->td_family, &td->td_ti6.ip6, &td->td_ti6.th,
|
||||||
&td->td_ti6.th, td->td_req);
|
td->td_req);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done: if (follow) {
|
done:
|
||||||
|
if (follow) {
|
||||||
prev_debx = tcp_debx + 1;
|
prev_debx = tcp_debx + 1;
|
||||||
if (prev_debx >= TCP_NDEBUG)
|
if (prev_debx >= TCP_NDEBUG)
|
||||||
prev_debx = 0;
|
prev_debx = 0;
|
||||||
@ -302,7 +303,7 @@ done: if (follow) {
|
|||||||
* Tcp debug routines
|
* Tcp debug routines
|
||||||
*/
|
*/
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
void
|
static void
|
||||||
tcp_trace(short act, short ostate, struct tcpcb *tp, int family __unused,
|
tcp_trace(short act, short ostate, struct tcpcb *tp, int family __unused,
|
||||||
void *ip, struct tcphdr *th, int req)
|
void *ip, struct tcphdr *th, int req)
|
||||||
{
|
{
|
||||||
@ -310,21 +311,26 @@ tcp_trace(short act, short ostate, struct tcpcb *tp, int family __unused,
|
|||||||
int flags, len, win, timer;
|
int flags, len, win, timer;
|
||||||
struct ip *ip4;
|
struct ip *ip4;
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
int isipv6, nopkt = 1;
|
bool isipv6, nopkt = true;
|
||||||
struct ip6_hdr *ip6;
|
struct ip6_hdr *ip6;
|
||||||
char ntop_buf[INET6_ADDRSTRLEN];
|
char ntop_buf[INET6_ADDRSTRLEN];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
|
/* Appease GCC -Wmaybe-uninitialized */
|
||||||
|
ip4 = NULL;
|
||||||
|
ip6 = NULL;
|
||||||
|
isipv6 = false;
|
||||||
|
|
||||||
switch (family) {
|
switch (family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
nopkt = 0;
|
nopkt = false;
|
||||||
isipv6 = 0;
|
isipv6 = false;
|
||||||
ip4 = (struct ip *)ip;
|
ip4 = (struct ip *)ip;
|
||||||
break;
|
break;
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
nopkt = 0;
|
nopkt = false;
|
||||||
isipv6 = 1;
|
isipv6 = true;
|
||||||
ip6 = (struct ip6_hdr *)ip;
|
ip6 = (struct ip6_hdr *)ip;
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
@ -333,43 +339,39 @@ tcp_trace(short act, short ostate, struct tcpcb *tp, int family __unused,
|
|||||||
#else
|
#else
|
||||||
ip4 = (struct ip *)ip;
|
ip4 = (struct ip *)ip;
|
||||||
#endif
|
#endif
|
||||||
printf("%03ld %s:%s ", (long)((ntime/10) % 1000), tcpstates[ostate],
|
printf("%03ld %s:%s ", (long)((ntime / 10) % 1000), tcpstates[ostate],
|
||||||
tanames[act]);
|
tanames[act]);
|
||||||
switch (act) {
|
switch (act) {
|
||||||
case TA_INPUT:
|
case TA_INPUT:
|
||||||
case TA_OUTPUT:
|
case TA_OUTPUT:
|
||||||
case TA_DROP:
|
case TA_DROP:
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
if (nopkt != 0)
|
if (nopkt)
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
if (aflag) {
|
if (aflag) {
|
||||||
printf("(src=%s,%u, ",
|
printf("(src=%s,%u, ",
|
||||||
|
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
isipv6
|
isipv6 ? inet_ntop(AF_INET6, &ip6->ip6_src,
|
||||||
? inet_ntop(AF_INET6, &ip6->ip6_src, ntop_buf,
|
ntop_buf, sizeof(ntop_buf)) :
|
||||||
sizeof(ntop_buf)) :
|
|
||||||
#endif
|
#endif
|
||||||
inet_ntoa(ip4->ip_src),
|
inet_ntoa(ip4->ip_src), ntohs(th->th_sport));
|
||||||
ntohs(th->th_sport));
|
|
||||||
printf("dst=%s,%u)",
|
printf("dst=%s,%u)",
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
isipv6
|
isipv6 ? inet_ntop(AF_INET6, &ip6->ip6_dst,
|
||||||
? inet_ntop(AF_INET6, &ip6->ip6_dst, ntop_buf,
|
ntop_buf, sizeof(ntop_buf)) :
|
||||||
sizeof(ntop_buf)) :
|
|
||||||
#endif
|
#endif
|
||||||
inet_ntoa(ip4->ip_dst),
|
inet_ntoa(ip4->ip_dst), ntohs(th->th_dport));
|
||||||
ntohs(th->th_dport));
|
|
||||||
}
|
}
|
||||||
seq = th->th_seq;
|
seq = th->th_seq;
|
||||||
ack = th->th_ack;
|
ack = th->th_ack;
|
||||||
|
|
||||||
len =
|
len =
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
isipv6 ? ip6->ip6_plen :
|
isipv6 ? ip6->ip6_plen :
|
||||||
#endif
|
#endif
|
||||||
ip4->ip_len;
|
ip4->ip_len;
|
||||||
win = th->th_win;
|
win = th->th_win;
|
||||||
if (act == TA_OUTPUT) {
|
if (act == TA_OUTPUT) {
|
||||||
seq = ntohl(seq);
|
seq = ntohl(seq);
|
||||||
@ -421,23 +423,21 @@ tcp_trace(short act, short ostate, struct tcpcb *tp, int family __unused,
|
|||||||
(u_long)tp->snd_una, (u_long)tp->snd_nxt,
|
(u_long)tp->snd_una, (u_long)tp->snd_nxt,
|
||||||
(u_long)tp->snd_max);
|
(u_long)tp->snd_max);
|
||||||
printf("\tsnd_wl1 %lx snd_wl2 %lx snd_wnd %lx\n",
|
printf("\tsnd_wl1 %lx snd_wl2 %lx snd_wnd %lx\n",
|
||||||
(u_long)tp->snd_wl1,
|
(u_long)tp->snd_wl1, (u_long)tp->snd_wl2,
|
||||||
(u_long)tp->snd_wl2, (u_long)tp->snd_wnd);
|
(u_long)tp->snd_wnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
numeric(v1, v2)
|
numeric(const void *v1, const void *v2)
|
||||||
const void *v1, *v2;
|
|
||||||
{
|
{
|
||||||
const caddr_t *c1 = v1, *c2 = v2;
|
const caddr_t *c1 = v1, *c2 = v2;
|
||||||
return(*c1 - *c2);
|
|
||||||
|
return (*c1 - *c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
klseek(fd, base, off)
|
klseek(int fd, off_t base, int off)
|
||||||
int fd, off;
|
|
||||||
off_t base;
|
|
||||||
{
|
{
|
||||||
(void)lseek(fd, base, off);
|
(void)lseek(fd, base, off);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user