some 'const' specifications, putting the code to determine the default device
in its own file
This commit is contained in:
4
Makefile
4
Makefile
@@ -13,7 +13,7 @@ all: nethogs decpcap_test
|
|||||||
|
|
||||||
CFLAGS=-g -Wall -Wextra
|
CFLAGS=-g -Wall -Wextra
|
||||||
#CFLAGS=-O2
|
#CFLAGS=-O2
|
||||||
OBJS=packet.o connection.o process.o refresh.o decpcap.o cui.o inode2prog.o conninode.o
|
OBJS=packet.o connection.o process.o refresh.o decpcap.o cui.o inode2prog.o conninode.o devices.o
|
||||||
.PHONY: tgz
|
.PHONY: tgz
|
||||||
|
|
||||||
tgz: clean
|
tgz: clean
|
||||||
@@ -53,6 +53,8 @@ inode2prog.o: inode2prog.cpp inode2prog.h nethogs.h
|
|||||||
$(CXX) $(CFLAGS) -c inode2prog.cpp
|
$(CXX) $(CFLAGS) -c inode2prog.cpp
|
||||||
conninode.o: conninode.cpp nethogs.h conninode.h
|
conninode.o: conninode.cpp nethogs.h conninode.h
|
||||||
$(CXX) $(CFLAGS) -c conninode.cpp
|
$(CXX) $(CFLAGS) -c conninode.cpp
|
||||||
|
#devices.o: devices.cpp devices.h
|
||||||
|
# $(CXX) $(CFLAGS) -c devices.cpp
|
||||||
cui.o: cui.cpp cui.h nethogs.h
|
cui.o: cui.cpp cui.h nethogs.h
|
||||||
$(CXX) $(CFLAGS) -c cui.cpp -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
|
$(CXX) $(CFLAGS) -c cui.cpp -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ struct dp_handle * dp_open_offline(char * fname, char * ebuf)
|
|||||||
return dp_fillhandle(temp);
|
return dp_fillhandle(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dp_handle * dp_open_live(char * device, int snaplen, int promisc, int to_ms, char * ebuf)
|
struct dp_handle * dp_open_live(const char * device, int snaplen, int promisc, int to_ms, const char * ebuf)
|
||||||
{
|
{
|
||||||
pcap_t * temp = pcap_open_live(device, snaplen, promisc, to_ms, ebuf);
|
pcap_t * temp = pcap_open_live(device, snaplen, promisc, to_ms, ebuf);
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ struct dp_handle {
|
|||||||
|
|
||||||
/* functions to set up a handle (which is basically just a pcap handle) */
|
/* functions to set up a handle (which is basically just a pcap handle) */
|
||||||
|
|
||||||
struct dp_handle * dp_open_live(char * device, int snaplen, int promisc, int to_ms, char * ebuf);
|
struct dp_handle * dp_open_live(const char * device, int snaplen, int promisc, int to_ms, const char * ebuf);
|
||||||
struct dp_handle * dp_open_offline(char * fname, char * ebuf);
|
struct dp_handle * dp_open_offline(char * fname, char * ebuf);
|
||||||
|
|
||||||
/* functions to add callbacks */
|
/* functions to add callbacks */
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ extern "C" {
|
|||||||
#include "decpcap.h"
|
#include "decpcap.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
int process_tcp (u_char * userdata, const dp_header * header, const u_char * m_packet) {
|
int process_tcp (u_char * /* userdata */, const dp_header * /* header */, const u_char * /* m_packet */) {
|
||||||
std::cout << "Callback for processing TCP packet called" << std::endl;
|
std::cout << "Callback for processing TCP packet called" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
7
devices.cpp
Normal file
7
devices.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "devices.h"
|
||||||
|
|
||||||
|
device * determine_default_device()
|
||||||
|
{
|
||||||
|
return new device("eth0");
|
||||||
|
}
|
||||||
|
|
||||||
13
devices.h
Normal file
13
devices.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include <cstddef> // NULL
|
||||||
|
|
||||||
|
class device {
|
||||||
|
public:
|
||||||
|
device (const char * m_name, device * m_next = NULL)
|
||||||
|
{
|
||||||
|
name = m_name; next = m_next;
|
||||||
|
}
|
||||||
|
const char * name;
|
||||||
|
device * next;
|
||||||
|
};
|
||||||
|
|
||||||
|
device * determine_default_device();
|
||||||
25
nethogs.cpp
25
nethogs.cpp
@@ -28,6 +28,7 @@ extern "C" {
|
|||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "refresh.h"
|
#include "refresh.h"
|
||||||
|
#include "devices.h"
|
||||||
|
|
||||||
extern Process * unknownudp;
|
extern Process * unknownudp;
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ bool needrefresh = true;
|
|||||||
//dp_link_type linktype = dp_link_ethernet;
|
//dp_link_type linktype = dp_link_ethernet;
|
||||||
const char version[] = " version " VERSION "." SUBVERSION "." MINORVERSION;
|
const char version[] = " version " VERSION "." SUBVERSION "." MINORVERSION;
|
||||||
|
|
||||||
char * currentdevice = NULL;
|
const char * currentdevice = NULL;
|
||||||
|
|
||||||
timeval curtime;
|
timeval curtime;
|
||||||
|
|
||||||
@@ -172,7 +173,7 @@ int process_udp (u_char * userdata, const dp_header * header, const u_char * m_p
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int process_ip (u_char * userdata, const dp_header * header, const u_char * m_packet) {
|
int process_ip (u_char * userdata, const dp_header * /* header */, const u_char * m_packet) {
|
||||||
struct dpargs * args = (struct dpargs *) userdata;
|
struct dpargs * args = (struct dpargs *) userdata;
|
||||||
struct ip * ip = (struct ip *) m_packet;
|
struct ip * ip = (struct ip *) m_packet;
|
||||||
args->sa_family = AF_INET;
|
args->sa_family = AF_INET;
|
||||||
@@ -183,7 +184,7 @@ int process_ip (u_char * userdata, const dp_header * header, const u_char * m_pa
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int process_ip6 (u_char * userdata, const dp_header * header, const u_char * m_packet) {
|
int process_ip6 (u_char * userdata, const dp_header * /* header */, const u_char * m_packet) {
|
||||||
struct dpargs * args = (struct dpargs *) userdata;
|
struct dpargs * args = (struct dpargs *) userdata;
|
||||||
const struct ip6_hdr * ip6 = (struct ip6_hdr *) m_packet;
|
const struct ip6_hdr * ip6 = (struct ip6_hdr *) m_packet;
|
||||||
args->sa_family = AF_INET6;
|
args->sa_family = AF_INET6;
|
||||||
@@ -194,7 +195,7 @@ int process_ip6 (u_char * userdata, const dp_header * header, const u_char * m_p
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void quit_cb (int i)
|
void quit_cb (int /* i */)
|
||||||
{
|
{
|
||||||
procclean();
|
procclean();
|
||||||
if ((!tracemode) && (!DEBUG))
|
if ((!tracemode) && (!DEBUG))
|
||||||
@@ -240,24 +241,14 @@ static void help(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class device {
|
|
||||||
public:
|
|
||||||
device (char * m_name, device * m_next = NULL)
|
|
||||||
{
|
|
||||||
name = m_name; next = m_next;
|
|
||||||
}
|
|
||||||
char * name;
|
|
||||||
device * next;
|
|
||||||
};
|
|
||||||
|
|
||||||
class handle {
|
class handle {
|
||||||
public:
|
public:
|
||||||
handle (dp_handle * m_handle, char * m_devicename = NULL,
|
handle (dp_handle * m_handle, const char * m_devicename = NULL,
|
||||||
handle * m_next = NULL) {
|
handle * m_next = NULL) {
|
||||||
content = m_handle; next = m_next; devicename = m_devicename;
|
content = m_handle; next = m_next; devicename = m_devicename;
|
||||||
}
|
}
|
||||||
dp_handle * content;
|
dp_handle * content;
|
||||||
char * devicename;
|
const char * devicename;
|
||||||
handle * next;
|
handle * next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -313,7 +304,7 @@ int main (int argc, char** argv)
|
|||||||
|
|
||||||
if (devices == NULL)
|
if (devices == NULL)
|
||||||
{
|
{
|
||||||
devices = new device (strdup("eth0"));
|
devices = determine_default_device();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!tracemode) && (!DEBUG)){
|
if ((!tracemode) && (!DEBUG)){
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ void check_all_procs ()
|
|||||||
* if the inode is not associated with any PID, return the unknown process
|
* if the inode is not associated with any PID, return the unknown process
|
||||||
* if the process is not yet in the proclist, add it
|
* if the process is not yet in the proclist, add it
|
||||||
*/
|
*/
|
||||||
Process * getProcess (unsigned long inode, char * devicename)
|
Process * getProcess (unsigned long inode, const char * devicename)
|
||||||
{
|
{
|
||||||
struct prg_node * node = findPID(inode);
|
struct prg_node * node = findPID(inode);
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ Process * getProcess (unsigned long inode, char * devicename)
|
|||||||
* is made. If no process can be found even then, it's added to the
|
* is made. If no process can be found even then, it's added to the
|
||||||
* 'unknown' process.
|
* 'unknown' process.
|
||||||
*/
|
*/
|
||||||
Process * getProcess (Connection * connection, char * devicename)
|
Process * getProcess (Connection * connection, const char * devicename)
|
||||||
{
|
{
|
||||||
unsigned long inode = conninode[connection->refpacket->gethashstring()];
|
unsigned long inode = conninode[connection->refpacket->gethashstring()];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user