version 1.10, 1997/12/19 09:36:50 |
version 1.11, 1999/12/08 10:50:04 |
|
|
} |
} |
|
|
struct netinfo { |
struct netinfo { |
struct netinfo *ni_forw, *ni_prev; |
struct netinfo *nif_forw, *nif_prev; |
short ni_line; /* line on screen */ |
short nif_line; /* line on screen */ |
short ni_seen; /* 0 when not present in list */ |
short nif_seen; /* 0 when not present in list */ |
short ni_flags; |
short nif_flags; |
#define NIF_LACHG 0x1 /* local address changed */ |
#define NIF_LACHG 0x1 /* local address changed */ |
#define NIF_FACHG 0x2 /* foreign address changed */ |
#define NIF_FACHG 0x2 /* foreign address changed */ |
short ni_state; /* tcp state */ |
short nif_state; /* tcp state */ |
char *ni_proto; /* protocol */ |
char *nif_proto; /* protocol */ |
struct in_addr ni_laddr; /* local address */ |
struct in_addr nif_laddr; /* local address */ |
long ni_lport; /* local port */ |
long nif_lport; /* local port */ |
struct in_addr ni_faddr; /* foreign address */ |
struct in_addr nif_faddr; /* foreign address */ |
long ni_fport; /* foreign port */ |
long nif_fport; /* foreign port */ |
long ni_rcvcc; /* rcv buffer character count */ |
long nif_rcvcc; /* rcv buffer character count */ |
long ni_sndcc; /* snd buffer character count */ |
long nif_sndcc; /* snd buffer character count */ |
}; |
}; |
|
|
static struct { |
static struct { |
struct netinfo *ni_forw, *ni_prev; |
struct netinfo *nif_forw, *nif_prev; |
} netcb; |
} netcb; |
|
|
static int aflag = 0; |
static int aflag = 0; |
|
|
|
|
endhostent(); |
endhostent(); |
endnetent(); |
endnetent(); |
p = (struct netinfo *)netcb.ni_forw; |
p = (struct netinfo *)netcb.nif_forw; |
while (p != (struct netinfo *)&netcb) { |
while (p != (struct netinfo *)&netcb) { |
if (p->ni_line != -1) |
if (p->nif_line != -1) |
lastrow--; |
lastrow--; |
p->ni_line = -1; |
p->nif_line = -1; |
p = p->ni_forw; |
p = p->nif_forw; |
} |
} |
if (w != NULL) { |
if (w != NULL) { |
wclear(w); |
wclear(w); |
|
|
error("No symbols in namelist"); |
error("No symbols in namelist"); |
return(0); |
return(0); |
} |
} |
netcb.ni_forw = netcb.ni_prev = (struct netinfo *)&netcb; |
netcb.nif_forw = netcb.nif_prev = (struct netinfo *)&netcb; |
protos = TCP|UDP; |
protos = TCP|UDP; |
return(1); |
return(1); |
} |
} |
|
|
|
|
if (namelist[X_TCBTABLE].n_value == 0) |
if (namelist[X_TCBTABLE].n_value == 0) |
return; |
return; |
for (p = netcb.ni_forw; p != (struct netinfo *)&netcb; p = p->ni_forw) |
for (p = netcb.nif_forw; p != (struct netinfo *)&netcb; p = p->nif_forw) |
p->ni_seen = 0; |
p->nif_seen = 0; |
if (protos&TCP) { |
if (protos&TCP) { |
off = NPTR(X_TCBTABLE); |
off = NPTR(X_TCBTABLE); |
istcp = 1; |
istcp = 1; |
|
|
KREAD(next, &inpcb, sizeof (inpcb)); |
KREAD(next, &inpcb, sizeof (inpcb)); |
if (inpcb.inp_queue.cqe_prev != prev) { |
if (inpcb.inp_queue.cqe_prev != prev) { |
printf("prev = %x, head = %x, next = %x, inpcb...prev = %x\n", prev, head, next, inpcb.inp_queue.cqe_prev); |
printf("prev = %x, head = %x, next = %x, inpcb...prev = %x\n", prev, head, next, inpcb.inp_queue.cqe_prev); |
p = netcb.ni_forw; |
p = netcb.nif_forw; |
for (; p != (struct netinfo *)&netcb; p = p->ni_forw) |
for (; p != (struct netinfo *)&netcb; p = p->nif_forw) |
p->ni_seen = 1; |
p->nif_seen = 1; |
error("Kernel state in transition"); |
error("Kernel state in transition"); |
return; |
return; |
} |
} |
|
|
* will appear as ``not seen'' in the kernel |
* will appear as ``not seen'' in the kernel |
* data structures. |
* data structures. |
*/ |
*/ |
for (p = netcb.ni_forw; p != (struct netinfo *)&netcb; p = p->ni_forw) { |
for (p = netcb.nif_forw; |
if (!streq(proto, p->ni_proto)) |
p != (struct netinfo *)&netcb; |
|
p = p->nif_forw) { |
|
if (!streq(proto, p->nif_proto)) |
continue; |
continue; |
if (p->ni_lport != inp->inp_lport || |
if (p->nif_lport != inp->inp_lport || |
p->ni_laddr.s_addr != inp->inp_laddr.s_addr) |
p->nif_laddr.s_addr != inp->inp_laddr.s_addr) |
continue; |
continue; |
if (p->ni_faddr.s_addr == inp->inp_faddr.s_addr && |
if (p->nif_faddr.s_addr == inp->inp_faddr.s_addr && |
p->ni_fport == inp->inp_fport) |
p->nif_fport == inp->inp_fport) |
break; |
break; |
} |
} |
if (p == (struct netinfo *)&netcb) { |
if (p == (struct netinfo *)&netcb) { |
|
|
error("Out of memory"); |
error("Out of memory"); |
return; |
return; |
} |
} |
p->ni_prev = (struct netinfo *)&netcb; |
p->nif_prev = (struct netinfo *)&netcb; |
p->ni_forw = netcb.ni_forw; |
p->nif_forw = netcb.nif_forw; |
netcb.ni_forw->ni_prev = p; |
netcb.nif_forw->nif_prev = p; |
netcb.ni_forw = p; |
netcb.nif_forw = p; |
p->ni_line = -1; |
p->nif_line = -1; |
p->ni_laddr = inp->inp_laddr; |
p->nif_laddr = inp->inp_laddr; |
p->ni_lport = inp->inp_lport; |
p->nif_lport = inp->inp_lport; |
p->ni_faddr = inp->inp_faddr; |
p->nif_faddr = inp->inp_faddr; |
p->ni_fport = inp->inp_fport; |
p->nif_fport = inp->inp_fport; |
p->ni_proto = proto; |
p->nif_proto = proto; |
p->ni_flags = NIF_LACHG|NIF_FACHG; |
p->nif_flags = NIF_LACHG|NIF_FACHG; |
} |
} |
p->ni_rcvcc = so->so_rcv.sb_cc; |
p->nif_rcvcc = so->so_rcv.sb_cc; |
p->ni_sndcc = so->so_snd.sb_cc; |
p->nif_sndcc = so->so_snd.sb_cc; |
p->ni_state = state; |
p->nif_state = state; |
p->ni_seen = 1; |
p->nif_seen = 1; |
} |
} |
|
|
/* column locations */ |
/* column locations */ |
|
|
* away and adjust the position of connections |
* away and adjust the position of connections |
* below to reflect the deleted line. |
* below to reflect the deleted line. |
*/ |
*/ |
p = netcb.ni_forw; |
p = netcb.nif_forw; |
while (p != (struct netinfo *)&netcb) { |
while (p != (struct netinfo *)&netcb) { |
if (p->ni_line == -1 || p->ni_seen) { |
if (p->nif_line == -1 || p->nif_seen) { |
p = p->ni_forw; |
p = p->nif_forw; |
continue; |
continue; |
} |
} |
wmove(wnd, p->ni_line, 0); wdeleteln(wnd); |
wmove(wnd, p->nif_line, 0); wdeleteln(wnd); |
q = netcb.ni_forw; |
q = netcb.nif_forw; |
for (; q != (struct netinfo *)&netcb; q = q->ni_forw) |
for (; q != (struct netinfo *)&netcb; q = q->nif_forw) |
if (q != p && q->ni_line > p->ni_line) { |
if (q != p && q->nif_line > p->nif_line) { |
q->ni_line--; |
q->nif_line--; |
/* this shouldn't be necessary */ |
/* this shouldn't be necessary */ |
q->ni_flags |= NIF_LACHG|NIF_FACHG; |
q->nif_flags |= NIF_LACHG|NIF_FACHG; |
} |
} |
lastrow--; |
lastrow--; |
q = p->ni_forw; |
q = p->nif_forw; |
p->ni_prev->ni_forw = p->ni_forw; |
p->nif_prev->nif_forw = p->nif_forw; |
p->ni_forw->ni_prev = p->ni_prev; |
p->nif_forw->nif_prev = p->nif_prev; |
free(p); |
free(p); |
p = q; |
p = q; |
} |
} |
/* |
/* |
* Update existing connections and add new ones. |
* Update existing connections and add new ones. |
*/ |
*/ |
for (p = netcb.ni_forw; p != (struct netinfo *)&netcb; p = p->ni_forw) { |
for (p = netcb.nif_forw; |
if (p->ni_line == -1) { |
p != (struct netinfo *)&netcb; |
|
p = p->nif_forw) { |
|
if (p->nif_line == -1) { |
/* |
/* |
* Add a new entry if possible. |
* Add a new entry if possible. |
*/ |
*/ |
if (lastrow > YMAX(wnd)) |
if (lastrow > YMAX(wnd)) |
continue; |
continue; |
p->ni_line = lastrow++; |
p->nif_line = lastrow++; |
p->ni_flags |= NIF_LACHG|NIF_FACHG; |
p->nif_flags |= NIF_LACHG|NIF_FACHG; |
} |
} |
if (p->ni_flags & NIF_LACHG) { |
if (p->nif_flags & NIF_LACHG) { |
wmove(wnd, p->ni_line, LADDR); |
wmove(wnd, p->nif_line, LADDR); |
inetprint(&p->ni_laddr, p->ni_lport, p->ni_proto); |
inetprint(&p->nif_laddr, p->nif_lport, p->nif_proto); |
p->ni_flags &= ~NIF_LACHG; |
p->nif_flags &= ~NIF_LACHG; |
} |
} |
if (p->ni_flags & NIF_FACHG) { |
if (p->nif_flags & NIF_FACHG) { |
wmove(wnd, p->ni_line, FADDR); |
wmove(wnd, p->nif_line, FADDR); |
inetprint(&p->ni_faddr, p->ni_fport, p->ni_proto); |
inetprint(&p->nif_faddr, p->nif_fport, p->nif_proto); |
p->ni_flags &= ~NIF_FACHG; |
p->nif_flags &= ~NIF_FACHG; |
} |
} |
mvwaddstr(wnd, p->ni_line, PROTO, p->ni_proto); |
mvwaddstr(wnd, p->nif_line, PROTO, p->nif_proto); |
mvwprintw(wnd, p->ni_line, RCVCC, "%6d", p->ni_rcvcc); |
mvwprintw(wnd, p->nif_line, RCVCC, "%6d", p->nif_rcvcc); |
mvwprintw(wnd, p->ni_line, SNDCC, "%6d", p->ni_sndcc); |
mvwprintw(wnd, p->nif_line, SNDCC, "%6d", p->nif_sndcc); |
if (streq(p->ni_proto, "tcp")) |
if (streq(p->nif_proto, "tcp")) |
if (p->ni_state < 0 || p->ni_state >= TCP_NSTATES) |
if (p->nif_state < 0 || p->nif_state >= TCP_NSTATES) |
mvwprintw(wnd, p->ni_line, STATE, "%d", |
mvwprintw(wnd, p->nif_line, STATE, "%d", |
p->ni_state); |
p->nif_state); |
else |
else |
mvwaddstr(wnd, p->ni_line, STATE, |
mvwaddstr(wnd, p->nif_line, STATE, |
tcpstates[p->ni_state]); |
tcpstates[p->nif_state]); |
wclrtoeol(wnd); |
wclrtoeol(wnd); |
} |
} |
if (lastrow < YMAX(wnd)) { |
if (lastrow < YMAX(wnd)) { |
|
|
new = prefix(cmd, "numbers"); |
new = prefix(cmd, "numbers"); |
if (new == nflag) |
if (new == nflag) |
return (1); |
return (1); |
p = netcb.ni_forw; |
p = netcb.nif_forw; |
for (; p != (struct netinfo *)&netcb; p = p->ni_forw) { |
for (; p != (struct netinfo *)&netcb; p = p->nif_forw) { |
if (p->ni_line == -1) |
if (p->nif_line == -1) |
continue; |
continue; |
p->ni_flags |= NIF_LACHG|NIF_FACHG; |
p->nif_flags |= NIF_LACHG|NIF_FACHG; |
} |
} |
nflag = new; |
nflag = new; |
wclear(wnd); |
wclear(wnd); |