1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#ifndef __PROCESS_H
#define __PROCESS_H
#include <assert.h>
#include "nethogs.h"
#include "connection.h"
extern bool tracemode;
void check_all_procs ();
class ConnList
{
public:
ConnList (Connection * m_val, ConnList * m_next)
{
if (!ROBUST)
assert (m_val != NULL);
val = m_val; next = m_next;
}
~ConnList ()
{
/* does not delete its value, to allow a connection to
* remove itself from the global connlist in its destructor */
}
Connection * getVal ()
{
return val;
}
void setNext (ConnList * m_next)
{
next = m_next;
}
ConnList * getNext ()
{
return next;
}
private:
Connection * val;
ConnList * next;
};
class Process
{
public:
/* the process makes a copy of the device name and name. */
Process (unsigned long m_inode, char * m_devicename, char * m_name = NULL)
{
//std::cout << "ARN: Process created with dev " << m_devicename << std::endl;
if (DEBUG)
std::cout << "PROC: Process created at " << this << std::endl;
inode = m_inode;
if (m_name == NULL)
name = NULL;
else
name = strdup(m_name);
devicename = strdup(m_devicename);
connections = NULL;
pid = 0;
uid = 0;
}
void check () {
if (!ROBUST) {
assert (pid >= 0);
assert (uid >= 0);
}
}
~Process ()
{
free (name);
free (devicename);
if (DEBUG)
std::cout << "PROC: Process deleted at " << this << std::endl;
}
int getLastPacket ();
char * name;
char * devicename;
int pid;
unsigned long inode;
ConnList * connections;
uid_t getUid()
{
return uid;
}
void setUid(uid_t m_uid)
{
assert (m_uid >= 0);
uid = m_uid;
}
private:
uid_t uid;
};
class ProcList
{
public:
ProcList (Process * m_val, ProcList * m_next)
{
if (!ROBUST)
assert (m_val != NULL);
val = m_val; next = m_next;
}
int size ();
Process * getVal () { return val; }
ProcList * getNext () { return next; }
ProcList * next;
private:
Process * val;
};
Process * getProcess (Connection * connection, char * devicename = NULL);
void process_init ();
void refreshconninode ();
void procclean ();
#endif
|