"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/vnstat_func.c" between
vnstat-2.8.tar.gz and vnstat-2.9.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

vnstat_func.c  (vnstat-2.8):vnstat_func.c  (vnstat-2.9)
skipping to change at line 44 skipping to change at line 44
p->interface[0] = '\0'; p->interface[0] = '\0';
p->alias[0] = '\0'; p->alias[0] = '\0';
p->newifname[0] = '\0'; p->newifname[0] = '\0';
p->filename[0] = '\0'; p->filename[0] = '\0';
p->definterface[0] = '\0'; p->definterface[0] = '\0';
p->cfgfile[0] = '\0'; p->cfgfile[0] = '\0';
p->jsonmode = 'a'; p->jsonmode = 'a';
p->xmlmode = 'a'; p->xmlmode = 'a';
p->databegin[0] = '\0'; p->databegin[0] = '\0';
p->dataend[0] = '\0'; p->dataend[0] = '\0';
p->alert = 0;
p->alertoutput = 0;
p->alertexit = 0;
p->alerttype = 0;
p->alertcondition = 0;
p->alertlimit = 0;
} }
void showhelp(PARAMS *p) void showhelp(PARAMS *p)
{ {
printf("vnStat %s by Teemu Toivola <tst at iki dot fi>\n\n", getversion() ); printf("vnStat %s by Teemu Toivola <tst at iki dot fi>\n\n", getversion() );
printf(" -5, --fiveminutes [limit] show 5 minutes\n"); printf(" -5, --fiveminutes [limit] show 5 minutes\n");
printf(" -h, --hours [limit] show hours\n"); printf(" -h, --hours [limit] show hours\n");
printf(" -hg, --hoursgraph show hours graph\n"); printf(" -hg, --hoursgraph show hours graph\n");
printf(" -d, --days [limit] show days\n"); printf(" -d, --days [limit] show days\n");
printf(" -m, --months [limit] show months\n"); printf(" -m, --months [limit] show months\n");
printf(" -y, --years [limit] show years\n"); printf(" -y, --years [limit] show years\n");
printf(" -t, --top [limit] show top days\n\n"); printf(" -t, --top [limit] show top days\n\n");
printf(" -b, --begin <date> set list begin date\n"); printf(" -b, --begin <date> set list begin date\n");
printf(" -e, --end <date> set list end date\n\n"); printf(" -e, --end <date> set list end date\n\n");
printf(" --oneline [mode] show simple parsable format\n" ); printf(" --oneline [mode] show simple parsable format\n" );
printf(" --json [mode] [limit] show database in json format\n "); printf(" --json [mode] [limit] show database in json format\n ");
printf(" --xml [mode] [limit] show database in xml format\n\ printf(" --xml [mode] [limit] show database in xml format\n"
n"); );
printf(" --alert <output> <exit> <type> <condition> <limit> <unit>\n
");
printf(" alert if limit is exceeded\n\n
");
printf(" -tr, --traffic [time] calculate traffic\n"); printf(" -tr, --traffic [time] calculate traffic\n");
printf(" -l, --live [mode] show transfer rate in real tim e\n"); printf(" -l, --live [mode] show transfer rate in real tim e\n");
printf(" -i, --iface <interface> select interface"); printf(" -i, --iface <interface> select interface");
if (strlen(p->definterface)) { if (strlen(p->definterface)) {
printf(" (default: %s)", p->definterface); printf(" (default: %s)", p->definterface);
} }
printf("\n\n"); printf("\n\n");
printf("Use \"--longhelp\" or \"man vnstat\" for complete list of options .\n"); printf("Use \"--longhelp\" or \"man vnstat\" for complete list of options .\n");
skipping to change at line 95 skipping to change at line 104
printf(" -h, --hours [limit] show hours\n"); printf(" -h, --hours [limit] show hours\n");
printf(" -hg, --hoursgraph show hours graph\n"); printf(" -hg, --hoursgraph show hours graph\n");
printf(" -d, --days [limit] show days\n"); printf(" -d, --days [limit] show days\n");
printf(" -m, --months [limit] show months\n"); printf(" -m, --months [limit] show months\n");
printf(" -y, --years [limit] show years\n"); printf(" -y, --years [limit] show years\n");
printf(" -t, --top [limit] show top days\n"); printf(" -t, --top [limit] show top days\n");
printf(" -b, --begin <date> set list begin date\n"); printf(" -b, --begin <date> set list begin date\n");
printf(" -e, --end <date> set list end date\n"); printf(" -e, --end <date> set list end date\n");
printf(" --oneline [mode] show simple parsable format\n" ); printf(" --oneline [mode] show simple parsable format\n" );
printf(" --json [mode] [limit] show database in json format\n "); printf(" --json [mode] [limit] show database in json format\n ");
printf(" --xml [mode] [limit] show database in xml format\n\ printf(" --xml [mode] [limit] show database in xml format\n"
n"); );
printf(" --alert <output> <exit> <type> <condition> <limit> <unit>\n
");
printf(" alert if limit is exceeded\n\n
");
printf("Modify:\n"); printf("Modify:\n");
printf(" --add add interface to database\n"); printf(" --add add interface to database\n");
printf(" --remove remove interface from database \n"); printf(" --remove remove interface from database \n");
printf(" --rename <name> rename interface in database\n "); printf(" --rename <name> rename interface in database\n ");
printf(" --setalias <alias> set alias for interface\n\n"); printf(" --setalias <alias> set alias for interface\n\n");
printf("Misc:\n"); printf("Misc:\n");
skipping to change at line 130 skipping to change at line 141
printf(" --dbiflist [mode] show list of interfaces in dat abase\n"); printf(" --dbiflist [mode] show list of interfaces in dat abase\n");
printf(" --dbdir <directory> select database directory\n"); printf(" --dbdir <directory> select database directory\n");
printf(" --locale <locale> set locale\n"); printf(" --locale <locale> set locale\n");
printf(" --config <config file> select config file\n"); printf(" --config <config file> select config file\n");
printf(" --showconfig dump config file with current settings\n"); printf(" --showconfig dump config file with current settings\n");
printf(" --longhelp show this help\n\n"); printf(" --longhelp show this help\n\n");
printf("See also \"man vnstat\" for longer descriptions of each option.\n "); printf("See also \"man vnstat\" for longer descriptions of each option.\n ");
} }
void parseargs(PARAMS *p, int argc, char **argv) void parseargs(PARAMS *p, const int argc, char **argv)
{ {
int currentarg; int currentarg;
/* parse parameters, maybe not the best way but... */ /* parse parameters, maybe not the best way but... */
for (currentarg = 1; currentarg < argc; currentarg++) { for (currentarg = 1; currentarg < argc; currentarg++) {
if (debug) if (debug)
printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]); printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]);
if (strcmp(argv[currentarg], "--longhelp") == 0) { if (strcmp(argv[currentarg], "--longhelp") == 0) {
showlonghelp(p); showlonghelp(p);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
skipping to change at line 423 skipping to change at line 434
p->renameiface = 1; p->renameiface = 1;
p->query = 0; p->query = 0;
currentarg++; currentarg++;
} else { } else {
printf("Error: New interface name for %s missing. \n", argv[currentarg]); printf("Error: New interface name for %s missing. \n", argv[currentarg]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[ currentarg], "--begin") == 0)) { } else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[ currentarg], "--begin") == 0)) {
if (currentarg + 1 < argc) { if (currentarg + 1 < argc) {
if (!validatedatetime(argv[currentarg + 1])) { if (!validatedatetime(argv[currentarg + 1])) {
printf("Error: Invalid date format, expec ted YYYY-MM-DD HH:MM or YYYY-MM-DD.\n"); printf("Error: Invalid date format, expec ted YYYY-MM-DD HH:MM, YYYY-MM-DD or \"today\".\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
strncpy_nt(p->databegin, argv[currentarg + 1], 18 ); strncpy_nt(p->databegin, argv[currentarg + 1], 18 );
currentarg++; currentarg++;
} else { } else {
printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]); printf("Error: Date of format YYYY-MM-DD HH:MM, Y YYY-MM-DD or \"today\" for %s missing.\n", argv[currentarg]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[ currentarg], "--end") == 0)) { } else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[ currentarg], "--end") == 0)) {
if (currentarg + 1 < argc) { if (currentarg + 1 < argc) {
if (!validatedatetime(argv[currentarg + 1])) { if (!validatedatetime(argv[currentarg + 1])) {
printf("Error: Invalid date format, expec ted YYYY-MM-DD HH:MM or YYYY-MM-DD.\n"); printf("Error: Invalid date format, expec ted YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
strncpy_nt(p->dataend, argv[currentarg + 1], 18); strncpy_nt(p->dataend, argv[currentarg + 1], 18);
currentarg++; currentarg++;
skipping to change at line 488 skipping to change at line 499
p->limit = atoi(argv[currentarg + 1]); p->limit = atoi(argv[currentarg + 1]);
if (p->limit < 0) { if (p->limit < 0) {
printf("Error: Invalid limit parameter \" %s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); printf("Error: Invalid limit parameter \" %s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
currentarg++; currentarg++;
} else { } else {
printf("Error: Invalid or missing parameter for % s.\n", argv[currentarg]); printf("Error: Invalid or missing parameter for % s.\n", argv[currentarg]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if (strcmp(argv[currentarg], "--alert") == 0) {
if (currentarg + 6 >= argc) {
printf("Error: Invalid parameter count for %s.\n"
, argv[currentarg]);
showalerthelp();
exit(EXIT_FAILURE);
}
if (!parsealertargs(p, argv + currentarg)) {
exit(EXIT_FAILURE);
} else {
currentarg += 6;
p->alert = 1;
}
} else if ((strcmp(argv[currentarg], "-v") == 0) || (strcmp(argv[ currentarg], "--version") == 0)) { } else if ((strcmp(argv[currentarg], "-v") == 0) || (strcmp(argv[ currentarg], "--version") == 0)) {
printf("vnStat %s by Teemu Toivola <tst at iki dot fi>\n" , getversion()); printf("vnStat %s by Teemu Toivola <tst at iki dot fi>\n" , getversion());
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} else { } else {
if (argv[currentarg][0] == '-' || strlen(argv[currentarg] ) == 1) { if (argv[currentarg][0] == '-' || strlen(argv[currentarg] ) == 1) {
printf("Unknown parameter \"%s\". Use --help for help.\n", argv[currentarg]); printf("Unknown parameter \"%s\". Use --help for help.\n", argv[currentarg]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} else { } else {
if (strlen(argv[currentarg]) > 31) { if (strlen(argv[currentarg]) > 31) {
printf("Error: Interface name is limited to 31 characters.\n"); printf("Error: Interface name is limited to 31 characters.\n");
skipping to change at line 517 skipping to change at line 540
printf("Used interface: \"%s\"\n", p->int erface); printf("Used interface: \"%s\"\n", p->int erface);
} }
} }
} }
if (p->limit != -1) { if (p->limit != -1) {
cfg.listfivemins = cfg.listhours = cfg.listdays = cfg.listmonths = cfg.listyears = cfg.listtop = cfg.listjsonxml = p->limit; cfg.listfivemins = cfg.listhours = cfg.listdays = cfg.listmonths = cfg.listyears = cfg.listtop = cfg.listjsonxml = p->limit;
} }
} }
int parsealertargs(PARAMS *p, char **argv)
{
int i, u, found, currentarg = 0;
uint64_t alertlimit = 0, unitmultiplier = 1;
int32_t unitmode = cfg.unitmode;
const char *alerttypes[] = {"h", "hour", "hourly", "d", "day", "daily", "
m", "month", "monthly", "y", "year", "yearly"};
const char *alertconditions[] = {"rx", "tx", "total", "rx_estimate", "tx_
estimate", "total_estimate"}; // order must match that of AlertCondition in dbsh
ow.h
for (i = 1; i <= 6; i++) {
if (argv[currentarg + i][0] == '-' || ishelprequest(argv[currenta
rg + i])) {
showalerthelp();
return 0;
}
}
currentarg++;
// output
if (!isnumeric(argv[currentarg])) {
printf("Error: Non-numeric output parameter \"%s\" for %s.\n", ar
gv[currentarg], argv[0]);
showalerthelp();
return 0;
}
p->alertoutput = (unsigned int)atoi(argv[currentarg]);
if (p->alertoutput > 3) {
printf("Error: Output parameter out of range for %s.\n", argv[0])
;
showalerthelp();
return 0;
}
if (debug) {
printf("Alert output: %u\n", p->alertoutput);
}
currentarg++;
// exit
if (!isnumeric(argv[currentarg])) {
printf("Error: Non-numeric exit parameter \"%s\" for %s.\n", argv
[currentarg], argv[0]);
showalerthelp();
return 0;
}
p->alertexit = (unsigned int)atoi(argv[currentarg]);
if (p->alertexit > 3) {
printf("Error: Exit parameter out of range for %s.\n", argv[0]);
showalerthelp();
return 0;
}
if (debug) {
printf("Alert exit: %u\n", p->alertexit);
}
if (p->alertoutput == AO_No_Output && (p->alertexit == AE_Always_Exit_0 |
| p->alertexit == AE_Always_Exit_1)) {
printf("Error: Configuring %s for no output and always same exit
status provides no real usability.\n", argv[0]);
showalerthelp();
return 0;
}
currentarg++;
// type
found = 0;
for (i = 0; i < 12; i++) {
if (strcmp(argv[currentarg], alerttypes[i]) == 0) {
found = 1;
break;
}
}
if (!found) {
printf("Error: Invalid type parameter \"%s\" for %s.\n", argv[cur
rentarg], argv[0]);
showalerthelp();
return 0;
}
switch (argv[currentarg][0]) {
case 'h':
p->alerttype = AT_Hour;
break;
case 'd':
p->alerttype = AT_Day;
break;
case 'm':
p->alerttype = AT_Month;
break;
case 'y':
p->alerttype = AT_Year;
break;
default:
return 0;
}
if (debug) {
printf("Alert type: %u\n", p->alerttype);
}
currentarg++;
// condition
found = 0;
for (i = 0; i < 6; i++) {
if (strcmp(argv[currentarg], alertconditions[i]) == 0) {
found = 1;
p->alertcondition = (unsigned int)i + 1;
break;
}
}
if (!found) {
printf("Error: Invalid condition parameter \"%s\" for %s.\n", arg
v[currentarg], argv[0]);
showalerthelp();
return 0;
}
if (debug) {
printf("Alert condition: %u\n", p->alertcondition);
}
currentarg++;
if ((p->alertcondition == AC_RX_Estimate || p->alertcondition == AC_TX_Es
timate || p->alertcondition == AC_Total_Estimate) &&
(p->alertoutput == AO_Output_On_Estimate || p->alertexit == AE_Ex
it_1_On_Estimate)) {
if (p->alertoutput == AO_Output_On_Estimate) {
printf("Error: Estimate conditions cannot be used in comb
ination with output parameter \"2\".\n");
}
if (p->alertexit == AE_Exit_1_On_Estimate) {
printf("Error: Estimate conditions cannot be used in comb
ination with exit parameter \"2\".\n");
}
showalerthelp();
return 0;
}
// limit
if (!isnumeric(argv[currentarg])) {
printf("Error: Limit parameter for %s must be a greater than zero
integer without decimals.\n", argv[0]);
showalerthelp();
return 0;
}
alertlimit = strtoull(argv[currentarg], (char **)NULL, 0);
if (alertlimit == 0) {
printf("Error: Invalid limit parameter \"%s\" for %s.\n", argv[cu
rrentarg], argv[0]);
showalerthelp();
return 0;
}
if (debug) {
printf("Alert limit: %" PRIu64 "\n", alertlimit);
}
currentarg++;
// limit unit
found = 0;
for (u = 0; u < 3; u++) {
cfg.unitmode = u;
for (i = 1; i <= UNITPREFIXCOUNT; i++) {
if (strcmp(argv[currentarg], getunitprefix(i)) == 0) {
found = 1;
break;
}
}
if (found) {
break;
}
}
cfg.unitmode = unitmode;
if (!found) {
printf("Error: Invalid limit unit parameter \"%s\" for %s.\n", ar
gv[currentarg], argv[0]);
showalerthelp();
return 0;
}
unitmultiplier = getunitdivisor(u, i);
if (alertlimit > (uint64_t)(MAX64 / unitmultiplier)) {
printf("Error: %" PRIu64 " %s exceeds maximum supported limit of
%" PRIu64 " %s.\n", alertlimit, argv[currentarg], (uint64_t)(MAX64 / unitmultipl
ier), argv[currentarg]);
return 0;
}
p->alertlimit = alertlimit * unitmultiplier;
if (debug) {
printf("Alert unit %s is %d %d = %" PRIu64 "\n", argv[currentarg]
, u, i, unitmultiplier);
printf("Alert real limit is %" PRIu64 " * %" PRIu64 " = %" PRIu64
"\n", alertlimit, unitmultiplier, p->alertlimit);
}
return 1;
}
void showalerthelp(void)
{
printf("\n");
printf("Valid parameters for\n--alert <output> <exit> <type> <condition>
<limit> <unit>\n\n");
printf(" <output>\n");
printf(" 0 - no output\n");
printf(" 1 - always show output\n");
printf(" 2 - show output only if usage estimate exceeds limit\n");
printf(" 3 - show output only if limit is exceeded\n\n");
printf(" <exit>\n");
printf(" 0 - always use exit status 0\n");
printf(" 1 - always use exit status 1\n");
printf(" 2 - use exit status 1 if usage estimate exceeds limit\n");
printf(" 3 - use exit status 1 if limit is exceeded\n\n");
printf(" <type>\n");
printf(" h, hour, hourly d, day, daily\n");
printf(" m, month, monthly y, year, yearly\n\n");
printf(" <condition>\n");
printf(" rx, tx, total, rx_estimate, tx_estimate, total_estimate\n\n")
;
printf(" <limit>\n");
printf(" greater than zero integer without decimals\n\n");
printf(" <unit> for <limit>\n");
printf(" B, KiB, MiB, GiB, TiB, PiB, EiB\n");
printf(" B, KB, MB, GB, TB, PB, EB\n");
}
void showstylehelp(void) void showstylehelp(void)
{ {
printf(" Valid parameters for --style.:\n"); printf(" Valid parameters for --style:\n");
printf(" 0 - a more narrow output\n"); printf(" 0 - a more narrow output\n");
printf(" 1 - enable bar column if available\n"); printf(" 1 - enable bar column if available\n");
printf(" 2 - average traffic rate in summary output\n"); printf(" 2 - average traffic rate in summary output\n");
printf(" 3 - average traffic rate in all outputs if available\n"); printf(" 3 - average traffic rate in all outputs if available\n");
printf(" 4 - disable terminal control characters in -l / --live\n"); printf(" 4 - disable terminal control characters in -l / --live\n");
printf(" and show raw values in --oneline\n"); printf(" and show raw values in --oneline\n");
} }
void handleshowalert(PARAMS *p)
{
int alert = 0;
if (!p->alert) {
return;
}
if (p->defaultiface) {
printf("Error: An interface needs to be explicitly specified for
--alert.\n");
exit(EXIT_FAILURE);
}
validateinterface(p);
alert = showalert(p->interface, p->alertoutput, p->alertexit, p->alerttyp
e, p->alertcondition, p->alertlimit);
if ((alert || p->alertexit == AE_Always_Exit_1) && p->alertexit != AE_Alw
ays_Exit_0) {
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
void handleremoveinterface(PARAMS *p) void handleremoveinterface(PARAMS *p)
{ {
if (!p->removeiface) { if (!p->removeiface) {
return; return;
} }
if (p->defaultiface) { if (p->defaultiface) {
printf("Error: Use -i parameter to specify an interface.\n"); printf("Error: An interface needs to be explicitly specified for --remove.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!db_getinterfacecountbyname(p->interface)) { if (!db_getinterfacecountbyname(p->interface)) {
printf("Error: Interface \"%s\" not found in database.\n", p->int erface); printf("Error: Interface \"%s\" not found in database.\n", p->int erface);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!p->force) { if (!p->force) {
printf("Warning:\nThe current option would remove all data about interface \"%s\" from the database. ", p->interface); printf("Warning:\nThe current option would remove all data about interface \"%s\" from the database. ", p->interface);
skipping to change at line 577 skipping to change at line 833
} }
} }
void handlerenameinterface(PARAMS *p) void handlerenameinterface(PARAMS *p)
{ {
if (!p->renameiface) { if (!p->renameiface) {
return; return;
} }
if (p->defaultiface) { if (p->defaultiface) {
printf("Error: Use -i parameter to specify an interface.\n"); printf("Error: An interface needs to be explicitly specified for --rename.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!strlen(p->newifname)) { if (!strlen(p->newifname)) {
printf("Error: New interface name must be at least one character long.\n"); printf("Error: New interface name must be at least one character long.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!db_getinterfacecountbyname(p->interface)) { if (!db_getinterfacecountbyname(p->interface)) {
printf("Error: Interface \"%s\" not found in database.\n", p->int erface); printf("Error: Interface \"%s\" not found in database.\n", p->int erface);
skipping to change at line 628 skipping to change at line 884
} }
} }
void handleaddinterface(PARAMS *p) void handleaddinterface(PARAMS *p)
{ {
if (!p->addiface) { if (!p->addiface) {
return; return;
} }
if (p->defaultiface) { if (p->defaultiface) {
printf("Error: Use -i parameter to specify an interface.\n"); printf("Error: An interface needs to be explicitly specified for --add.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
db_errcode = 0; db_errcode = 0;
if (db_getinterfacecountbyname(p->interface)) { if (db_getinterfacecountbyname(p->interface)) {
printf("Error: Interface \"%s\" already exists in the database.\n ", p->interface); printf("Error: Interface \"%s\" already exists in the database.\n ", p->interface);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (db_errcode) { if (db_errcode) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
skipping to change at line 686 skipping to change at line 942
} }
} }
void handlesetalias(PARAMS *p) void handlesetalias(PARAMS *p)
{ {
if (!p->setalias) { if (!p->setalias) {
return; return;
} }
if (p->defaultiface) { if (p->defaultiface) {
printf("Error: Use -i parameter to specify an interface.\n"); printf("Error: An interface needs to be explicitly specified for --setalias.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!db_getinterfacecountbyname(p->interface)) { if (!db_getinterfacecountbyname(p->interface)) {
printf("Error: Interface \"%s\" not found in database.\n", p->int erface); printf("Error: Interface \"%s\" not found in database.\n", p->int erface);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifndef CHECK_VNSTAT #ifndef CHECK_VNSTAT
if (!db_close() || !db_open_rw(0)) { if (!db_close() || !db_open_rw(0)) {
skipping to change at line 729 skipping to change at line 985
if (!p->query) { if (!p->query) {
return; return;
} }
/* show only specified file */ /* show only specified file */
if (!p->defaultiface) { if (!p->defaultiface) {
showoneinterface(p); showoneinterface(p);
return; return;
} }
/* show all interfaces if -i isn't specified */ /* show all interfaces if none is explicitly specified */
if (p->dbifcount == 0) { if (p->dbifcount == 0) {
p->query = 0; p->query = 0;
} else if ((cfg.qmode == 0 || cfg.qmode == 8 || cfg.qmode == 10) && (p->d bifcount > 1)) { } else if ((cfg.qmode == 0 || cfg.qmode == 8 || cfg.qmode == 10) && (p->d bifcount > 1)) {
if (cfg.qmode == 0) { if (cfg.qmode == 0) {
if (cfg.ostyle != 0) { if (cfg.ostyle != 0) {
printf("\n rx / tx / total / estimated\n"); printf("\n rx / tx / total / estimated\n");
} else { } else {
printf("\n rx / tx / total\n"); printf("\n rx / tx / total\n");
} }
skipping to change at line 782 skipping to change at line 1038
} }
/* show in qmode if there's only one interface or qmode!=0 */ /* show in qmode if there's only one interface or qmode!=0 */
} else { } else {
showoneinterface(p); showoneinterface(p);
} }
} }
void showoneinterface(PARAMS *p) void showoneinterface(PARAMS *p)
{ {
if (!db_getinterfacecountbyname(p->interface)) { validateinterface(p);
if (strchr(p->interface, '+') == NULL) {
printf("Error: Interface \"%s\" not found in database.\n"
, p->interface);
} else {
printf("Error: Not all requested interfaces found in data
base or given interfaces aren't unique.\n");
}
exit(EXIT_FAILURE);
}
if (cfg.qmode == 5) { if (cfg.qmode == 5) {
if (cfg.ostyle != 0) { if (cfg.ostyle != 0) {
printf("\n rx / tx / total / estimated\n"); printf("\n rx / tx / total / estimated\n");
} else { } else {
printf("\n rx / tx / total\n"); printf("\n rx / tx / total\n");
} }
} }
if (cfg.qmode != 8 && cfg.qmode != 10) { if (cfg.qmode != 8 && cfg.qmode != 10) {
showdb(p->interface, cfg.qmode, p->databegin, p->dataend); showdb(p->interface, cfg.qmode, p->databegin, p->dataend);
skipping to change at line 837 skipping to change at line 1086
p->defaultiface = 0; p->defaultiface = 0;
printf("using \"%s\" instead.\n", p->interface); printf("using \"%s\" instead.\n", p->interface);
} }
if (!isifavailable(p->interface)) { if (!isifavailable(p->interface)) {
getifliststring(&p->ifacelist, 0); getifliststring(&p->ifacelist, 0);
if (p->defaultiface) { if (p->defaultiface) {
printf("Error: Configured default interface \"%s\" isn't available.\n\n", p->interface); printf("Error: Configured default interface \"%s\" isn't available.\n\n", p->interface);
if (strlen(cfg.cfgfile)) { if (strlen(cfg.cfgfile)) {
printf("Update \"Interface\" keyword value in con figuration file \"%s\" to change ", cfg.cfgfile); printf("Update \"Interface\" keyword value in con figuration file \"%s\" to change ", cfg.cfgfile);
printf("the default interface or give an alternat ive interface using the -i parameter.\n\n"); printf("the default interface or give an alternat ive interface with or without the -i parameter.\n\n");
} else { } else {
printf("An alternative interface can be given usi ng the -i parameter.\n\n"); printf("An alternative interface can be given wit h or without the -i parameter.\n\n");
} }
printf("The following interfaces are currently available: \n %s\n", p->ifacelist); printf("The following interfaces are currently available: \n %s\n", p->ifacelist);
} else { } else {
printf("Error: Unable to get interface \"%s\" statistics. \n\n", p->interface); printf("Error: Unable to get interface \"%s\" statistics. \n\n", p->interface);
printf("The following interfaces are currently available: \n %s\n", p->ifacelist); printf("The following interfaces are currently available: \n %s\n", p->ifacelist);
} }
free(p->ifacelist); free(p->ifacelist);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
skipping to change at line 1005 skipping to change at line 1254
while (dbifl_i != NULL) { while (dbifl_i != NULL) {
printf("%s\n", dbifl_i->interface); printf("%s\n", dbifl_i->interface);
dbifl_i = dbifl_i->next; dbifl_i = dbifl_i->next;
} }
} }
} }
iflistfree(&dbifl); iflistfree(&dbifl);
db_close(); db_close();
} }
void validateinterface(PARAMS *p)
{
int i, found = 0;
timeused_debug(__func__, 1);
if (!db_getinterfacecountbyname(p->interface)) {
if (strchr(p->interface, '+') == NULL) {
for (i = 1; i <= cfg.ifacematchmethod; i++) {
found = db_setinterfacebyalias(p->interface, p->i
nterface, i);
if (found) {
if (debug) {
printf("Found \"%s\" with method
%d\n", p->interface, i);
}
break;
}
}
if (!found) {
printf("Error: No interface matching \"%s\" found
in database.\n", p->interface);
exit(EXIT_FAILURE);
}
} else {
printf("Error: Not all requested interfaces found in data
base or given interfaces aren't unique.\n");
exit(EXIT_FAILURE);
}
}
timeused_debug(__func__, 0);
}
 End of changes. 19 change blocks. 
25 lines changed or deleted 304 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)