diff --git a/Makefile b/Makefile index dcb5e43..9f9982b 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ all: nethogs #CFLAGS=-g -Wall CFLAGS=-O2 -OBJS=structs.o packet.o connection.o process.o refresh.o decpcap.o cui.o inode2prog.o +OBJS=packet.o connection.o process.o refresh.o decpcap.o cui.o inode2prog.o .PHONY: tgz tgz: clean @@ -33,8 +33,6 @@ nethogs: nethogs.cpp $(OBJS) refresh.o: refresh.cpp refresh.h nethogs.h $(CXX) $(CFLAGS) -c refresh.cpp -structs.o: structs.cpp structs.h nethogs.h - $(CXX) $(CFLAGS) -c structs.cpp process.o: process.cpp process.h nethogs.h $(CXX) $(CFLAGS) -c process.cpp packet.o: packet.cpp packet.h nethogs.h diff --git a/nethogs.cpp b/nethogs.cpp index 135fb13..d9f9980 100644 --- a/nethogs.cpp +++ b/nethogs.cpp @@ -203,11 +203,22 @@ void quit_cb (int i) } void forceExit(const char *msg) +{ + forceExit (msg, NULL); +} + +void forceExit(const char *msg, const char* msg2) { if ((!tracemode)&&(!DEBUG)){ exit_ui(); } - std::cerr << msg << std::endl; + std::cerr << msg; + if (msg2 != NULL) + { + std::cerr << msg2; + } + std::cerr << std::endl; + exit(0); } @@ -299,7 +310,9 @@ int main (int argc, char** argv) } if (devices == NULL) + { devices = new device (strdup("eth0")); + } if ((!tracemode) && (!DEBUG)){ init_ui(); diff --git a/nethogs.h b/nethogs.h index 873ca0b..27e3364 100644 --- a/nethogs.h +++ b/nethogs.h @@ -48,6 +48,7 @@ #define PROGNAME_WIDTH 27 void forceExit(const char *msg); +void forceExit(const char *msg, const char* msg2); class local_addr { public: diff --git a/packet.cpp b/packet.cpp index 7b9aac9..a858be3 100644 --- a/packet.cpp +++ b/packet.cpp @@ -38,12 +38,12 @@ void getLocal (const char *device, bool tracemode) struct ifreq iFreq; struct sockaddr_in *saddr; - if((sock=socket(AF_INET, SOCK_PACKET, htons(0x0806)))<0){ + if((sock=socket(AF_INET, SOCK_RAW, htons(0x0806)))<0){ forceExit("creating socket failed while establishing local IP - are you root?"); } strcpy(iFreq.ifr_name, device); if(ioctl(sock, SIOCGIFADDR, &iFreq)<0){ - forceExit("ioctl failed while establishing local IP"); + forceExit("ioctl failed while establishing local IP for device ", device); } saddr=(struct sockaddr_in*)&iFreq.ifr_addr; local_addrs = new local_addr (saddr->sin_addr.s_addr, local_addrs);