* when a packet's owner cannot be found (for example if it has already disappeared,

which can happen with for example small fast HTTP requests), show the source and
  destination ports and ip's
* support UDP packets (which never have owners)
* nicely truncate oversized program names
This commit is contained in:
Arnout Engelen
2005-08-27 11:49:16 +00:00
parent c4ac4e55eb
commit 4182fc0b17
5 changed files with 138 additions and 30 deletions

32
cui.cpp
View File

@@ -12,7 +12,10 @@ std::string * caption;
const char version[] = " version " VERSION "." SUBVERSION "." MINORVERSION;
extern ProcList * processes;
extern timeval curtime;
extern Process * unknownproc;
extern Process * unknowntcp;
extern Process * unknownudp;
extern Process * unknownip;
class Line
{
@@ -74,6 +77,7 @@ void Line::show (int row)
{
assert (m_uid >= 0);
assert (m_pid >= 0);
assert (m_pid <= 100000);
}
if (DEBUG || tracemode)
@@ -86,7 +90,17 @@ void Line::show (int row)
char * username = uid2username(m_uid);
mvprintw (3+row, 6, "%s", username);
free (username);
mvprintw (3+row, 6 + 9, "%s", m_name);
if (strlen (m_name) > PROGNAME_WIDTH) {
// truncate oversized names
char * tmp = strdup(m_name);
char * start = tmp + strlen (m_name) - PROGNAME_WIDTH;
start[0] = '.';
start[1] = '.';
mvprintw (3+row, 6 + 9, "%s", start);
free (tmp);
} else {
mvprintw (3+row, 6 + 9, "%s", m_name);
}
mvprintw (3+row, 6 + 9 + PROGNAME_WIDTH + 2, "%s", devicename);
mvprintw (3+row, 6 + 9 + PROGNAME_WIDTH + 2 + 6, "%10.3f", sent_kbps);
mvprintw (3+row, 6 + 9 + PROGNAME_WIDTH + 2 + 6 + 9 + 3, "%10.3f", recv_kbps);
@@ -193,10 +207,12 @@ void do_refresh()
assert (curproc->getVal() != NULL);
assert (nproc == processes->size());
}
/* do not remove the unknown process */
if ((curproc->getVal()->getLastPacket() + PROCESSTIMEOUT <= curtime.tv_sec) && (curproc->getVal() != unknownproc))
/* remove timed-out processes (unless it's the unknown process) */
if ((curproc->getVal()->getLastPacket() + PROCESSTIMEOUT <= curtime.tv_sec)
&& (curproc->getVal() != unknowntcp)
&& (curproc->getVal() != unknownudp)
&& (curproc->getVal() != unknownip))
{
/* remove process */
if (DEBUG)
std::cout << "PROC: Deleting process\n";
ProcList * todelete = curproc;
@@ -220,8 +236,8 @@ void do_refresh()
u_int32_t sum_sent = 0,
sum_recv = 0;
/* walk though all this process's connections, and sum them
* up */
/* walk though all this process's connections, and sum
* them up */
ConnList * curconn = curproc->getVal()->connections;
ConnList * previous = NULL;
while (curconn != NULL)
@@ -286,7 +302,7 @@ void do_refresh()
}
if (tracemode || DEBUG) {
/* print the 'unknown' connections, for debugging */
ConnList * curr_unknownconn = unknownproc->connections;
ConnList * curr_unknownconn = unknowntcp->connections;
while (curr_unknownconn != NULL) {
std::cout << "Unknown connection: " <<
curr_unknownconn->getVal()->refpacket->gethashstring() << std::endl;