some 'const' specifications, putting the code to determine the default device

in its own file
This commit is contained in:
Arnout Engelen
2011-07-12 21:53:54 +00:00
parent a50b249438
commit ff8151fe96
9 changed files with 37 additions and 24 deletions

View File

@@ -13,7 +13,7 @@ all: nethogs decpcap_test
CFLAGS=-g -Wall -Wextra
#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
tgz: clean
@@ -53,6 +53,8 @@ inode2prog.o: inode2prog.cpp inode2prog.h nethogs.h
$(CXX) $(CFLAGS) -c inode2prog.cpp
conninode.o: conninode.cpp nethogs.h conninode.h
$(CXX) $(CFLAGS) -c conninode.cpp
#devices.o: devices.cpp devices.h
# $(CXX) $(CFLAGS) -c devices.cpp
cui.o: cui.cpp cui.h nethogs.h
$(CXX) $(CFLAGS) -c cui.cpp -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"

View File

@@ -55,7 +55,7 @@ struct dp_handle * dp_open_offline(char * fname, char * ebuf)
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);

View File

@@ -40,7 +40,7 @@ struct dp_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);
/* functions to add callbacks */

View File

@@ -4,7 +4,7 @@ extern "C" {
#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;
return 0;
}

7
devices.cpp Normal file
View File

@@ -0,0 +1,7 @@
#include "devices.h"
device * determine_default_device()
{
return new device("eth0");
}

13
devices.h Normal file
View 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();

View File

@@ -28,6 +28,7 @@ extern "C" {
#include "connection.h"
#include "process.h"
#include "refresh.h"
#include "devices.h"
extern Process * unknownudp;
@@ -39,7 +40,7 @@ bool needrefresh = true;
//dp_link_type linktype = dp_link_ethernet;
const char version[] = " version " VERSION "." SUBVERSION "." MINORVERSION;
char * currentdevice = NULL;
const char * currentdevice = NULL;
timeval curtime;
@@ -172,7 +173,7 @@ int process_udp (u_char * userdata, const dp_header * header, const u_char * m_p
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 ip * ip = (struct ip *) m_packet;
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;
}
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;
const struct ip6_hdr * ip6 = (struct ip6_hdr *) m_packet;
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;
}
void quit_cb (int i)
void quit_cb (int /* i */)
{
procclean();
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 {
public:
handle (dp_handle * m_handle, char * m_devicename = NULL,
handle (dp_handle * m_handle, const char * m_devicename = NULL,
handle * m_next = NULL) {
content = m_handle; next = m_next; devicename = m_devicename;
}
dp_handle * content;
char * devicename;
const char * devicename;
handle * next;
};
@@ -313,7 +304,7 @@ int main (int argc, char** argv)
if (devices == NULL)
{
devices = new device (strdup("eth0"));
devices = determine_default_device();
}
if ((!tracemode) && (!DEBUG)){

View File

@@ -174,7 +174,7 @@ void check_all_procs ()
* if the inode is not associated with any PID, return the unknown process
* 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);
@@ -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
* 'unknown' process.
*/
Process * getProcess (Connection * connection, char * devicename)
Process * getProcess (Connection * connection, const char * devicename)
{
unsigned long inode = conninode[connection->refpacket->gethashstring()];

View File

@@ -109,7 +109,7 @@ private:
Process * val;
};
Process * getProcess (Connection * connection, char * devicename = NULL);
Process * getProcess (Connection * connection, const char * devicename = NULL);
void process_init ();