make 'forceexit' more fprintf-like, better error message when ioctl fails.
This commit is contained in:
18
nethogs.cpp
18
nethogs.cpp
@@ -10,6 +10,7 @@
|
||||
#include <signal.h>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip6.h>
|
||||
@@ -200,21 +201,16 @@ void quit_cb (int i)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void forceExit(const char *msg)
|
||||
{
|
||||
forceExit (msg, NULL);
|
||||
}
|
||||
|
||||
void forceExit(const char *msg, const char* msg2)
|
||||
void forceExit(const char *msg, ...)
|
||||
{
|
||||
if ((!tracemode)&&(!DEBUG)){
|
||||
exit_ui();
|
||||
}
|
||||
std::cerr << msg;
|
||||
if (msg2 != NULL)
|
||||
{
|
||||
std::cerr << msg2;
|
||||
}
|
||||
|
||||
va_list argp;
|
||||
va_start(argp, msg);
|
||||
vfprintf(stderr, msg, argp);
|
||||
va_end(argp);
|
||||
std::cerr << std::endl;
|
||||
|
||||
exit(0);
|
||||
|
||||
@@ -47,8 +47,7 @@
|
||||
|
||||
#define PROGNAME_WIDTH 27
|
||||
|
||||
void forceExit(const char *msg);
|
||||
void forceExit(const char *msg, const char* msg2);
|
||||
void forceExit(const char *msg, ...);
|
||||
|
||||
class local_addr {
|
||||
public:
|
||||
|
||||
@@ -43,7 +43,7 @@ void getLocal (const char *device, bool tracemode)
|
||||
}
|
||||
strcpy(iFreq.ifr_name, device);
|
||||
if(ioctl(sock, SIOCGIFADDR, &iFreq)<0){
|
||||
forceExit("ioctl failed while establishing local IP for selected device ", device);
|
||||
forceExit("ioctl failed while establishing local IP for selected device %s. You may specify the device on the command line.", device);
|
||||
}
|
||||
saddr=(struct sockaddr_in*)&iFreq.ifr_addr;
|
||||
local_addrs = new local_addr (saddr->sin_addr.s_addr, local_addrs);
|
||||
|
||||
Reference in New Issue
Block a user