Use negative return values on errors

This commit is contained in:
Arnout Engelen
2012-03-15 20:53:25 +00:00
parent d7476faae1
commit 2c04ca9267
4 changed files with 7 additions and 7 deletions

View File

@@ -430,7 +430,7 @@ void do_refresh()
} }
else else
{ {
forceExit("Invalid viewmode"); forceExit("Invalid viewmode", -1);
} }
uid_t uid = curproc->getVal()->getUid(); uid_t uid = curproc->getVal()->getUid();
#ifndef NDEBUG #ifndef NDEBUG

View File

@@ -222,7 +222,7 @@ void quit_cb (int /* i */)
exit(0); exit(0);
} }
void forceExit(const char *msg, ...) void forceExit(const char *msg, int errcode, ...)
{ {
if ((!tracemode)&&(!DEBUG)){ if ((!tracemode)&&(!DEBUG)){
exit_ui(); exit_ui();
@@ -234,7 +234,7 @@ void forceExit(const char *msg, ...)
va_end(argp); va_end(argp);
std::cerr << std::endl; std::cerr << std::endl;
exit(0); exit(errcode);
} }
static void versiondisplay(void) static void versiondisplay(void)
@@ -331,7 +331,7 @@ int main (int argc, char** argv)
} }
if (NEEDROOT && (getuid() != 0)) if (NEEDROOT && (getuid() != 0))
forceExit("You need to be root to run NetHogs!"); forceExit("You need to be root to run NetHogs!", -2);
char errbuf[PCAP_ERRBUF_SIZE]; char errbuf[PCAP_ERRBUF_SIZE];

View File

@@ -63,7 +63,7 @@
#define PROGNAME_WIDTH 512 #define PROGNAME_WIDTH 512
void forceExit(const char *msg, ...); void forceExit(const char *msg, int errcode, ...);
class local_addr { class local_addr {
public: public:

View File

@@ -61,11 +61,11 @@ void getLocal (const char *device, bool tracemode)
struct sockaddr_in *saddr; struct sockaddr_in *saddr;
if((sock=socket(AF_INET, SOCK_RAW, htons(0x0806)))<0){ if((sock=socket(AF_INET, SOCK_RAW, htons(0x0806)))<0){
forceExit("creating socket failed while establishing local IP - are you root?"); forceExit("creating socket failed while establishing local IP - are you root?", -3);
} }
strcpy(iFreq.ifr_name, device); strcpy(iFreq.ifr_name, device);
if(ioctl(sock, SIOCGIFADDR, &iFreq)<0){ if(ioctl(sock, SIOCGIFADDR, &iFreq)<0){
forceExit("ioctl failed while establishing local IP for selected device %s. You may specify the device on the command line.", device); forceExit("ioctl failed while establishing local IP for selected device %s. You may specify the device on the command line.", -4, device);
} }
saddr=(struct sockaddr_in*)&iFreq.ifr_addr; saddr=(struct sockaddr_in*)&iFreq.ifr_addr;
local_addrs = new local_addr (saddr->sin_addr.s_addr, local_addrs); local_addrs = new local_addr (saddr->sin_addr.s_addr, local_addrs);