--- /dev/null
+---
+Language: Cpp
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Linux
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 0
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: true
+IndentPPDirectives: None
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+RawStringFormats:
+ - Delimiter: pb
+ Language: TextProto
+ BasedOnStyle: google
+ReflowComments: true
+SortIncludes: false
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Auto
+TabWidth: 4
+UseTab: Always
+...
INSTALL_BSD
UPGRADE
UNINSTALL
+.vscode
char value[512], cfgline[512];
struct cfgsetting cset[] =
- { /* cfg string, char var name, int var name, char len, fill status */
- { "Interface", cfg.iface, 0, 32, 0 },
- { "DatabaseDir", cfg.dbdir, 0, 512, 0 },
- { "Locale", cfg.locale, 0, 32, 0 },
- { "MonthRotate", 0, &cfg.monthrotate, 0, 0 },
- { "MonthRotateAffectsYears", 0, &cfg.monthrotateyears, 0, 0 },
- { "DayFormat", cfg.dformat, 0, 64, 0 },
- { "MonthFormat", cfg.mformat, 0, 64, 0 },
- { "TopFormat", cfg.tformat, 0, 64, 0 },
- { "RXCharacter", cfg.rxchar, 0, 2, 0 },
- { "TXCharacter", cfg.txchar, 0, 2, 0 },
- { "RXHourCharacter", cfg.rxhourchar, 0, 2, 0 },
- { "TXHourCharacter", cfg.txhourchar, 0, 2, 0 },
- { "UnitMode", 0, &cfg.unitmode, 0, 0 },
- { "RateUnitMode", 0, &cfg.rateunitmode, 0, 0 },
- { "OutputStyle", 0, &cfg.ostyle, 0, 0 },
- { "RateUnit", 0, &cfg.rateunit, 0, 0 },
- { "DefaultDecimals", 0, &cfg.defaultdecimals, 0, 0 },
- { "HourlyDecimals", 0, &cfg.hourlydecimals, 0, 0 },
- { "HourlySectionStyle", 0, &cfg.hourlystyle, 0, 0 },
- { "BandwidthDetection", 0, &cfg.bwdetection, 0, 0 },
- { "MaxBandwidth", 0, &cfg.maxbw, 0, 0 },
- { "Sampletime", 0, &cfg.sampletime, 0, 0 },
- { "QueryMode", 0, &cfg.qmode, 0, 0 },
- { "CheckDiskSpace", 0, &cfg.spacecheck, 0, 0 },
- { "BootVariation", 0, &cfg.bvar, 0, 0 },
- { "TrafficlessEntries", 0, &cfg.trafficlessentries, 0, 0 },
- { "List5Mins", 0, &cfg.listfivemins, 0, 0 },
- { "ListHours", 0, &cfg.listhours, 0, 0 },
- { "ListDays", 0, &cfg.listdays, 0, 0 },
- { "ListMonths", 0, &cfg.listmonths, 0, 0 },
- { "ListYears", 0, &cfg.listyears, 0, 0 },
- { "ListTop", 0, &cfg.listtop, 0, 0 },
- { "5MinuteHours", 0, &cfg.fiveminutehours, 0, 0 },
- { "HourlyDays", 0, &cfg.hourlydays, 0, 0 },
- { "DailyDays", 0, &cfg.dailydays, 0, 0 },
- { "MonthlyMonths", 0, &cfg.monthlymonths, 0, 0 },
- { "YearlyYears", 0, &cfg.yearlyyears, 0, 0 },
- { "TopDayEntries", 0, &cfg.topdayentries, 0, 0 },
- { "DaemonUser", cfg.daemonuser, 0, 33, 0 },
- { "DaemonGroup", cfg.daemongroup, 0, 33, 0 },
- { "TimeSyncWait", 0, &cfg.timesyncwait, 0, 0 },
- { "UpdateInterval", 0, &cfg.updateinterval, 0, 0 },
- { "PollInterval", 0, &cfg.pollinterval, 0, 0 },
- { "SaveInterval", 0, &cfg.saveinterval, 0, 0 },
- { "OfflineSaveInterval", 0, &cfg.offsaveinterval, 0, 0 },
- { "BandwidthDetectionInterval", 0, &cfg.bwdetectioninterval, 0, 0 },
- { "SaveOnStatusChange", 0, &cfg.savestatus, 0, 0 },
- { "UseLogging", 0, &cfg.uselogging, 0, 0 },
- { "CreateDirs", 0, &cfg.createdirs, 0, 0 },
- { "UpdateFileOwner", 0, &cfg.updatefileowner, 0, 0 },
- { "LogFile", cfg.logfile, 0, 512, 0 },
- { "PidFile", cfg.pidfile, 0, 512, 0 },
- { "64bitInterfaceCounters", 0, &cfg.is64bit, 0, 0 },
- { "HeaderFormat", cfg.hformat, 0, 64, 0 },
- { "HourlyRate", 0, &cfg.hourlyrate, 0, 0 },
- { "SummaryRate", 0, &cfg.summaryrate, 0, 0 },
- { "TransparentBg", 0, &cfg.transbg, 0, 0 },
- { "CBackground", cfg.cbg, 0, 8, 0 },
- { "CEdge", cfg.cedge, 0, 8, 0 },
- { "CHeader", cfg.cheader, 0, 8, 0 },
- { "CHeaderTitle", cfg.cheadertitle, 0, 8, 0 },
- { "CHeaderDate", cfg.cheaderdate, 0, 8, 0 },
- { "CText", cfg.ctext, 0, 8, 0 },
- { "CLine", cfg.cline, 0, 8, 0 },
- { "CLineL", cfg.clinel, 0, 8, 0 },
- { "CRx", cfg.crx, 0, 8, 0 },
- { "CRxD", cfg.crxd, 0, 8, 0 },
- { "CTx", cfg.ctx, 0, 8, 0 },
- { "CTxD", cfg.ctxd, 0, 8, 0 },
- { 0, 0, 0, 0, 0 }
- };
+ {/* cfg string, char var name, int var name, char len, fill status */
+ {"Interface", cfg.iface, 0, 32, 0},
+ {"DatabaseDir", cfg.dbdir, 0, 512, 0},
+ {"Locale", cfg.locale, 0, 32, 0},
+ {"MonthRotate", 0, &cfg.monthrotate, 0, 0},
+ {"MonthRotateAffectsYears", 0, &cfg.monthrotateyears, 0, 0},
+ {"DayFormat", cfg.dformat, 0, 64, 0},
+ {"MonthFormat", cfg.mformat, 0, 64, 0},
+ {"TopFormat", cfg.tformat, 0, 64, 0},
+ {"RXCharacter", cfg.rxchar, 0, 2, 0},
+ {"TXCharacter", cfg.txchar, 0, 2, 0},
+ {"RXHourCharacter", cfg.rxhourchar, 0, 2, 0},
+ {"TXHourCharacter", cfg.txhourchar, 0, 2, 0},
+ {"UnitMode", 0, &cfg.unitmode, 0, 0},
+ {"RateUnitMode", 0, &cfg.rateunitmode, 0, 0},
+ {"OutputStyle", 0, &cfg.ostyle, 0, 0},
+ {"RateUnit", 0, &cfg.rateunit, 0, 0},
+ {"DefaultDecimals", 0, &cfg.defaultdecimals, 0, 0},
+ {"HourlyDecimals", 0, &cfg.hourlydecimals, 0, 0},
+ {"HourlySectionStyle", 0, &cfg.hourlystyle, 0, 0},
+ {"BandwidthDetection", 0, &cfg.bwdetection, 0, 0},
+ {"MaxBandwidth", 0, &cfg.maxbw, 0, 0},
+ {"Sampletime", 0, &cfg.sampletime, 0, 0},
+ {"QueryMode", 0, &cfg.qmode, 0, 0},
+ {"CheckDiskSpace", 0, &cfg.spacecheck, 0, 0},
+ {"BootVariation", 0, &cfg.bvar, 0, 0},
+ {"TrafficlessEntries", 0, &cfg.trafficlessentries, 0, 0},
+ {"List5Mins", 0, &cfg.listfivemins, 0, 0},
+ {"ListHours", 0, &cfg.listhours, 0, 0},
+ {"ListDays", 0, &cfg.listdays, 0, 0},
+ {"ListMonths", 0, &cfg.listmonths, 0, 0},
+ {"ListYears", 0, &cfg.listyears, 0, 0},
+ {"ListTop", 0, &cfg.listtop, 0, 0},
+ {"5MinuteHours", 0, &cfg.fiveminutehours, 0, 0},
+ {"HourlyDays", 0, &cfg.hourlydays, 0, 0},
+ {"DailyDays", 0, &cfg.dailydays, 0, 0},
+ {"MonthlyMonths", 0, &cfg.monthlymonths, 0, 0},
+ {"YearlyYears", 0, &cfg.yearlyyears, 0, 0},
+ {"TopDayEntries", 0, &cfg.topdayentries, 0, 0},
+ {"DaemonUser", cfg.daemonuser, 0, 33, 0},
+ {"DaemonGroup", cfg.daemongroup, 0, 33, 0},
+ {"TimeSyncWait", 0, &cfg.timesyncwait, 0, 0},
+ {"UpdateInterval", 0, &cfg.updateinterval, 0, 0},
+ {"PollInterval", 0, &cfg.pollinterval, 0, 0},
+ {"SaveInterval", 0, &cfg.saveinterval, 0, 0},
+ {"OfflineSaveInterval", 0, &cfg.offsaveinterval, 0, 0},
+ {"BandwidthDetectionInterval", 0, &cfg.bwdetectioninterval, 0, 0},
+ {"SaveOnStatusChange", 0, &cfg.savestatus, 0, 0},
+ {"UseLogging", 0, &cfg.uselogging, 0, 0},
+ {"CreateDirs", 0, &cfg.createdirs, 0, 0},
+ {"UpdateFileOwner", 0, &cfg.updatefileowner, 0, 0},
+ {"LogFile", cfg.logfile, 0, 512, 0},
+ {"PidFile", cfg.pidfile, 0, 512, 0},
+ {"64bitInterfaceCounters", 0, &cfg.is64bit, 0, 0},
+ {"HeaderFormat", cfg.hformat, 0, 64, 0},
+ {"HourlyRate", 0, &cfg.hourlyrate, 0, 0},
+ {"SummaryRate", 0, &cfg.summaryrate, 0, 0},
+ {"TransparentBg", 0, &cfg.transbg, 0, 0},
+ {"CBackground", cfg.cbg, 0, 8, 0},
+ {"CEdge", cfg.cedge, 0, 8, 0},
+ {"CHeader", cfg.cheader, 0, 8, 0},
+ {"CHeaderTitle", cfg.cheadertitle, 0, 8, 0},
+ {"CHeaderDate", cfg.cheaderdate, 0, 8, 0},
+ {"CText", cfg.ctext, 0, 8, 0},
+ {"CLine", cfg.cline, 0, 8, 0},
+ {"CLineL", cfg.clinel, 0, 8, 0},
+ {"CRx", cfg.crx, 0, 8, 0},
+ {"CRxD", cfg.crxd, 0, 8, 0},
+ {"CTx", cfg.ctx, 0, 8, 0},
+ {"CTxD", cfg.ctxd, 0, 8, 0},
+ {0, 0, 0, 0, 0}};
/* load default config */
defaultcfg();
while (!feof(fd)) {
cfgline[0] = '\0';
- if (fgets(cfgline, 512, fd)==NULL) {
+ if (fgets(cfgline, 512, fd) == NULL) {
break;
}
linelen = (unsigned int)strlen(cfgline);
- if (linelen<=2 || cfgline[0]=='#') {
+ if (linelen <= 2 || cfgline[0] == '#') {
continue;
}
- for (i=0; cset[i].name!=0; i++) {
+ for (i = 0; cset[i].name != 0; i++) {
if (cset[i].found) {
continue;
}
cfglen = (unsigned int)strlen(cset[i].name);
- if ( (linelen<(cfglen+2)) || (strncasecmp(cfgline, cset[i].name, cfglen)!=0) ) {
+ if ((linelen < (cfglen + 2)) || (strncasecmp(cfgline, cset[i].name, cfglen) != 0)) {
continue;
}
break;
}
- if ((debug) && (!cset[i].found) && (strncasecmp(cfgline, "MaxBW", 5)!=0))
+ if ((debug) && (!cset[i].found) && (strncasecmp(cfgline, "MaxBW", 5) != 0))
printf("Unknown configuration line: %s", cfgline);
-
}
fclose(fd);
validatecfg();
return 1;
-
}
void validatecfg(void)
const char *resettingto = "resetting to";
const char *noslashstart = "doesn't start with \"/\", resetting to default.";
- if (cfg.unitmode<0 || cfg.unitmode>2) {
+ if (cfg.unitmode < 0 || cfg.unitmode > 2) {
cfg.unitmode = UNITMODE;
snprintf(errorstring, 1024, "%s UnitMode, %s \"%d\".", invalidvalue, resettingto, cfg.unitmode);
printe(PT_Config);
}
- if (cfg.rateunitmode<0 || cfg.rateunitmode>1) {
+ if (cfg.rateunitmode < 0 || cfg.rateunitmode > 1) {
cfg.rateunitmode = RATEUNITMODE;
snprintf(errorstring, 1024, "%s RateUnitMode, %s \"%d\".", invalidvalue, resettingto, cfg.rateunitmode);
printe(PT_Config);
}
- if (cfg.ostyle<0 || cfg.ostyle>3) {
+ if (cfg.ostyle < 0 || cfg.ostyle > 3) {
cfg.ostyle = OSTYLE;
snprintf(errorstring, 1024, "%s OutputStyle, %s \"%d\".", invalidvalue, resettingto, cfg.ostyle);
printe(PT_Config);
}
- if (cfg.defaultdecimals<0 || cfg.defaultdecimals>2) {
+ if (cfg.defaultdecimals < 0 || cfg.defaultdecimals > 2) {
cfg.defaultdecimals = DEFAULTDECIMALS;
snprintf(errorstring, 1024, "%s DefaultDecimals, %s \"%d\".", invalidvalue, resettingto, cfg.defaultdecimals);
printe(PT_Config);
}
- if (cfg.hourlydecimals<0 || cfg.hourlydecimals>2) {
+ if (cfg.hourlydecimals < 0 || cfg.hourlydecimals > 2) {
cfg.hourlydecimals = HOURLYDECIMALS;
snprintf(errorstring, 1024, "%s HourlyDecimals, %s \"%d\".", invalidvalue, resettingto, cfg.hourlydecimals);
printe(PT_Config);
}
- if (cfg.hourlystyle<0 || cfg.hourlystyle>3) {
+ if (cfg.hourlystyle < 0 || cfg.hourlystyle > 3) {
cfg.hourlystyle = HOURLYSTYLE;
snprintf(errorstring, 1024, "%s HourlySectionStyle, %s \"%d\".", invalidvalue, resettingto, cfg.hourlystyle);
printe(PT_Config);
}
- if (cfg.bvar<0 || cfg.bvar>300) {
+ if (cfg.bvar < 0 || cfg.bvar > 300) {
cfg.bvar = BVAR;
snprintf(errorstring, 1024, "%s BootVariation, %s \"%d\".", invalidvalue, resettingto, cfg.bvar);
printe(PT_Config);
}
- if (cfg.sampletime<2 || cfg.sampletime>600) {
+ if (cfg.sampletime < 2 || cfg.sampletime > 600) {
cfg.sampletime = DEFSAMPTIME;
snprintf(errorstring, 1024, "%s Sampletime, %s \"%d\".", invalidvalue, resettingto, cfg.sampletime);
printe(PT_Config);
}
- if (cfg.monthrotate<1 || cfg.monthrotate>28) {
+ if (cfg.monthrotate < 1 || cfg.monthrotate > 28) {
cfg.monthrotate = MONTHROTATE;
snprintf(errorstring, 1024, "%s MonthRotate, %s \"%d\".", invalidvalue, resettingto, cfg.monthrotate);
printe(PT_Config);
}
- if (cfg.monthrotateyears<0 || cfg.monthrotateyears>1) {
+ if (cfg.monthrotateyears < 0 || cfg.monthrotateyears > 1) {
cfg.monthrotateyears = MONTHROTATEYEARS;
snprintf(errorstring, 1024, "%s MonthRotateAffectsYears, %s \"%d\".", invalidvalue, resettingto, cfg.monthrotateyears);
printe(PT_Config);
}
- if (cfg.maxbw<0 || cfg.maxbw>BWMAX) {
+ if (cfg.maxbw < 0 || cfg.maxbw > BWMAX) {
cfg.maxbw = DEFMAXBW;
snprintf(errorstring, 1024, "%s MaxBandwidth, %s \"%d\".", invalidvalue, resettingto, cfg.maxbw);
printe(PT_Config);
}
- if (cfg.spacecheck<0 || cfg.spacecheck>1) {
+ if (cfg.spacecheck < 0 || cfg.spacecheck > 1) {
cfg.spacecheck = USESPACECHECK;
snprintf(errorstring, 1024, "%s CheckDiskSpace, %s \"%d\".", invalidvalue, resettingto, cfg.spacecheck);
printe(PT_Config);
printe(PT_Config);
}
- if (cfg.timesyncwait<0 || cfg.timesyncwait>60) {
+ if (cfg.timesyncwait < 0 || cfg.timesyncwait > 60) {
cfg.timesyncwait = TIMESYNCWAIT;
snprintf(errorstring, 1024, "%s TimeSyncWait, %s \"%d\".", invalidvalue, resettingto, cfg.timesyncwait);
printe(PT_Config);
}
- if (cfg.pollinterval<2 || cfg.pollinterval>60) {
+ if (cfg.pollinterval < 2 || cfg.pollinterval > 60) {
cfg.pollinterval = POLLINTERVAL;
snprintf(errorstring, 1024, "%s PollInterval, %s \"%d\".", invalidvalue, resettingto, cfg.pollinterval);
printe(PT_Config);
}
- if (cfg.updateinterval<cfg.pollinterval || cfg.updateinterval>300) {
- if (cfg.pollinterval>UPDATEINTERVAL) {
+ if (cfg.updateinterval < cfg.pollinterval || cfg.updateinterval > 300) {
+ if (cfg.pollinterval > UPDATEINTERVAL) {
cfg.updateinterval = cfg.pollinterval;
} else {
cfg.updateinterval = UPDATEINTERVAL;
printe(PT_Config);
}
- if ((cfg.saveinterval*60)<cfg.updateinterval || cfg.saveinterval>60) {
- if (cfg.updateinterval>(SAVEINTERVAL*60)) {
+ if ((cfg.saveinterval * 60) < cfg.updateinterval || cfg.saveinterval > 60) {
+ if (cfg.updateinterval > (SAVEINTERVAL * 60)) {
cfg.saveinterval = cfg.updateinterval;
} else {
cfg.saveinterval = SAVEINTERVAL;
printe(PT_Config);
}
- if (cfg.offsaveinterval<cfg.saveinterval || cfg.offsaveinterval>60) {
- if (cfg.saveinterval>OFFSAVEINTERVAL) {
+ if (cfg.offsaveinterval < cfg.saveinterval || cfg.offsaveinterval > 60) {
+ if (cfg.saveinterval > OFFSAVEINTERVAL) {
cfg.offsaveinterval = cfg.saveinterval;
} else {
cfg.offsaveinterval = OFFSAVEINTERVAL;
printe(PT_Config);
}
- if (cfg.savestatus<0 || cfg.savestatus>1) {
+ if (cfg.savestatus < 0 || cfg.savestatus > 1) {
cfg.savestatus = SAVESTATUS;
snprintf(errorstring, 1024, "%s SaveOnStatusChange, %s \"%d\".", invalidvalue, resettingto, cfg.savestatus);
printe(PT_Config);
}
- if (cfg.uselogging<0 || cfg.uselogging>2) {
+ if (cfg.uselogging < 0 || cfg.uselogging > 2) {
cfg.uselogging = USELOGGING;
snprintf(errorstring, 1024, "%s UseLogging, %s \"%d\".", invalidvalue, resettingto, cfg.uselogging);
printe(PT_Config);
}
- if (cfg.createdirs<0 || cfg.createdirs>2) {
+ if (cfg.createdirs < 0 || cfg.createdirs > 2) {
cfg.createdirs = CREATEDIRS;
snprintf(errorstring, 1024, "%s CreateDirs, %s \"%d\".", invalidvalue, resettingto, cfg.createdirs);
printe(PT_Config);
}
- if (cfg.updatefileowner<0 || cfg.updatefileowner>2) {
+ if (cfg.updatefileowner < 0 || cfg.updatefileowner > 2) {
cfg.updatefileowner = UPDATEFILEOWNER;
snprintf(errorstring, 1024, "%s UpdateFileOwner, %s \"%d\".", invalidvalue, resettingto, cfg.updatefileowner);
printe(PT_Config);
printe(PT_Config);
}
- if (cfg.is64bit<-2 || cfg.is64bit>1) {
+ if (cfg.is64bit < -2 || cfg.is64bit > 1) {
cfg.is64bit = IS64BIT;
snprintf(errorstring, 1024, "%s 64bitInterfaceCounters, %s \"%d\".", invalidvalue, resettingto, cfg.is64bit);
printe(PT_Config);
}
- if (cfg.transbg<0 || cfg.transbg>1) {
+ if (cfg.transbg < 0 || cfg.transbg > 1) {
cfg.transbg = TRANSBG;
snprintf(errorstring, 1024, "%s TransparentBg, %s \"%d\".", invalidvalue, resettingto, cfg.transbg);
printe(PT_Config);
}
- if (cfg.hourlyrate<0 || cfg.hourlyrate>1) {
+ if (cfg.hourlyrate < 0 || cfg.hourlyrate > 1) {
cfg.hourlyrate = HOURLYRATE;
snprintf(errorstring, 1024, "%s HourlyRate, %s \"%d\".", invalidvalue, resettingto, cfg.hourlyrate);
printe(PT_Config);
}
- if (cfg.summaryrate<0 || cfg.summaryrate>1) {
+ if (cfg.summaryrate < 0 || cfg.summaryrate > 1) {
cfg.summaryrate = SUMMARYRATE;
snprintf(errorstring, 1024, "%s SummaryRate, %s \"%d\".", invalidvalue, resettingto, cfg.summaryrate);
printe(PT_Config);
}
- if (cfg.trafficlessentries<0 || cfg.trafficlessentries>1) {
+ if (cfg.trafficlessentries < 0 || cfg.trafficlessentries > 1) {
cfg.trafficlessentries = TRAFFICLESSENTRIES;
snprintf(errorstring, 1024, "%s TrafficlessEntries, %s \"%d\".", invalidvalue, resettingto, cfg.trafficlessentries);
printe(PT_Config);
}
- if (cfg.listfivemins<0) {
+ if (cfg.listfivemins < 0) {
cfg.listfivemins = LISTFIVEMINS;
snprintf(errorstring, 1024, "%s List5Mins, %s \"%d\".", invalidvalue, resettingto, cfg.listfivemins);
printe(PT_Config);
}
- if (cfg.listhours<0) {
+ if (cfg.listhours < 0) {
cfg.listhours = LISTHOURS;
snprintf(errorstring, 1024, "%s ListHours, %s \"%d\".", invalidvalue, resettingto, cfg.listhours);
printe(PT_Config);
}
- if (cfg.listdays<0) {
+ if (cfg.listdays < 0) {
cfg.listdays = LISTDAYS;
snprintf(errorstring, 1024, "%s ListDays, %s \"%d\".", invalidvalue, resettingto, cfg.listdays);
printe(PT_Config);
}
- if (cfg.listmonths<0) {
+ if (cfg.listmonths < 0) {
cfg.listmonths = LISTMONTHS;
snprintf(errorstring, 1024, "%s ListMonths, %s \"%d\".", invalidvalue, resettingto, cfg.listmonths);
printe(PT_Config);
}
- if (cfg.listyears<0) {
+ if (cfg.listyears < 0) {
cfg.listyears = LISTYEARS;
snprintf(errorstring, 1024, "%s ListYears, %s \"%d\".", invalidvalue, resettingto, cfg.listyears);
printe(PT_Config);
}
- if (cfg.listtop<0) {
+ if (cfg.listtop < 0) {
cfg.listtop = LISTTOP;
snprintf(errorstring, 1024, "%s ListTop, %s \"%d\".", invalidvalue, resettingto, cfg.listtop);
printe(PT_Config);
}
- if (cfg.fiveminutehours<-1) {
+ if (cfg.fiveminutehours < -1) {
cfg.fiveminutehours = FIVEMINUTEHOURS;
snprintf(errorstring, 1024, "%s 5MinuteHours, %s \"%d\".", invalidvalue, resettingto, cfg.fiveminutehours);
printe(PT_Config);
}
- if (cfg.hourlydays<-1) {
+ if (cfg.hourlydays < -1) {
cfg.hourlydays = HOURLYDAYS;
snprintf(errorstring, 1024, "%s HourlyDays, %s \"%d\".", invalidvalue, resettingto, cfg.hourlydays);
printe(PT_Config);
}
- if (cfg.dailydays<-1) {
+ if (cfg.dailydays < -1) {
cfg.dailydays = DAILYDAYS;
snprintf(errorstring, 1024, "%s DailyDays, %s \"%d\".", invalidvalue, resettingto, cfg.dailydays);
printe(PT_Config);
}
- if (cfg.monthlymonths<-1) {
+ if (cfg.monthlymonths < -1) {
cfg.monthlymonths = MONTHLYMONTHS;
snprintf(errorstring, 1024, "%s MonthlyMonths, %s \"%d\".", invalidvalue, resettingto, cfg.monthlymonths);
printe(PT_Config);
}
- if (cfg.yearlyyears<-1) {
+ if (cfg.yearlyyears < -1) {
cfg.yearlyyears = YEARLYYEARS;
snprintf(errorstring, 1024, "%s YearlyYears, %s \"%d\".", invalidvalue, resettingto, cfg.yearlyyears);
printe(PT_Config);
}
- if (cfg.topdayentries<-1) {
+ if (cfg.topdayentries < -1) {
cfg.topdayentries = TOPDAYENTRIES;
snprintf(errorstring, 1024, "%s TopDayEntries, %s \"%d\".", invalidvalue, resettingto, cfg.topdayentries);
printe(PT_Config);
}
- if (cfg.bwdetection<0 || cfg.bwdetection>1) {
+ if (cfg.bwdetection < 0 || cfg.bwdetection > 1) {
cfg.bwdetection = BWDETECT;
snprintf(errorstring, 1024, "%s BandwidthDetection, %s \"%d\".", invalidvalue, resettingto, cfg.bwdetection);
printe(PT_Config);
}
- if (cfg.bwdetectioninterval<0 || cfg.bwdetectioninterval>30) {
+ if (cfg.bwdetectioninterval < 0 || cfg.bwdetectioninterval > 30) {
cfg.bwdetectioninterval = BWDETECTINTERVAL;
snprintf(errorstring, 1024, "%s BandwidthDetectionInterval, %s \"%d\".", invalidvalue, resettingto, cfg.bwdetectioninterval);
printe(PT_Config);
int i, tryhome;
/* clear buffer */
- for (i=0; i<512; i++) {
+ for (i = 0; i < 512; i++) {
buffer[i] = '\0';
}
cfg.cfgfile[0] = '\0';
/* possible config files: 1) --config 2) $HOME/.vnstatrc 3) /etc/vnstat.conf 4) none */
- if (cfgfile[0]!='\0') {
+ if (cfgfile[0] != '\0') {
/* try to open given file */
- if ((*fd=fopen(cfgfile, "r"))!=NULL) {
+ if ((*fd = fopen(cfgfile, "r")) != NULL) {
strncpy_nt(cfg.cfgfile, cfgfile, 512);
if (debug)
printf("Config file: --config\n");
}
/* try to open first available config file */
- if (tryhome && (*fd=fopen(buffer, "r"))!=NULL) {
+ if (tryhome && (*fd = fopen(buffer, "r")) != NULL) {
strncpy_nt(cfg.cfgfile, buffer, 512);
- } else if ((*fd=fopen("/etc/vnstat.conf", "r"))!=NULL) {
+ } else if ((*fd = fopen("/etc/vnstat.conf", "r")) != NULL) {
snprintf(cfg.cfgfile, 512, "/etc/vnstat.conf");
- } else if ((*fd=fopen("/usr/local/etc/vnstat.conf", "r"))!=NULL) {
+ } else if ((*fd = fopen("/usr/local/etc/vnstat.conf", "r")) != NULL) {
snprintf(cfg.cfgfile, 512, "/usr/local/etc/vnstat.conf");
} else {
if (debug)
return 2;
}
-int extractcfgvalue(char *value, const unsigned int valuelen, const char *cfgline, const unsigned int cfglen) {
+int extractcfgvalue(char *value, const unsigned int valuelen, const char *cfgline, const unsigned int cfglen)
+{
unsigned int i, j, linelen;
linelen = (unsigned int)strlen(cfgline);
- for (i=0; i<valuelen; i++) {
- value[i]='\0';
+ for (i = 0; i < valuelen; i++) {
+ value[i] = '\0';
}
i = 0;
- for (j=cfglen; j<linelen; j++) {
- if (cfgline[j]=='\n' || cfgline[j]=='\r') {
+ for (j = cfglen; j < linelen; j++) {
+ if (cfgline[j] == '\n' || cfgline[j] == '\r') {
break;
- } else if (cfgline[j]=='\"') {
- if (i==0) {
+ } else if (cfgline[j] == '\"') {
+ if (i == 0) {
continue;
} else {
break;
}
} else {
- if (i==0 && (cfgline[j]==' ' || cfgline[j]=='=' || cfgline[j]=='\t')) {
+ if (i == 0 && (cfgline[j] == ' ' || cfgline[j] == '=' || cfgline[j] == '\t')) {
continue;
} else {
value[i] = cfgline[j];
int setcfgvalue(const struct cfgsetting *cset, const char *value, const char *cfgline)
{
- if (cset->namelen>0) {
+ if (cset->namelen > 0) {
strncpy_nt(cset->locc, value, (size_t)cset->namelen);
if (debug)
printf(" c: %s -> \"%s\": \"%s\"\n", cfgline, cset->name, cset->locc);
- } else if ( ( strlen(value)>1 && isdigit(value[1]) ) || isdigit(value[0]) ) {
+ } else if ((strlen(value) > 1 && isdigit(value[1])) || isdigit(value[0])) {
*cset->loci = (int32_t)strtol(value, (char **)NULL, 0);
if (debug)
printf(" i: %s -> \"%s\": %d\n", cfgline, cset->name, *cset->loci);
void configlocale(void)
{
- if (cfg.locale[0]!='-' && strlen(cfg.locale)>0) {
+ if (cfg.locale[0] != '-' && strlen(cfg.locale) > 0) {
setlocale(LC_ALL, cfg.locale);
} else {
if (getenv("LC_ALL")) {
printf("CTx \"%s\"\n", cfg.ctx);
printf("CRxD \"%s\"\n", cfg.crxd);
printf("CTxD \"%s\"\n", cfg.ctxd);
-
}
char errorstring[1024];
ibwnode *ifacebw;
int debug;
-int noexit; /* = running as daemon if 2 */
+int noexit; /* = running as daemon if 2 */
int intsignal;
int pidfile;
int disableprints;
-
int printe(const PrintType type)
{
int result = 1;
if (disableprints) {
return 1;
- /* daemon running but log not enabled */
- } else if (noexit==2 && cfg.uselogging==0) {
+ /* daemon running but log not enabled */
+ } else if (noexit == 2 && cfg.uselogging == 0) {
return 1;
- /* daemon running, log enabled */
- } else if (noexit==2) {
+ /* daemon running, log enabled */
+ } else if (noexit == 2) {
switch (type) {
case PT_Multiline:
break;
}
- /* daemon isn't running */
+ /* daemon isn't running */
} else {
switch (type) {
buffer[0] = '\0';
/* logfile */
- if (cfg.uselogging==1) {
+ if (cfg.uselogging == 1) {
if (type == PT_Multiline) {
return 0;
break;
}
- if (fwrite(buffer, strlen(buffer), 1, logfile)!=1) {
+ if (fwrite(buffer, strlen(buffer), 1, logfile) != 1) {
fclose(logfile);
return 0;
}
fclose(logfile);
return 1;
- /* syslog */
- } else if (cfg.uselogging==2) {
+ /* syslog */
+ } else if (cfg.uselogging == 2) {
openlog("vnstatd", LOG_PID, LOG_DAEMON);
FILE *logfile;
/* only logfile logging can be verified */
- if (cfg.uselogging==1) {
+ if (cfg.uselogging == 1) {
if ((logfile = fopen(cfg.logfile, "a")) == NULL) {
return 0;
}
time_t current;
/* handle leap years */
- if (month==1) {
+ if (month == 1) {
current = time(NULL);
year = localtime(¤t)->tm_year + 1900;
if (isleapyear(year)) {
d.tm_mday = cfg.monthrotate;
d.tm_hour = d.tm_min = d.tm_sec = 0;
- if ((updated-month)>0) {
- return updated-mktime(&d);
+ if ((updated - month) > 0) {
+ return updated - mktime(&d);
} else {
return 1;
}
/* no rollover */
if (*b >= *a) {
if (debug)
- printf("cc (%d): %"PRIu64" - %"PRIu64" = %"PRIu64"\n", is64bit, *b, *a, *b-*a);
- return *b-*a;
+ printf("cc (%d): %" PRIu64 " - %" PRIu64 " = %" PRIu64 "\n", is64bit, *b, *a, *b - *a);
+ return *b - *a;
- /* rollover exists */
+ /* rollover exists */
} else {
/* counter is 64bit */
if (*a > MAX32 || is64bit == 1) {
if (debug)
- printf("cc64 (%d): uint64 - %"PRIu64" + %"PRIu64" = %"PRIu64"\n", is64bit, *a, *b, (uint64_t)MAX64-*a+*b);
- return MAX64-*a+*b;
+ printf("cc64 (%d): uint64 - %" PRIu64 " + %" PRIu64 " = %" PRIu64 "\n", is64bit, *a, *b, (uint64_t)MAX64 - *a + *b);
+ return MAX64 - *a + *b;
- /* counter is 32bit */
+ /* counter is 32bit */
} else {
if (debug)
- printf("cc32 (%d): uint32 - %"PRIu64" + %"PRIu64" = %"PRIu64"\n", is64bit, *a, *b, (uint64_t)MAX32-*a+*b);
- return MAX32-*a+*b;
+ printf("cc32 (%d): uint32 - %" PRIu64 " + %" PRIu64 " = %" PRIu64 "\n", is64bit, *a, *b, (uint64_t)MAX32 - *a + *b);
+ return MAX32 - *a + *b;
}
}
}
char *strncpy_nt(char *dest, const char *src, size_t n)
{
strncpy(dest, src, n);
- dest[n-1] = '\0';
+ dest[n - 1] = '\0';
return dest;
}
return 0;
}
- for (i=0; i<len; i++) {
+ for (i = 0; i < len; i++) {
if (!isdigit(s[i])) {
return 0;
}
return 1;
}
-__attribute__((noreturn))
-void panicexit(const char *sourcefile, const int sourceline)
+__attribute__((noreturn)) void panicexit(const char *sourcefile, const int sourceline)
{
snprintf(errorstring, 1024, "Unexpected error (%s), exiting. (%s:%d)", strerror(errno), sourcefile, sourceline);
fprintf(stderr, "%s\n", errorstring);
int i;
static char versionbuffer[16];
strncpy_nt(versionbuffer, VERSION, 16);
- for (i=0; i<(int)strlen(versionbuffer); i++) {
+ for (i = 0; i < (int)strlen(versionbuffer); i++) {
if (versionbuffer[i] == '_') {
versionbuffer[i] = ' ';
}
/* OpenBSD and NetBSD don't support the ' character (decimal conversion) in printf formatting */
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
- #define DECCONV "'"
+#define DECCONV "'"
#else
- #define DECCONV
+#define DECCONV
#endif
/* used in debug to get function name */
#if __STDC_VERSION__ < 199901L
- #if __GNUC__ >= 2
- #define __func__ __FUNCTION__
- #else
- #define __func__ "function"
- #endif
+#if __GNUC__ >= 2
+#define __func__ __FUNCTION__
+#else
+#define __func__ "function"
+#endif
#endif
/*
/* location of the database directory */
#ifndef DATABASEDIR
- #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
- #define DATABASEDIR "/var/db/vnstat"
- #else
- #define DATABASEDIR "/var/lib/vnstat"
- #endif
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
+#define DATABASEDIR "/var/db/vnstat"
+#else
+#define DATABASEDIR "/var/lib/vnstat"
+#endif
#endif
/* database file name */
/* date output formats for -d, -m, -t and image header*/
/* see 'man date' for control codes 1.x values <1.8 values */
-#define DFORMAT "%Y-%m-%d" /* "%x" "%d.%m." */
-#define MFORMAT "%Y-%m" /* "%b '%y" "%b '%y" */
-#define TFORMAT "%Y-%m-%d" /* "%x" "%d.%m.%y" */
-#define HFORMAT "%Y-%m-%d %H:%M" /* "%x %H:%M" "%d.%m.%Y %H:%M" */
+#define DFORMAT "%Y-%m-%d" /* "%x" "%d.%m." */
+#define MFORMAT "%Y-%m" /* "%b '%y" "%b '%y" */
+#define TFORMAT "%Y-%m-%d" /* "%x" "%d.%m.%y" */
+#define HFORMAT "%Y-%m-%d %H:%M" /* "%x %H:%M" "%d.%m.%Y %H:%M" */
#ifndef DATETIMEFORMAT
#define DATETIMEFORMAT "%Y-%m-%d %H:%M:%S"
extern char errorstring[1024];
extern ibwnode *ifacebw;
extern int debug;
-extern int noexit; /* = running as daemon if 2 */
+extern int noexit; /* = running as daemon if 2 */
extern int intsignal;
extern int pidfile;
extern int disableprints;
int i;
char str[10];
- if (getppid()==1) {
+ if (getppid() == 1) {
return; /* already a daemon */
}
i = (int)fork();
- if (i<0) { /* fork error */
+ if (i < 0) { /* fork error */
perror("Error: fork");
exit(EXIT_FAILURE);
}
- if (i>0) { /* parent exits */
+ if (i > 0) { /* parent exits */
exit(EXIT_SUCCESS);
}
/* child (daemon) continues */
}
/* lock / pid file */
- pidfile = open(cfg.pidfile, O_RDWR|O_CREAT, 0644);
- if (pidfile<0) {
+ pidfile = open(cfg.pidfile, O_RDWR | O_CREAT, 0644);
+ if (pidfile < 0) {
perror("Error: pidfile");
snprintf(errorstring, 1024, "opening pidfile \"%s\" failed (%s), exiting.", cfg.pidfile, strerror(errno));
printe(PT_Error);
exit(EXIT_FAILURE); /* can't open */
}
- if (lockf(pidfile,F_TLOCK,0)<0) {
+ if (lockf(pidfile, F_TLOCK, 0) < 0) {
perror("Error: pidfile lock");
snprintf(errorstring, 1024, "pidfile \"%s\" lock failed (%s), exiting.", cfg.pidfile, strerror(errno));
printe(PT_Error);
}
/* close all descriptors except lock file */
- for (i=getdtablesize();i>=0;--i) {
- if (i!=pidfile) {
+ for (i = getdtablesize(); i >= 0; --i) {
+ if (i != pidfile) {
close(i);
}
}
/* redirect standard i/o to null */
- i=open("/dev/null",O_RDWR); /* stdin */
+ i = open("/dev/null", O_RDWR); /* stdin */
if (i < 0) {
perror("Error: open() /dev/null");
snprintf(str, 10, "%d\n", (int)getpid());
/* record pid to pidfile */
- if (write(pidfile,str,strlen(str)) < 0) {
+ if (write(pidfile, str, strlen(str)) < 0) {
perror("Error: write(pidfile)");
snprintf(errorstring, 1024, "writing to pidfile \"%s\" failed (%s), exiting.", cfg.pidfile, strerror(errno));
printe(PT_Error);
exit(EXIT_FAILURE);
}
- signal(SIGCHLD,SIG_IGN); /* ignore child */
- signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
- signal(SIGTTOU,SIG_IGN);
- signal(SIGTTIN,SIG_IGN);
+ signal(SIGCHLD, SIG_IGN); /* ignore child */
+ signal(SIGTSTP, SIG_IGN); /* ignore tty signals */
+ signal(SIGTTOU, SIG_IGN);
+ signal(SIGTTIN, SIG_IGN);
}
unsigned int addinterfaces(DSTATE *s)
timeused(__func__, 1);
/* get list of currently visible interfaces */
- if (getiflist(&ifacelist, 0)==0) {
+ if (getiflist(&ifacelist, 0) == 0) {
free(ifacelist);
return 0;
}
- if (strlen(ifacelist)<2) {
+ if (strlen(ifacelist) < 2) {
free(ifacelist);
return 0;
}
if (debug)
printf("Interface list: \"%s\"\n", ifacelist);
- while (sscanf(ifacelist+index, "%31s", interface)!=EOF) {
+ while (sscanf(ifacelist + index, "%31s", interface) != EOF) {
if (debug)
printf("Processing: \"%s\"\n", interface);
- index += strlen(interface)+1;
+ index += strlen(interface) + 1;
/* skip local interfaces */
- if ((strcmp(interface,"lo")==0) || (strcmp(interface,"lo0")==0) || (strcmp(interface,"sit0")==0)) {
+ if ((strcmp(interface, "lo") == 0) || (strcmp(interface, "lo0") == 0) || (strcmp(interface, "sit0") == 0)) {
if (debug)
printf("skip\n");
continue;
count++;
ibwget(interface, &bwlimit);
if (bwlimit > 0) {
- snprintf(errorstring, 1024, "Interface \"%s\" added with %"PRIu32" Mbit bandwidth limit.", interface, bwlimit);
+ snprintf(errorstring, 1024, "Interface \"%s\" added with %" PRIu32 " Mbit bandwidth limit.", interface, bwlimit);
} else {
snprintf(errorstring, 1024, "Interface \"%s\" added. Warning: no bandwidth limit has been set.", interface);
}
if (current_btime == 0) {
return;
} else if (strlen(btime_buffer) == 0) {
- snprintf(buffer, 32, "%"PRIu64"", current_btime);
+ snprintf(buffer, 32, "%" PRIu64 "", current_btime);
db_setinfo("btime", buffer, 1);
return;
}
db_btime = strtoull(btime_buffer, (char **)NULL, 0);
- if (db_btime < (current_btime-(uint32_t)cfg.bvar)) {
+ if (db_btime < (current_btime - (uint32_t)cfg.bvar)) {
s->bootdetected = 1;
if (debug)
- printf("System has been booted, %"PRIu64" < %"PRIu64" - %d\n", db_btime, current_btime, cfg.bvar);
+ printf("System has been booted, %" PRIu64 " < %" PRIu64 " - %d\n", db_btime, current_btime, cfg.bvar);
}
- snprintf(buffer, 32, "%"PRIu64"", current_btime);
+ snprintf(buffer, 32, "%" PRIu64 "", current_btime);
db_setinfo("btime", buffer, 1);
}
void initdstate(DSTATE *s)
{
- noexit = 1; /* disable exits in functions */
- debug = 0; /* debug disabled by default */
+ noexit = 1; /* disable exits in functions */
+ debug = 0; /* debug disabled by default */
disableprints = 0; /* let prints be visible */
s->rundaemon = 0; /* daemon disabled by default */
}
if (debug) {
- printf("db if count: %"PRIu64"\n", s->dbifcount);
+ printf("db if count: %" PRIu64 "\n", s->dbifcount);
}
if (s->noadd) {
struct dirent *di;
unsigned int importcount = 0;
- if ((dir=opendir(s->dirname))==NULL) {
+ if ((dir = opendir(s->dirname)) == NULL) {
printf("Error: Unable to open database directory \"%s\": %s\n", s->dirname, strerror(errno));
printf("Make sure it exists and is at least read enabled for current user.\n");
printf("Exiting...\n");
}
s->dbifcount = 0;
- while ((di=readdir(dir))) {
- if ((di->d_name[0]!='.') && (strcmp(di->d_name, DATABASEFILE)!=0)) {
+ while ((di = readdir(dir))) {
+ if ((di->d_name[0] != '.') && (strcmp(di->d_name, DATABASEFILE) != 0)) {
/* ignore already known interfaces */
if (db_getinterfacecountbyname(di->d_name)) {
continue;
if ((*dc)->updated > ifinfo.timestamp) {
/* skip update if previous update is less than a day in the future */
/* otherwise exit with error message since the clock is problably messed */
- if ((*dc)->updated > (ifinfo.timestamp+86400)) {
+ if ((*dc)->updated > (ifinfo.timestamp + 86400)) {
snprintf(errorstring, 1024, "Interface \"%s\" has previous update date too much in the future, exiting. (%u / %u)", (*dc)->interface, (unsigned int)(*dc)->updated, (unsigned int)ifinfo.timestamp);
printe(PT_Error);
errorexitdaemon(s, 1);
interval = ifinfo.timestamp - (*dc)->updated;
/* maximum configurable update interval is 5 minutes, limit here is set to 6 minutes (360 seconds) */
/* in order to be on the safe side and avoid discarding data in case there's some random extra delay */
- if ( (interval >= 1) && (interval <= 360) ) {
+ if ((interval >= 1) && (interval <= 360)) {
rxchange = countercalc(&(*dc)->currx, &ifinfo.rx, ifinfo.is64bit);
txchange = countercalc(&(*dc)->curtx, &ifinfo.tx, ifinfo.is64bit);
/* calculate maximum possible transfer since last update based on set maximum rate */
/* and add 10% in order to be on the safe side */
- maxtransfer = (uint64_t)(ceilf((maxbw/(float)8)*interval*(float)1.1)) * 1024 * 1024;
+ maxtransfer = (uint64_t)(ceilf((maxbw / (float)8) * interval * (float)1.1)) * 1024 * 1024;
if (debug)
- printf("interval: %"PRIu64" maxbw: %"PRIu32" maxrate: %"PRIu64" rxc: %"PRIu64" txc: %"PRIu64"\n", (uint64_t)interval, maxbw, maxtransfer, rxchange, txchange);
+ printf("interval: %" PRIu64 " maxbw: %" PRIu32 " maxrate: %" PRIu64 " rxc: %" PRIu64 " txc: %" PRIu64 "\n", (uint64_t)interval, maxbw, maxtransfer, rxchange, txchange);
/* sync counters if traffic is greater than set maximum */
- if ( (rxchange > maxtransfer) || (txchange > maxtransfer) ) {
- snprintf(errorstring, 1024, "Traffic rate for \"%s\" higher than set maximum %"PRIu32" Mbit (%"PRIu64"->%"PRIu64", r%"PRIu64" t%"PRIu64"), syncing.", (*dc)->interface, maxbw, (uint64_t)interval, maxtransfer, rxchange, txchange);
+ if ((rxchange > maxtransfer) || (txchange > maxtransfer)) {
+ snprintf(errorstring, 1024, "Traffic rate for \"%s\" higher than set maximum %" PRIu32 " Mbit (%" PRIu64 "->%" PRIu64 ", r%" PRIu64 " t%" PRIu64 "), syncing.", (*dc)->interface, maxbw, (uint64_t)interval, maxtransfer, rxchange, txchange);
printe(PT_Info);
rxchange = txchange = 0;
}
b = (unsigned int)strlen(buffer) + 1;
while (iterator != NULL) {
- if ((b+strlen(iterator->interface)+16) < 1020) {
+ if ((b + strlen(iterator->interface) + 16) < 1020) {
if (!ibwget(iterator->interface, &bwlimit) || bwlimit == 0) {
snprintf(bwtemp, 16, " (no limit) ");
} else {
- snprintf(bwtemp, 16, " (%"PRIu32" Mbit) ", bwlimit);
+ snprintf(bwtemp, 16, " (%" PRIu32 " Mbit) ", bwlimit);
}
strcat(buffer, iterator->interface);
strcat(buffer, bwtemp);
timeused(__func__, 1);
/* get list of currently visible interfaces */
- if (getiflist(&ifacelist, 0)==0) {
+ if (getiflist(&ifacelist, 0) == 0) {
free(ifacelist);
s->iflisthash = 0;
return;
found = offset = 0;
while (offset <= (int)strlen(ifacelist)) {
- sscanf(ifacelist+offset, "%31s", interface);
+ sscanf(ifacelist + offset, "%31s", interface);
if (strcmp(iterator->interface, interface) == 0) {
found = 1;
break;
return hash;
}
-__attribute__((noreturn))
-void errorexitdaemon(DSTATE *s, const int fataldberror)
+__attribute__((noreturn)) void errorexitdaemon(DSTATE *s, const int fataldberror)
{
if (!fataldberror) {
flushcachetodisk(s);
snprintf(errorstring, 1024, "Latest database update is in the future (db: %s > now: %s). Giving the system clock up to %d minutes to sync before continuing.", timestamp2, timestamp, cfg.timesyncwait);
printe(PT_Info);
}
- if (s->current - s->prevdbupdate >= cfg.timesyncwait*60) {
+ if (s->current - s->prevdbupdate >= cfg.timesyncwait * 60) {
strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current));
strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave));
snprintf(errorstring, 1024, "Latest database update is still in the future (db: %s > now: %s), continuing. Some errors may follow.", timestamp2, timestamp);
printf(" xferlog: ");
}
while (logiterator != NULL) {
- printf("%d: %"PRIu64" - %"PRIu64" / %"PRIu64"", i, (uint64_t)logiterator->timestamp, logiterator->rx, logiterator->tx);
+ printf("%d: %" PRIu64 " - %" PRIu64 " / %" PRIu64 "", i, (uint64_t)logiterator->timestamp, logiterator->rx, logiterator->tx);
if (logiterator->next != NULL) {
printf(", ");
}
}
for (i = 23; i >= 0; i--) {
- if (data->hour[i].date > 0 && ( data->hour[i].rx > 0 || data->hour[i].tx > 0 )) {
- if (!db_insertdata("hour", iface, data->hour[i].rx*1024, data->hour[i].tx*1024, (uint64_t)data->hour[i].date)) {
+ if (data->hour[i].date > 0 && (data->hour[i].rx > 0 || data->hour[i].tx > 0)) {
+ if (!db_insertdata("hour", iface, data->hour[i].rx * 1024, data->hour[i].tx * 1024, (uint64_t)data->hour[i].date)) {
db_rollbacktransaction();
return 0;
}
}
for (i = 29; i >= 0; i--) {
if (data->day[i].used) {
- if (!db_insertdata("day", iface, data->day[i].rx*1024*1024+(uint64_t)data->day[i].rxk*1024, data->day[i].tx*1024*1024+(uint64_t)data->day[i].txk*1024, (uint64_t)data->day[i].date)) {
+ if (!db_insertdata("day", iface, data->day[i].rx * 1024 * 1024 + (uint64_t)data->day[i].rxk * 1024, data->day[i].tx * 1024 * 1024 + (uint64_t)data->day[i].txk * 1024, (uint64_t)data->day[i].date)) {
db_rollbacktransaction();
return 0;
}
}
for (i = 11; i >= 0; i--) {
if (data->month[i].used) {
- if (!db_insertdata("month", iface, data->month[i].rx*1024*1024+(uint64_t)data->month[i].rxk*1024, data->month[i].tx*1024*1024+(uint64_t)data->month[i].txk*1024, (uint64_t)data->month[i].month)) {
+ if (!db_insertdata("month", iface, data->month[i].rx * 1024 * 1024 + (uint64_t)data->month[i].rxk * 1024, data->month[i].tx * 1024 * 1024 + (uint64_t)data->month[i].txk * 1024, (uint64_t)data->month[i].month)) {
db_rollbacktransaction();
return 0;
}
}
for (i = 9; i >= 0; i--) {
if (data->top10[i].used) {
- if (!db_insertdata("top", iface, data->top10[i].rx*1024*1024+(uint64_t)data->top10[i].rxk*1024, data->top10[i].tx*1024*1024+(uint64_t)data->top10[i].txk*1024, (uint64_t)data->top10[i].date)) {
+ if (!db_insertdata("top", iface, data->top10[i].rx * 1024 * 1024 + (uint64_t)data->top10[i].rxk * 1024, data->top10[i].tx * 1024 * 1024 + (uint64_t)data->top10[i].txk * 1024, (uint64_t)data->top10[i].date)) {
db_rollbacktransaction();
return 0;
}
}
stm = localtime(&data->month[i].month);
/* sanity check for possible invalid data */
- if (stm->tm_year+1900 <= 1980 || stm->tm_year+1900 >= 2050) {
+ if (stm->tm_year + 1900 <= 1980 || stm->tm_year + 1900 >= 2050) {
continue;
}
- if (stm->tm_year+1900 != year) {
- if (year != 0 && ( rx > 0 || tx > 0 )) {
+ if (stm->tm_year + 1900 != year) {
+ if (year != 0 && (rx > 0 || tx > 0)) {
if (!db_insertdata("year", iface, rx, tx, (uint64_t)yeartime)) {
db_rollbacktransaction();
return 0;
rx = 0;
tx = 0;
}
- rx += data->month[i].rx*1024*1024+(uint64_t)data->month[i].rxk*1024;
- tx += data->month[i].tx*1024*1024+(uint64_t)data->month[i].txk*1024;
+ rx += data->month[i].rx * 1024 * 1024 + (uint64_t)data->month[i].rxk * 1024;
+ tx += data->month[i].tx * 1024 * 1024 + (uint64_t)data->month[i].txk * 1024;
}
- if (year != 0 && ( rx > 0 || tx > 0 )) {
+ if (year != 0 && (rx > 0 || tx > 0)) {
if (!db_insertdata("year", iface, rx, tx, (uint64_t)yeartime)) {
db_rollbacktransaction();
return 0;
}
}
- if (!db_settotal(iface, data->totalrx*1024*1024+(uint64_t)data->totalrxk*1024, data->totaltx*1024*1024+(uint64_t)data->totaltxk*1024)) {
+ if (!db_settotal(iface, data->totalrx * 1024 * 1024 + (uint64_t)data->totalrxk * 1024, data->totaltx * 1024 * 1024 + (uint64_t)data->totaltxk * 1024)) {
db_rollbacktransaction();
return 0;
}
snprintf(file, 512, "%s/%s", dirname, iface);
snprintf(backup, 512, "%s/.%s", dirname, iface);
- if ((legacydb=fopen(file,"r"))==NULL) {
+ if ((legacydb = fopen(file, "r")) == NULL) {
snprintf(errorstring, 1024, "Unable to read database \"%s\": %s", file, strerror(errno));
printe(PT_Error);
return 1;
}
- if (fread(data,sizeof(DATA),1,legacydb)!=1 || ferror(legacydb)) {
- data->version=-1;
+ if (fread(data, sizeof(DATA), 1, legacydb) != 1 || ferror(legacydb)) {
+ data->version = -1;
if (debug) {
printf("db: Database read failed for file \"%s\".\n", file);
}
if (data->version == LEGACYDBVERSION) {
if (!validatedb(data) && !force) {
- data->version=-1;
+ data->version = -1;
if (debug) {
printf("db: Database for interface \"%s\" fails to validate, trying with backup\n", data->interface);
}
}
/* convert old database to new format if necessary */
- if (data->version<LEGACYDBVERSION) {
- if (data->version==-1) {
+ if (data->version < LEGACYDBVERSION) {
+ if (data->version == -1) {
/* close current db and try using backup if database conversion failed */
fclose(legacydb);
- if ((legacydb=fopen(backup,"r"))==NULL) {
+ if ((legacydb = fopen(backup, "r")) == NULL) {
snprintf(errorstring, 1024, "Unable to open backup database \"%s\": %s", backup, strerror(errno));
printe(PT_Error);
if (noexit) {
}
}
- if (fread(data,sizeof(DATA),1,legacydb)!=1 || ferror(legacydb)) {
+ if (fread(data, sizeof(DATA), 1, legacydb) != 1 || ferror(legacydb)) {
snprintf(errorstring, 1024, "Database load failed even when using backup (%s). Aborting.", strerror(errno));
printe(PT_Error);
fclose(legacydb);
if (data->version == LEGACYDBVERSION) {
if (!validatedb(data)) {
- data->version=-1;
+ data->version = -1;
if (debug) {
printf("db: Backup database for interface \"%s\" fails to validate\n", data->interface);
}
}
}
- if (data->version!=LEGACYDBVERSION) {
- if (data->version==-1) {
+ if (data->version != LEGACYDBVERSION) {
+ if (data->version == -1) {
snprintf(errorstring, 1024, "Unable to use database \"%s\" or its backup.", file);
printe(PT_Error);
fclose(legacydb);
printe(PT_Info);
}
- } else if (data->version>LEGACYDBVERSION) {
+ } else if (data->version > LEGACYDBVERSION) {
snprintf(errorstring, 1024, "Downgrading database \"%s\" (v%d) is not supported.", file, data->version);
printe(PT_Error);
fclose(legacydb);
fclose(legacydb);
- if (strcmp(data->interface,iface)) {
- snprintf(errorstring, 1024, "Warning:\nThe previous interface for this file was \"%s\".",data->interface);
+ if (strcmp(data->interface, iface)) {
+ snprintf(errorstring, 1024, "Warning:\nThe previous interface for this file was \"%s\".", data->interface);
printe(PT_Multiline);
- snprintf(errorstring, 1024, "It has now been replaced with \"%s\".",iface);
+ snprintf(errorstring, 1024, "It has now been replaced with \"%s\".", iface);
printe(PT_Multiline);
snprintf(errorstring, 1024, "You can ignore this message if you renamed the filename.");
printe(PT_Multiline);
snprintf(errorstring, 1024, "Interface name mismatch, renamed \"%s\" -> \"%s\"", data->interface, iface);
printe(PT_ShortMultiline);
- if (strcmp(data->interface, data->nick)==0) {
+ if (strcmp(data->interface, data->nick) == 0) {
strncpy_nt(data->nick, iface, 32);
}
strncpy_nt(data->interface, iface, 32);
time_t current;
struct tm *d;
- current=time(NULL);
- d=localtime(¤t);
+ current = time(NULL);
+ d = localtime(¤t);
/* set default values for a new database */
- data->version=LEGACYDBVERSION;
- data->active=1;
- data->totalrx=0;
- data->totaltx=0;
- data->currx=0;
- data->curtx=0;
- data->totalrxk=0;
- data->totaltxk=0;
- data->lastupdated=current;
- data->created=current;
+ data->version = LEGACYDBVERSION;
+ data->active = 1;
+ data->totalrx = 0;
+ data->totaltx = 0;
+ data->currx = 0;
+ data->curtx = 0;
+ data->totalrxk = 0;
+ data->totaltxk = 0;
+ data->lastupdated = current;
+ data->created = current;
/* days */
- for (i=0;i<=29;i++) {
- data->day[i].rx=0;
- data->day[i].tx=0;
- data->day[i].rxk=0;
- data->day[i].txk=0;
- data->day[i].date=0;
- data->day[i].used=0;
+ for (i = 0; i <= 29; i++) {
+ data->day[i].rx = 0;
+ data->day[i].tx = 0;
+ data->day[i].rxk = 0;
+ data->day[i].txk = 0;
+ data->day[i].date = 0;
+ data->day[i].used = 0;
}
/* months */
- for (i=0;i<=11;i++) {
- data->month[i].rx=0;
- data->month[i].tx=0;
- data->month[i].rxk=0;
- data->month[i].txk=0;
- data->month[i].month=0;
- data->month[i].used=0;
+ for (i = 0; i <= 11; i++) {
+ data->month[i].rx = 0;
+ data->month[i].tx = 0;
+ data->month[i].rxk = 0;
+ data->month[i].txk = 0;
+ data->month[i].month = 0;
+ data->month[i].used = 0;
}
/* top10 */
- for (i=0;i<=9;i++) {
- data->top10[i].rx=0;
- data->top10[i].tx=0;
- data->top10[i].rxk=0;
- data->top10[i].txk=0;
- data->top10[i].date=0;
- data->top10[i].used=0;
+ for (i = 0; i <= 9; i++) {
+ data->top10[i].rx = 0;
+ data->top10[i].tx = 0;
+ data->top10[i].rxk = 0;
+ data->top10[i].txk = 0;
+ data->top10[i].date = 0;
+ data->top10[i].used = 0;
}
/* hours */
- for (i=0;i<=23;i++) {
- data->hour[i].rx=0;
- data->hour[i].tx=0;
- data->hour[i].date=0;
+ for (i = 0; i <= 23; i++) {
+ data->hour[i].rx = 0;
+ data->hour[i].tx = 0;
+ data->hour[i].date = 0;
}
- data->day[0].used=data->month[0].used=1;
- data->day[0].date=current;
+ data->day[0].used = data->month[0].used = 1;
+ data->day[0].date = current;
/* calculate new date for current month if current day is less
than the set monthrotate value so that new databases begin
from the right month */
if (d->tm_mday < cfg.monthrotate) {
- d->tm_mday=cfg.monthrotate;
+ d->tm_mday = cfg.monthrotate;
d->tm_mon--;
- data->month[0].month=mktime(d);
+ data->month[0].month = mktime(d);
} else {
- data->month[0].month=current;
+ data->month[0].month = current;
}
- data->btime=MAX32;
+ data->btime = MAX32;
}
int removedb(const char *iface, const char *dirname)
unlink(file);
snprintf(file, 512, "%s/%s", dirname, iface);
- if (unlink(file)!=0) {
+ if (unlink(file) != 0) {
return 0;
}
}
/* enforce string termination */
- data->interface[sizeof(data->interface)-1] = '\0';
- data->nick[sizeof(data->nick)-1] = '\0';
+ data->interface[sizeof(data->interface) - 1] = '\0';
+ data->nick[sizeof(data->nick) - 1] = '\0';
- if (data->version>LEGACYDBVERSION) {
+ if (data->version > LEGACYDBVERSION) {
snprintf(errorstring, 1024, "%s: %s version: %d", data->interface, invaliddb, data->version);
printe(PT_Error);
return 0;
}
- if (data->active<0 || data->active>1) {
+ if (data->active < 0 || data->active > 1) {
snprintf(errorstring, 1024, "%s: %s activity status: %d", data->interface, invaliddb, data->active);
printe(PT_Error);
return 0;
rxsum = txsum = 0;
used = 1;
- for (i=0; i<30; i++) {
- if (data->day[i].used<0 || data->day[i].used>1) {
+ for (i = 0; i < 30; i++) {
+ if (data->day[i].used < 0 || data->day[i].used > 1) {
snprintf(errorstring, 1024, "%s: %s daily use information: %d %d", data->interface, invaliddb, i, data->day[i].used);
printe(PT_Error);
return 0;
}
- if (data->day[i].rxk<0 || data->day[i].txk<0) {
+ if (data->day[i].rxk < 0 || data->day[i].txk < 0) {
snprintf(errorstring, 1024, "%s: %s daily traffic: %d", data->interface, invaliddb, i);
printe(PT_Error);
return 0;
}
}
- for (i=1; i<30; i++) {
+ for (i = 1; i < 30; i++) {
if (!data->day[i].used) {
break;
}
- if (data->day[i-1].date < data->day[i].date) {
- snprintf(errorstring, 1024, "%s: %s daily date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->day[i-1].date, i-1, (unsigned int)data->day[i].date, i);
+ if (data->day[i - 1].date < data->day[i].date) {
+ snprintf(errorstring, 1024, "%s: %s daily date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->day[i - 1].date, i - 1, (unsigned int)data->day[i].date, i);
printe(PT_Error);
return 0;
}
rxsum = txsum = 0;
used = 1;
- for (i=0; i<12; i++) {
- if (data->month[i].used<0 || data->month[i].used>1) {
+ for (i = 0; i < 12; i++) {
+ if (data->month[i].used < 0 || data->month[i].used > 1) {
snprintf(errorstring, 1024, "%s: %s monthly use information: %d %d", data->interface, invaliddb, i, data->month[i].used);
printe(PT_Error);
return 0;
}
- if (data->month[i].rxk<0 || data->month[i].txk<0) {
+ if (data->month[i].rxk < 0 || data->month[i].txk < 0) {
snprintf(errorstring, 1024, "%s: %s monthly traffic: %d", data->interface, invaliddb, i);
printe(PT_Error);
return 0;
}
}
- for (i=1; i<12; i++) {
+ for (i = 1; i < 12; i++) {
if (!data->month[i].used) {
break;
}
- if (data->month[i-1].month < data->month[i].month) {
- snprintf(errorstring, 1024, "%s: %s monthly date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->month[i-1].month, i-1, (unsigned int)data->month[i].month, i);
+ if (data->month[i - 1].month < data->month[i].month) {
+ snprintf(errorstring, 1024, "%s: %s monthly date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->month[i - 1].month, i - 1, (unsigned int)data->month[i].month, i);
printe(PT_Error);
return 0;
}
}
used = 1;
- for (i=0; i<10; i++) {
- if (data->top10[i].used<0 || data->top10[i].used>1) {
+ for (i = 0; i < 10; i++) {
+ if (data->top10[i].used < 0 || data->top10[i].used > 1) {
snprintf(errorstring, 1024, "%s: %s top10 use information: %d %d", data->interface, invaliddb, i, data->top10[i].used);
printe(PT_Error);
return 0;
}
- if (data->top10[i].rxk<0 || data->top10[i].txk<0) {
+ if (data->top10[i].rxk < 0 || data->top10[i].txk < 0) {
snprintf(errorstring, 1024, "%s: %s top10 traffic: %d", data->interface, invaliddb, i);
printe(PT_Error);
return 0;
/* from the legacy database format => don't modify */
#if defined(__clang__)
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wpadded"
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpadded"
#endif
typedef struct {
time_t date;
uint64_t btime;
} DATA;
#if defined(__clang__)
- #pragma clang diagnostic pop
+#pragma clang diagnostic pop
#endif
int importlegacydb(const char *iface, const char *dirname);
printf("},");
printf("\"traffic\":");
- printf("{\"total\":{\"rx\":%"PRIu64",\"tx\":%"PRIu64"},", info.rxtotal, info.txtotal);
+ printf("{\"total\":{\"rx\":%" PRIu64 ",\"tx\":%" PRIu64 "},", info.rxtotal, info.txtotal);
switch (mode) {
case 'd':
} else {
first = 0;
}
- printf("{\"id\":%"PRId64",", datalist_i->rowid);
+ printf("{\"id\":%" PRId64 ",", datalist_i->rowid);
jsondate(&datalist_i->timestamp, datetype);
- printf(",\"rx\":%"PRIu64",\"tx\":%"PRIu64"}", datalist_i->rx, datalist_i->tx);
+ printf(",\"rx\":%" PRIu64 ",\"tx\":%" PRIu64 "}", datalist_i->rx, datalist_i->tx);
datalist_i = datalist_i->next;
}
dbdatalistfree(&datalist);
switch (type) {
case 1:
- printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d}", \
- 1900+d->tm_year, 1+d->tm_mon, d->tm_mday);
+ printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d}",
+ 1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday);
break;
case 2:
- printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d},\"time\":{\"hour\":%d,\"minute\":%d}", \
- 1900+d->tm_year, 1+d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min);
+ printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d},\"time\":{\"hour\":%d,\"minute\":%d}",
+ 1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min);
break;
case 3:
- printf("\"date\":{\"year\":%d,\"month\":%d}", \
- 1900+d->tm_year, 1+d->tm_mon);
+ printf("\"date\":{\"year\":%d,\"month\":%d}",
+ 1900 + d->tm_year, 1 + d->tm_mon);
break;
case 4:
- printf("\"date\":{\"year\":%d}", \
- 1900+d->tm_year);
+ printf("\"date\":{\"year\":%d}",
+ 1900 + d->tm_year);
break;
default:
break;
return;
}
- switch(qmode) {
+ switch (qmode) {
case 0:
showsummary(&info, 0);
break;
timeused(__func__, 1);
- current=time(NULL);
- yesterday=current-86400;
+ current = time(NULL);
+ yesterday = current - 86400;
- e_rx=e_tx=0;
+ e_rx = e_tx = 0;
if (interface->updated && !shortmode) {
strftime(datebuff, DATEBUFFLEN, DATETIMEFORMAT, localtime(&interface->updated));
printf(":\n");
} else {
/* get formatted date for creation date */
- d=localtime(&interface->created);
+ d = localtime(&interface->created);
strftime(datebuff, DATEBUFFLEN, cfg.tformat, d);
printf(" since %s\n\n", datebuff);
indent(3);
printf(" tx: %s", getvalue(interface->txtotal, 1, RT_Normal));
indent(3);
- printf(" total: %s\n\n", getvalue(interface->rxtotal+interface->txtotal, 1, RT_Normal));
+ printf(" total: %s\n\n", getvalue(interface->rxtotal + interface->txtotal, 1, RT_Normal));
indent(3);
printf("monthly\n");
while (datalist_i != NULL) {
indent(5);
d = localtime(&datalist_i->timestamp);
- if (strftime(datebuff, DATEBUFFLEN, cfg.mformat, d)<=8) {
+ if (strftime(datebuff, DATEBUFFLEN, cfg.mformat, d) <= 8) {
printf("%*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
} else {
printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
}
printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, RT_Normal));
- printf("%s%s", fieldseparator, getvalue(datalist_i->rx+datalist_i->tx, 11, RT_Normal));
+ printf("%s%s", fieldseparator, getvalue(datalist_i->rx + datalist_i->tx, 11, RT_Normal));
if (cfg.ostyle >= 2) {
if (datalist_i->next == NULL) {
- if ( datalist_i->rx == 0 || datalist_i->tx == 0 || (interface->updated-datalist_i->timestamp) == 0 ) {
+ if (datalist_i->rx == 0 || datalist_i->tx == 0 || (interface->updated - datalist_i->timestamp) == 0) {
e_rx = e_tx = 0;
} else {
- e_rx = (uint64_t)(datalist_i->rx/(float)(mosecs(datalist_i->timestamp, interface->updated)))*(uint64_t)(dmonth(d->tm_mon)*86400);
- e_tx = (uint64_t)(datalist_i->tx/(float)(mosecs(datalist_i->timestamp, interface->updated)))*(uint64_t)(dmonth(d->tm_mon)*86400);
+ e_rx = (uint64_t)(datalist_i->rx / (float)(mosecs(datalist_i->timestamp, interface->updated))) * (uint64_t)(dmonth(d->tm_mon) * 86400);
+ e_tx = (uint64_t)(datalist_i->tx / (float)(mosecs(datalist_i->timestamp, interface->updated))) * (uint64_t)(dmonth(d->tm_mon) * 86400);
}
if (shortmode && cfg.ostyle != 0) {
- printf("%s%s", fieldseparator, getvalue(e_rx+e_tx, 11, RT_Estimate));
+ printf("%s%s", fieldseparator, getvalue(e_rx + e_tx, 11, RT_Estimate));
} else if (!shortmode) {
- printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx+datalist_i->tx, mosecs(datalist_i->timestamp, interface->updated), 14));
+ printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx + datalist_i->tx, mosecs(datalist_i->timestamp, interface->updated), 14));
}
} else if (!shortmode) {
- printf(" | %s", gettrafficrate(datalist_i->rx+datalist_i->tx, dmonth(d->tm_mon)*86400, 14));
+ printf(" | %s", gettrafficrate(datalist_i->rx + datalist_i->tx, dmonth(d->tm_mon) * 86400, 14));
}
}
printf("\n");
indent(5);
printf("estimated %s", getvalue(e_rx, 11, RT_Estimate));
printf(" | %s", getvalue(e_tx, 11, RT_Estimate));
- printf(" | %s", getvalue(e_rx+e_tx, 11, RT_Estimate));
+ printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate));
if (cfg.ostyle >= 2) {
printf(" |\n\n");
} else {
printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
}
printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, RT_Normal));
- printf("%s%s", fieldseparator, getvalue(datalist_i->rx+datalist_i->tx, 11, RT_Normal));
+ printf("%s%s", fieldseparator, getvalue(datalist_i->rx + datalist_i->tx, 11, RT_Normal));
if (cfg.ostyle >= 2) {
if (datalist_i->next == NULL) {
d = localtime(&interface->updated);
- if ( datalist_i->rx == 0 || datalist_i->tx == 0 || (d->tm_hour*60+d->tm_min) == 0 ) {
+ if (datalist_i->rx == 0 || datalist_i->tx == 0 || (d->tm_hour * 60 + d->tm_min) == 0) {
e_rx = e_tx = 0;
} else {
- e_rx = (uint64_t)((datalist_i->rx)/(float)(d->tm_hour*60+d->tm_min))*1440;
- e_tx = (uint64_t)((datalist_i->tx)/(float)(d->tm_hour*60+d->tm_min))*1440;
+ e_rx = (uint64_t)((datalist_i->rx) / (float)(d->tm_hour * 60 + d->tm_min)) * 1440;
+ e_tx = (uint64_t)((datalist_i->tx) / (float)(d->tm_hour * 60 + d->tm_min)) * 1440;
}
if (shortmode && cfg.ostyle != 0) {
- printf("%s%s", fieldseparator, getvalue(e_rx+e_tx, 11, RT_Estimate));
+ printf("%s%s", fieldseparator, getvalue(e_rx + e_tx, 11, RT_Estimate));
} else if (!shortmode) {
- printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx+datalist_i->tx, d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600), 14));
+ printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx + datalist_i->tx, d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600), 14));
}
} else if (!shortmode) {
- printf(" | %s", gettrafficrate(datalist_i->rx+datalist_i->tx, 86400, 14));
+ printf(" | %s", gettrafficrate(datalist_i->rx + datalist_i->tx, 86400, 14));
}
}
printf("\n");
indent(5);
printf("estimated %s", getvalue(e_rx, 11, RT_Estimate));
printf(" | %s", getvalue(e_tx, 11, RT_Estimate));
- printf(" | %s", getvalue(e_rx+e_tx, 11, RT_Estimate));
+ printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate));
if (cfg.ostyle >= 2) {
printf(" |\n");
} else {
}
}
- if (strlen(datebuff)<=9 && listtype != 4) {
+ if (strlen(datebuff) <= 9 && listtype != 4) {
printf(" %*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
} else {
printf(" %-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal));
}
printf(" | %s", getvalue(datalist_i->tx, 11, RT_Normal));
- printf(" | %s", getvalue(datalist_i->rx+datalist_i->tx, 11, RT_Normal));
+ printf(" | %s", getvalue(datalist_i->rx + datalist_i->tx, 11, RT_Normal));
if (cfg.ostyle == 3) {
if (datalist_i->next == NULL) {
d = localtime(&interface->updated);
if (listtype == 1) { // day
- e_secs = (uint64_t)(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+ e_secs = (uint64_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
} else if (listtype == 2) { // month
e_secs = (uint64_t)mosecs(datalist_i->timestamp, interface->updated);
} else if (listtype == 3) { // year
- e_secs = (uint64_t)(d->tm_yday*86400+d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+ e_secs = (uint64_t)(d->tm_yday * 86400 + d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
} else if (listtype == 4) { // top
e_secs = 86400;
} else if (listtype == 5) { // hour
- e_secs = (uint64_t)(d->tm_sec+(d->tm_min*60));
+ e_secs = (uint64_t)(d->tm_sec + (d->tm_min * 60));
} else if (listtype == 6) { // 5min
e_secs = 300;
}
} else if (listtype == 2) { // month
e_secs = (uint64_t)(dmonth(d->tm_mon) * 86400);
} else if (listtype == 3) { // year
- e_secs = (uint64_t)((365 + isleapyear(d->tm_year+1900)) * 86400);
+ e_secs = (uint64_t)((365 + isleapyear(d->tm_year + 1900)) * 86400);
} else if (listtype == 5) { // hour
e_secs = 3600;
} else if (listtype == 6) { // 5min
e_secs = 300;
}
}
- printf(" | %s", gettrafficrate(datalist_i->rx+datalist_i->tx, (time_t)e_secs, 14));
+ printf(" | %s", gettrafficrate(datalist_i->rx + datalist_i->tx, (time_t)e_secs, 14));
} else if (cfg.ostyle != 0) {
- showbar(datalist_i->rx, datalist_i->tx, datainfo.max, 24-offset);
+ showbar(datalist_i->rx, datalist_i->tx, datainfo.max, 24 - offset);
}
printf("\n");
if (datalist_i->next == NULL) {
if ((strlen(dataend) == 0 && datainfo.count > 0 && listtype < 4) || (strlen(dataend) > 0 && datainfo.count > 1 && listtype != 4)) {
/* use database update time for estimates */
d = localtime(&interface->updated);
- if ( datalist_i->rx==0 || datalist_i->tx==0 || strlen(dataend)>0 ) {
+ if (datalist_i->rx == 0 || datalist_i->tx == 0 || strlen(dataend) > 0) {
e_rx = e_tx = 0;
} else {
div = 0;
printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate));
} else {
if (datainfo.count < 100) {
- snprintf(datebuff, DATEBUFFLEN, "sum of %"PRIu32"", datainfo.count);
+ snprintf(datebuff, DATEBUFFLEN, "sum of %" PRIu32 "", datainfo.count);
} else {
snprintf(datebuff, DATEBUFFLEN, "sum");
}
/* daily */
if (cfg.ostyle == 4) {
- printf("%"PRIu64";", datalist->rx);
- printf("%"PRIu64";", datalist->tx);
- printf("%"PRIu64";", datalist->rx+datalist->tx);
- div = (uint64_t)(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+ printf("%" PRIu64 ";", datalist->rx);
+ printf("%" PRIu64 ";", datalist->tx);
+ printf("%" PRIu64 ";", datalist->rx + datalist->tx);
+ div = (uint64_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
if (!div) {
div = 1;
}
- printf("%"PRIu64";", (datalist->rx+datalist->tx)/div);
+ printf("%" PRIu64 ";", (datalist->rx + datalist->tx) / div);
} else {
printf("%s;", getvalue(datalist->rx, 1, RT_Normal));
printf("%s;", getvalue(datalist->tx, 1, RT_Normal));
- printf("%s;", getvalue(datalist->rx+datalist->tx, 1, RT_Normal));
- printf("%s;", gettrafficrate(datalist->rx+datalist->tx, (time_t)(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600)), 1));
+ printf("%s;", getvalue(datalist->rx + datalist->tx, 1, RT_Normal));
+ printf("%s;", gettrafficrate(datalist->rx + datalist->tx, (time_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600)), 1));
}
} else {
printf(";;;;;");
/* monthly */
if (cfg.ostyle == 4) {
- printf("%"PRIu64";", datalist->rx);
- printf("%"PRIu64";", datalist->tx);
- printf("%"PRIu64";", datalist->rx+datalist->tx);
+ printf("%" PRIu64 ";", datalist->rx);
+ printf("%" PRIu64 ";", datalist->tx);
+ printf("%" PRIu64 ";", datalist->rx + datalist->tx);
div = (uint64_t)(mosecs(datalist->timestamp, interface->updated));
if (!div) {
div = 1;
}
- printf("%"PRIu64";", (datalist->rx+datalist->tx)/div);
+ printf("%" PRIu64 ";", (datalist->rx + datalist->tx) / div);
} else {
printf("%s;", getvalue(datalist->rx, 1, RT_Normal));
printf("%s;", getvalue(datalist->tx, 1, RT_Normal));
- printf("%s;", getvalue(datalist->rx+datalist->tx, 1, RT_Normal));
- printf("%s;", gettrafficrate(datalist->rx+datalist->tx, mosecs(datalist->timestamp, interface->updated), 1));
+ printf("%s;", getvalue(datalist->rx + datalist->tx, 1, RT_Normal));
+ printf("%s;", gettrafficrate(datalist->rx + datalist->tx, mosecs(datalist->timestamp, interface->updated), 1));
}
} else {
printf(";;;;;");
/* all time total */
if (cfg.ostyle == 4) {
- printf("%"PRIu64";", interface->rxtotal);
- printf("%"PRIu64";", interface->txtotal);
- printf("%"PRIu64"\n", interface->rxtotal+interface->txtotal);
+ printf("%" PRIu64 ";", interface->rxtotal);
+ printf("%" PRIu64 ";", interface->txtotal);
+ printf("%" PRIu64 "\n", interface->rxtotal + interface->txtotal);
} else {
printf("%s;", getvalue(interface->rxtotal, 1, RT_Normal));
printf("%s;", getvalue(interface->txtotal, 1, RT_Normal));
- printf("%s\n", getvalue(interface->rxtotal+interface->txtotal, 1, RT_Normal));
+ printf("%s\n", getvalue(interface->rxtotal + interface->txtotal, 1, RT_Normal));
}
timeused(__func__, 0);
}
void showhours(const interfaceinfo *interface)
{
- int i, s=0, hour, minute, declen=cfg.hourlydecimals, div=1;
- unsigned int j, k, tmax=0, dots=0;
- uint64_t max=1;
+ int i, s = 0, hour, minute, declen = cfg.hourlydecimals, div = 1;
+ unsigned int j, k, tmax = 0, dots = 0;
+ uint64_t max = 1;
char matrix[24][81]; /* width is one over 80 so that snprintf can write the end char */
char unit[4];
struct tm *d;
timeused(__func__, 1);
- for (i=0; i<24; i++) {
+ for (i = 0; i < 24; i++) {
hourdata[i].rx = hourdata[i].tx = 0;
hourdata[i].date = 0;
}
while (datalist_i != NULL) {
d = localtime(&datalist_i->timestamp);
- if (hourdata[d->tm_hour].date != 0 || interface->updated-datalist_i->timestamp > 86400) {
+ if (hourdata[d->tm_hour].date != 0 || interface->updated - datalist_i->timestamp > 86400) {
datalist_i = datalist_i->next;
continue;
}
hour = d->tm_hour;
minute = d->tm_min;
- for (i=0; i<24; i++) {
+ for (i = 0; i < 24; i++) {
if (hourdata[i].date >= hourdata[tmax].date) {
tmax = (unsigned int)i;
}
}
/* mr. proper */
- for (i=0; i<24; i++) {
- for (j=0; j<81; j++) {
+ for (i = 0; i < 24; i++) {
+ for (j = 0; j < 81; j++) {
matrix[i][j] = ' ';
}
}
/* unit selection */
- while (max/(pow(1024, div)) >= 100 && div < UNITPREFIXCOUNT) {
+ while (max / (pow(1024, div)) >= 100 && div < UNITPREFIXCOUNT) {
div++;
}
strncpy_nt(unit, getunitprefix(div), 4);
- div = (int)(pow(1024, div-1));
+ div = (int)(pow(1024, div - 1));
if (div == 1) {
declen = 0;
}
/* structure */
snprintf(matrix[11], 81, " -+--------------------------------------------------------------------------->");
- for (i=0; i<3; i++) {
- snprintf(matrix[14]+(i*28), 14, " h %*srx (%s)", 1+cfg.unitmode, " ", unit);
- snprintf(matrix[14]+(i*28)+15+cfg.unitmode, 10, "tx (%s)", unit);
+ for (i = 0; i < 3; i++) {
+ snprintf(matrix[14] + (i * 28), 14, " h %*srx (%s)", 1 + cfg.unitmode, " ", unit);
+ snprintf(matrix[14] + (i * 28) + 15 + cfg.unitmode, 10, "tx (%s)", unit);
}
- for (i=10;i>1;i--)
- matrix[i][2]='|';
+ for (i = 10; i > 1; i--)
+ matrix[i][2] = '|';
- matrix[1][2]='^';
- matrix[12][2]='|';
+ matrix[1][2] = '^';
+ matrix[12][2] = '|';
/* title */
if (strcmp(interface->name, interface->alias) == 0 || strlen(interface->alias) == 0) {
i = snprintf(matrix[0], 81, " %s (%s)", interface->alias, interface->name);
}
if (interface->active == 0) {
- snprintf(matrix[0]+i+1, 81, " [disabled]");
+ snprintf(matrix[0] + i + 1, 81, " [disabled]");
}
/* time to the corner */
- snprintf(matrix[0]+74, 7, "%02d:%02d", hour, minute);
+ snprintf(matrix[0] + 74, 7, "%02d:%02d", hour, minute);
/* numbers under x-axis and graphics :) */
k = 5;
- for (i=23; i>=0; i--) {
+ for (i = 23; i >= 0; i--) {
s = (int)tmax - i;
if (s < 0)
s += 24;
- snprintf(matrix[12]+k, 81-k, "%02d ", s);
+ snprintf(matrix[12] + k, 81 - k, "%02d ", s);
dots = (unsigned int)(10 * (hourdata[s].rx / (float)max));
- for (j=0; j<dots; j++)
- matrix[10-j][k] = cfg.rxhourchar[0];
+ for (j = 0; j < dots; j++)
+ matrix[10 - j][k] = cfg.rxhourchar[0];
dots = (unsigned int)(10 * (hourdata[s].tx / (float)max));
- for (j=0; j<dots; j++)
- matrix[10-j][k+1] = cfg.txhourchar[0];
+ for (j = 0; j < dots; j++)
+ matrix[10 - j][k + 1] = cfg.txhourchar[0];
k = k + 3;
}
/* hours and traffic */
- for (i=0; i<=7; i++) {
+ for (i = 0; i <= 7; i++) {
s = (int)tmax + i + 1;
- for (j=0; j<3; j++) {
- snprintf(matrix[15+i]+(j*28), 25, "%02d %"DECCONV"10.*f %"DECCONV"10.*f", \
- ((unsigned int)s+(j*8))%24, declen, hourdata[((unsigned int)s+(j*8))%24].rx/(double)div, \
- declen, hourdata[((unsigned int)s+(j*8))%24].tx/(double)div);
+ for (j = 0; j < 3; j++) {
+ snprintf(matrix[15 + i] + (j * 28), 25, "%02d %" DECCONV "10.*f %" DECCONV "10.*f",
+ ((unsigned int)s + (j * 8)) % 24, declen, hourdata[((unsigned int)s + (j * 8)) % 24].rx / (double)div,
+ declen, hourdata[((unsigned int)s + (j * 8)) % 24].tx / (double)div);
}
}
/* section separators */
if (cfg.hourlystyle) {
- for (i=0;i<9;i++) {
+ for (i = 0; i < 9; i++) {
if (cfg.hourlystyle == 1) {
- matrix[14+i][26]='|';
- matrix[14+i][54]='|';
+ matrix[14 + i][26] = '|';
+ matrix[14 + i][54] = '|';
} else if (cfg.hourlystyle == 2) {
- matrix[14+i][25]=']';
- matrix[14+i][26]='[';
- matrix[14+i][53]=']';
- matrix[14+i][54]='[';
+ matrix[14 + i][25] = ']';
+ matrix[14 + i][26] = '[';
+ matrix[14 + i][53] = ']';
+ matrix[14 + i][54] = '[';
} else if (cfg.hourlystyle == 3) {
- matrix[14+i][26]='[';
- matrix[14+i][53]=']';
+ matrix[14 + i][26] = '[';
+ matrix[14 + i][53] = ']';
}
}
}
/* clean \0 */
- for (i=0; i<23; i++) {
- for (j=0; j<80; j++) {
+ for (i = 0; i < 23; i++) {
+ for (j = 0; j < 80; j++) {
if (matrix[i][j] == '\0') {
matrix[i][j] = ' ';
}
}
/* show matrix (yes, the last line isn't shown) */
- for (i=0; i<23; i++) {
- for (j=0; j<80; j++) {
- printf("%c",matrix[i][j]);
+ for (i = 0; i < 23; i++) {
+ for (j = 0; j < 80; j++) {
+ printf("%c", matrix[i][j]);
}
printf("\n");
}
{
int i, l, width = len;
- if ( (rx + tx) < max) {
- width = (int)( ((rx + tx) / (float)max) * len );
+ if ((rx + tx) < max) {
+ width = (int)(((rx + tx) / (float)max) * len);
} else if ((rx + tx) > max || max == 0) {
return 0;
}
printf(" ");
if (tx > rx) {
- l = (int)(rintf((rx/(float)(rx+tx)*width)));
+ l = (int)(rintf((rx / (float)(rx + tx) * width)));
- for (i=0; i<l; i++) {
+ for (i = 0; i < l; i++) {
printf("%c", cfg.rxchar[0]);
}
- for (i=0; i<(width-l); i++) {
+ for (i = 0; i < (width - l); i++) {
printf("%c", cfg.txchar[0]);
}
} else {
- l = (int)(rintf((tx/(float)(rx+tx)*width)));
+ l = (int)(rintf((tx / (float)(rx + tx) * width)));
- for (i=0; i<(width-l); i++) {
+ for (i = 0; i < (width - l); i++) {
printf("%c", cfg.rxchar[0]);
}
- for (i=0; i<l; i++) {
+ for (i = 0; i < l; i++) {
printf("%c", cfg.txchar[0]);
}
}
return 0;
}
}
-
}
/* set pragmas */
return 0;
}
- sql = "CREATE TABLE info(\n" \
- " id INTEGER PRIMARY KEY,\n" \
- " name TEXT UNIQUE NOT NULL,\n" \
- " value TEXT NOT NULL)";
+ sql = "CREATE TABLE info(\n"
+ " id INTEGER PRIMARY KEY,\n"
+ " name TEXT UNIQUE NOT NULL,\n"
+ " value TEXT NOT NULL)";
if (!db_exec(sql)) {
db_rollbacktransaction();
return 0;
}
- sql = "CREATE TABLE interface(\n" \
- " id INTEGER PRIMARY KEY,\n" \
- " name TEXT UNIQUE NOT NULL,\n" \
- " alias TEXT,\n" \
- " active INTEGER NOT NULL,\n" \
- " created DATE NOT NULL,\n" \
- " updated DATE NOT NULL,\n" \
- " rxcounter INTEGER NOT NULL,\n" \
- " txcounter INTEGER NOT NULL,\n" \
- " rxtotal INTEGER NOT NULL,\n" \
- " txtotal INTEGER NOT NULL)";
+ sql = "CREATE TABLE interface(\n"
+ " id INTEGER PRIMARY KEY,\n"
+ " name TEXT UNIQUE NOT NULL,\n"
+ " alias TEXT,\n"
+ " active INTEGER NOT NULL,\n"
+ " created DATE NOT NULL,\n"
+ " updated DATE NOT NULL,\n"
+ " rxcounter INTEGER NOT NULL,\n"
+ " txcounter INTEGER NOT NULL,\n"
+ " rxtotal INTEGER NOT NULL,\n"
+ " txtotal INTEGER NOT NULL)";
if (!db_exec(sql)) {
db_rollbacktransaction();
return 0;
}
- sql = malloc(sizeof(char)*512);
- for (i=0; i<6; i++) {
- sqlite3_snprintf(512, sql, "CREATE TABLE %s(\n" \
- " id INTEGER PRIMARY KEY,\n" \
- " interface INTEGER REFERENCES interface(id) ON DELETE CASCADE,\n" \
- " date DATE NOT NULL,\n" \
- " rx INTEGER NOT NULL,\n" \
- " tx INTEGER NOT NULL,\n" \
- " CONSTRAINT u UNIQUE (interface, date))", datatables[i]);
+ sql = malloc(sizeof(char) * 512);
+ for (i = 0; i < 6; i++) {
+ sqlite3_snprintf(512, sql, "CREATE TABLE %s(\n"
+ " id INTEGER PRIMARY KEY,\n"
+ " interface INTEGER REFERENCES interface(id) ON DELETE CASCADE,\n"
+ " date DATE NOT NULL,\n"
+ " rx INTEGER NOT NULL,\n"
+ " tx INTEGER NOT NULL,\n"
+ " CONSTRAINT u UNIQUE (interface, date))",
+ datatables[i]);
if (!db_exec(sql)) {
free(sql);
}
free(sql);
- snprintf(buffer, 32, "%"PRIu64"", (uint64_t)MAX32);
+ snprintf(buffer, 32, "%" PRIu64 "", (uint64_t)MAX32);
if (!db_setinfo("btime", buffer, 1)) {
db_rollbacktransaction();
return 0;
return 0;
}
- sqlite3_snprintf(64, sql, "delete from interface where id=%"PRId64"", (int64_t)ifaceid);
+ sqlite3_snprintf(64, sql, "delete from interface where id=%" PRId64 "", (int64_t)ifaceid);
return db_exec(sql);
}
return 0;
}
- sqlite3_snprintf(64, sql, "update interface set active=%d where id=%"PRId64"", active, (int64_t)ifaceid);
+ sqlite3_snprintf(64, sql, "update interface set active=%d where id=%" PRId64 "", active, (int64_t)ifaceid);
return db_exec(sql);
}
return 0;
}
- sqlite3_snprintf(256, sql, "update interface set updated=datetime(%"PRIu64", 'unixepoch', 'localtime') where id=%"PRId64"", (uint64_t)timestamp, (int64_t)ifaceid);
+ sqlite3_snprintf(256, sql, "update interface set updated=datetime(%" PRIu64 ", 'unixepoch', 'localtime') where id=%" PRId64 "", (uint64_t)timestamp, (int64_t)ifaceid);
return db_exec(sql);
}
return 0;
}
- sqlite3_snprintf(256, sql, "update interface set rxcounter=%"PRIu64", txcounter=%"PRIu64" where id=%"PRId64"", rxcounter, txcounter, (int64_t)ifaceid);
+ sqlite3_snprintf(256, sql, "update interface set rxcounter=%" PRIu64 ", txcounter=%" PRIu64 " where id=%" PRId64 "", rxcounter, txcounter, (int64_t)ifaceid);
return db_exec(sql);
}
return 0;
}
- sqlite3_snprintf(128, sql, "select rxcounter, txcounter from interface where id=%"PRId64"", (int64_t)ifaceid);
+ sqlite3_snprintf(128, sql, "select rxcounter, txcounter from interface where id=%" PRId64 "", (int64_t)ifaceid);
rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL);
if (rc != SQLITE_OK) {
db_errcode = rc;
if (ifaceid == 0) {
return 0;
}
- sqlite3_snprintf(512, sql, "select name, alias, active, strftime('%%s', created, 'utc'), strftime('%%s', updated, 'utc'), rxcounter, txcounter, rxtotal, txtotal from interface where id=%"PRId64"", (int64_t)ifaceid);
+ sqlite3_snprintf(512, sql, "select name, alias, active, strftime('%%s', created, 'utc'), strftime('%%s', updated, 'utc'), rxcounter, txcounter, rxtotal, txtotal from interface where id=%" PRId64 "", (int64_t)ifaceid);
} else {
ifaceidin = db_getinterfaceidin(iface);
if (ifaceidin == NULL || strlen(ifaceidin) < 1) {
return 0;
}
- sqlite3_snprintf(128, sql, "update interface set alias='%q' where id=%"PRId64"", alias, (int64_t)ifaceid);
+ sqlite3_snprintf(128, sql, "update interface set alias='%q' where id=%" PRId64 "", alias, (int64_t)ifaceid);
return db_exec(sql);
}
sql = "select name from interface order by name desc";
rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL);
- if (rc != SQLITE_OK ) {
+ if (rc != SQLITE_OK) {
db_errcode = rc;
snprintf(errorstring, 1024, "Failed to get interface list from database (%d): %s", rc, sqlite3_errmsg(db));
printe(PT_Error);
if (direct || cfg.monthrotate == 1) {
snprintf(dgen, 512, "strftime('%%Y-%%m-01', %s, 'localtime')", nowdate);
} else {
- snprintf(dgen, 512, "strftime('%%Y-%%m-01', datetime(%s, '-%d days'), 'localtime')", nowdate, cfg.monthrotate-1);
+ snprintf(dgen, 512, "strftime('%%Y-%%m-01', datetime(%s, '-%d days'), 'localtime')", nowdate, cfg.monthrotate - 1);
}
break;
case 4: /* year */
if (direct || cfg.monthrotate == 1 || cfg.monthrotateyears == 0) {
snprintf(dgen, 512, "strftime('%%Y-01-01', %s, 'localtime')", nowdate);
} else {
- snprintf(dgen, 512, "strftime('%%Y-01-01', datetime(%s, '-%d days'), 'localtime')", nowdate, cfg.monthrotate-1);
+ snprintf(dgen, 512, "strftime('%%Y-01-01', datetime(%s, '-%d days'), 'localtime')", nowdate, cfg.monthrotate - 1);
}
break;
default:
}
if (timestamp > 0) {
- snprintf(nowdate, 64, "datetime(%"PRIu64", 'unixepoch')", timestamp);
+ snprintf(nowdate, 64, "datetime(%" PRIu64 ", 'unixepoch')", timestamp);
} else {
snprintf(nowdate, 64, "'now'");
}
if (debug)
- printf("db add %s (%"PRId64") %"PRIu64": rx %"PRIu64" - tx %"PRIu64"\n", iface, (int64_t)ifaceid, timestamp, rx, tx);
+ printf("db add %s (%" PRId64 ") %" PRIu64 ": rx %" PRIu64 " - tx %" PRIu64 "\n", iface, (int64_t)ifaceid, timestamp, rx, tx);
if (!intransaction) {
if (!db_begintransaction()) {
/* change updated only if more recent than previous when timestamp provided */
if (timestamp > 0) {
- sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%"PRId64" and updated < datetime(%s, 'localtime')", nowdate, (int64_t)ifaceid, nowdate);
+ sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%" PRId64 " and updated < datetime(%s, 'localtime')", nowdate, (int64_t)ifaceid, nowdate);
} else {
- sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%"PRId64"", nowdate, (int64_t)ifaceid);
+ sqlite3_snprintf(1024, sql, "update interface set active=1, updated=datetime(%s, 'localtime') where id=%" PRId64 "", nowdate, (int64_t)ifaceid);
}
if (!db_exec(sql)) {
/* no transaction rollback needed here as failure of the first step results in no transaction being active */
/* total */
if (rx > 0 || tx > 0) {
- sqlite3_snprintf(1024, sql, "update interface set rxtotal=rxtotal+%"PRIu64", txtotal=txtotal+%"PRIu64" where id=%"PRId64"", rx, tx, (int64_t)ifaceid);
+ sqlite3_snprintf(1024, sql, "update interface set rxtotal=rxtotal+%" PRIu64 ", txtotal=txtotal+%" PRIu64 " where id=%" PRId64 "", rx, tx, (int64_t)ifaceid);
if (!db_exec(sql)) {
db_rollbacktransaction();
return 0;
}
/* time specific */
- for (i=0; i<6; i++) {
+ for (i = 0; i < 6; i++) {
if (featurecfg[i] == 0) {
continue;
}
- sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%"PRId64", %s, 0, 0)", datatables[i], (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate));
+ sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%" PRId64 ", %s, 0, 0)", datatables[i], (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate));
if (!db_exec(sql)) {
db_rollbacktransaction();
return 0;
}
- sqlite3_snprintf(1024, sql, "update %s set rx=rx+%"PRIu64", tx=tx+%"PRIu64" where interface=%"PRId64" and date=%s", datatables[i], rx, tx, (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate));
+ sqlite3_snprintf(1024, sql, "update %s set rx=rx+%" PRIu64 ", tx=tx+%" PRIu64 " where interface=%" PRId64 " and date=%s", datatables[i], rx, tx, (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate));
if (!db_exec(sql)) {
db_rollbacktransaction();
return 0;
return 0;
}
- sqlite3_snprintf(256, sql, "update interface set created=datetime(%"PRIu64", 'unixepoch', 'localtime') where id=%"PRId64"", (uint64_t)timestamp, (int64_t)ifaceid);
+ sqlite3_snprintf(256, sql, "update interface set created=datetime(%" PRIu64 ", 'unixepoch', 'localtime') where id=%" PRId64 "", (uint64_t)timestamp, (int64_t)ifaceid);
return db_exec(sql);
}
return 0;
}
- sqlite3_snprintf(256, sql, "update interface set rxtotal=%"PRIu64", txtotal=%"PRIu64" where id=%"PRId64"", rx, tx, (int64_t)ifaceid);
+ sqlite3_snprintf(256, sql, "update interface set rxtotal=%" PRIu64 ", txtotal=%" PRIu64 " where id=%" PRId64 "", rx, tx, (int64_t)ifaceid);
return db_exec(sql);
}
const char *datatables[] = {"hour", "day", "month", "year", "top"};
- for (i=0; i<5; i++) {
+ for (i = 0; i < 5; i++) {
if (strcmp(table, datatables[i]) == 0) {
index = i;
break;
return 0;
}
- snprintf(nowdate, 64, "datetime(%"PRIu64", 'unixepoch')", timestamp);
+ snprintf(nowdate, 64, "datetime(%" PRIu64 ", 'unixepoch')", timestamp);
- sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%"PRId64", %s, %"PRIu64", %"PRIu64")", table, (int64_t)ifaceid, db_get_date_generator(index+1, 1, nowdate), rx, tx);
+ sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%" PRId64 ", %s, %" PRIu64 ", %" PRIu64 ")", table, (int64_t)ifaceid, db_get_date_generator(index + 1, 1, nowdate), rx, tx);
return db_exec(sql);
}
continue;
}
- sqlite3_snprintf(512, sql, "delete from top where id in ( select id from top where interface=%"PRId64" and date!=date('now', 'localtime') order by rx+tx desc limit -1 offset %d )", (int64_t)ifaceid, cfg.topdayentries);
+ sqlite3_snprintf(512, sql, "delete from top where id in ( select id from top where interface=%" PRId64 " and date!=date('now', 'localtime') order by rx+tx desc limit -1 offset %d )", (int64_t)ifaceid, cfg.topdayentries);
if (!db_exec(sql)) {
errorcount++;
}
ret = 0;
- for (i=0; i<6; i++) {
+ for (i = 0; i < 6; i++) {
if (strcmp(table, datatables[i]) == 0) {
ret = 1;
break;
}
limit[0] = '\0';
- if (resultlimit > 0 && ( !strlen(dbegin) || !strlen(dend) )) {
- snprintf(limit, 64, "limit %"PRIu32"", resultlimit);
+ if (resultlimit > 0 && (!strlen(dbegin) || !strlen(dend))) {
+ snprintf(limit, 64, "limit %" PRIu32 "", resultlimit);
}
/* note that using the linked list reverses the order */
/* 'top' entries, requires different query due to rx+tx ordering */
if (strlen(dbegin)) {
if (resultlimit > 0) {
- snprintf(limit, 64, "limit %"PRIu32"", resultlimit);
+ snprintf(limit, 64, "limit %" PRIu32 "", resultlimit);
}
sqlite3_snprintf(512, sql, "select * from (select id, strftime('%%s', date, 'utc'), sum(rx) as rx, sum(tx) as tx from day where interface in (%q) %s %s group by date order by rx+tx desc %s) order by rx+tx asc", ifaceidin, dbegin, dend, limit);
} else {
*dbdata = (*dbdata)->next;
free(dbdata_prev);
}
-
}
unsigned int getqueryinterfacecount(const char *input)
{
unsigned int i, ifacecount = 1;
- if (input[0] == '+' || input[strlen(input)-1] == '+' || !strlen(input)) {
+ if (input[0] == '+' || input[strlen(input) - 1] == '+' || !strlen(input)) {
return 0;
}
for (i = 0; i < (unsigned int)strlen(input); i++) {
if (input[i] == '+') {
- if (i > 0 && input[i-1] == '+') {
+ if (i > 0 && input[i - 1] == '+') {
return 0;
} else {
ifacecount++;
printf("</updated>\n");
printf(" <traffic>\n");
- printf(" <total><rx>%"PRIu64"</rx><tx>%"PRIu64"</tx></total>\n", info.rxtotal, info.txtotal);
+ printf(" <total><rx>%" PRIu64 "</rx><tx>%" PRIu64 "</tx></total>\n", info.rxtotal, info.txtotal);
switch (mode) {
case 'd':
printf(" <%ss>\n", tablename);
datalist_i = datalist;
while (datalist_i != NULL) {
- printf(" <%s id=\"%"PRId64"\">", tablename, datalist_i->rowid);
+ printf(" <%s id=\"%" PRId64 "\">", tablename, datalist_i->rowid);
xmldate(&datalist_i->timestamp, datetype);
- printf("<rx>%"PRIu64"</rx><tx>%"PRIu64"</tx></%s>\n", datalist_i->rx, datalist_i->tx, tablename);
+ printf("<rx>%" PRIu64 "</rx><tx>%" PRIu64 "</tx></%s>\n", datalist_i->rx, datalist_i->tx, tablename);
datalist_i = datalist_i->next;
}
dbdatalistfree(&datalist);
switch (type) {
case 1:
- printf("<date><year>%d</year><month>%02d</month><day>%02d</day></date>", \
- 1900+d->tm_year, 1+d->tm_mon, d->tm_mday);
+ printf("<date><year>%d</year><month>%02d</month><day>%02d</day></date>",
+ 1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday);
break;
case 2:
- printf("<date><year>%d</year><month>%02d</month><day>%02d</day></date><time><hour>%02d</hour><minute>%02d</minute></time>", \
- 1900+d->tm_year, 1+d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min);
+ printf("<date><year>%d</year><month>%02d</month><day>%02d</day></date><time><hour>%02d</hour><minute>%02d</minute></time>",
+ 1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min);
break;
case 3:
- printf("<date><year>%d</year><month>%02d</month></date>", \
- 1900+d->tm_year, 1+d->tm_mon);
+ printf("<date><year>%d</year><month>%02d</month></date>",
+ 1900 + d->tm_year, 1 + d->tm_mon);
break;
case 4:
- printf("<date><year>%d</year></date>", \
- 1900+d->tm_year);
+ printf("<date><year>%d</year></date>",
+ 1900 + d->tm_year);
break;
default:
break;
{
struct stat statbuf;
- if (stat(file, &statbuf)!=0) {
- if (errno==ENOENT) {
+ if (stat(file, &statbuf) != 0) {
+ if (errno == ENOENT) {
return 0;
}
if (debug)
}
len = strlen(tmp);
- if (tmp[len-1] == '/') {
- tmp[len-1] = '\0';
+ if (tmp[len - 1] == '/') {
+ tmp[len - 1] = '\0';
}
if (tmp[0] == '/') {
i++;
}
- for (; i<len; i++) {
+ for (; i < len; i++) {
if (tmp[i] == '/') {
tmp[i] = '\0';
if (!direxists(tmp)) {
- if (mkdir(tmp, mode)!=0) {
+ if (mkdir(tmp, mode) != 0) {
if (debug)
printf("Error: mkdir() \"%s\": %s\n", tmp, strerror(errno));
ret = 0;
}
}
if (ret) {
- if (mkdir(tmp, mode)!=0) {
+ if (mkdir(tmp, mode) != 0) {
if (debug)
printf("Error: mkdir() \"%s\": %s\n", tmp, strerror(errno));
ret = 0;
void preparevnstatdir(const char *dir, const char *user, const char *group)
{
- size_t i, len, lastslash=0;
+ size_t i, len, lastslash = 0;
char *path, *base;
if (dir == NULL) {
}
len = strlen(dir);
- if (len<2) {
+ if (len < 2) {
return;
}
- if (dir[len-1] == '/') {
+ if (dir[len - 1] == '/') {
return;
}
/* verify that path ends with vnstat or vnstatd */
base = basename(dirname(path));
- if (strcmp(base, "vnstat")!=0 && strcmp(base, "vnstatd")!=0) {
+ if (strcmp(base, "vnstat") != 0 && strcmp(base, "vnstatd") != 0) {
free(path);
return;
}
}
/* extract path */
- for (i=0; i<len; i++) {
+ for (i = 0; i < len; i++) {
if (path[i] == '/') {
lastslash = i;
}
if ((dir_fd = open(dir, FS_OPEN_RO_FLAGS)) == -1)
return;
- if (fstat(dir_fd, &statbuf)!=0) {
+ if (fstat(dir_fd, &statbuf) != 0) {
close(dir_fd);
return;
}
}
}
- if ((d=fdopendir(dir_fd))==NULL) {
+ if ((d = fdopendir(dir_fd)) == NULL) {
if (debug)
printf("Error: updatedirowner() diropen() \"%s\": %s\n", dir, strerror(errno));
close(dir_fd);
return;
}
- while ((di=readdir(d))) {
+ while ((di = readdir(d))) {
if (di->d_type != DT_REG) {
continue;
}
snprintf(entryname, 512, "%s/%s", dir, di->d_name);
if ((file_fd = open(entryname, FS_OPEN_RO_FLAGS)) == -1)
continue;
- if (fstat(file_fd, &statbuf)!=0) {
+ if (fstat(file_fd, &statbuf) != 0) {
close(file_fd);
continue;
}
return 0;
}
- if (stat(dir, &statbuf)!=0) {
+ if (stat(dir, &statbuf) != 0) {
if (debug)
printf("Error: stat() \"%s\": %s\n", dir, strerror(errno));
return 0;
/* update previous value if already in list */
while (p != NULL) {
- if (strcmp(p->interface, iface)==0) {
+ if (strcmp(p->interface, iface) == 0) {
p->limit = limit;
return 1;
}
}
/* add new node if not found */
- n = (ibwnode *)malloc(sizeof(ibwnode));
+ n = (ibwnode *)malloc(sizeof(ibwnode));
if (n == NULL) {
return 0;
void ibwlist(void)
{
- int i=1;
+ int i = 1;
ibwnode *p = ifacebw;
if (p == NULL) {
/* search for interface specific limit */
while (p != NULL) {
- if (strcasecmp(p->interface, iface)==0) {
+ if (strcasecmp(p->interface, iface) == 0) {
if (cfg.bwdetection && p->retries < 5) {
if (cfg.bwdetectioninterval > 0 && (current - p->detected) > (cfg.bwdetectioninterval * 60)) {
}
}
- if (p->limit>0) {
+ if (p->limit > 0) {
*limit = p->limit;
return 1;
} else {
}
/* return default limit if specified */
- if (cfg.maxbw>0) {
+ if (cfg.maxbw > 0) {
*limit = (uint32_t)cfg.maxbw;
return 1;
}
ibwnode *p = ifacebw;
while (p != NULL) {
- if (strcasecmp(p->interface, iface)==0) {
+ if (strcasecmp(p->interface, iface) == 0) {
return p;
}
p = p->next;
cfgline[0] = '\0';
/* get current line */
- if (fgets(cfgline, 512, fd)==NULL) {
+ if (fgets(cfgline, 512, fd) == NULL) {
break;
}
linelen = (int)strlen(cfgline);
- if (linelen<=8 || cfgline[0]=='#') {
+ if (linelen <= 8 || cfgline[0] == '#') {
continue;
}
- if (strncasecmp(cfgline, "MaxBW", 5)!=0) {
+ if (strncasecmp(cfgline, "MaxBW", 5) != 0) {
continue;
}
/* clear name and value buffers */
- for (j=0; j<512; j++) {
- name[j]=value[j]='\0';
+ for (j = 0; j < 512; j++) {
+ name[j] = value[j] = '\0';
}
/* get interface name */
- j=0;
- for (i=5; i<linelen; i++) {
- if (cfgline[i]==' ' || cfgline[i]=='=' || cfgline[i]=='\t' || cfgline[i]=='\n' || cfgline[i]=='\r') {
+ j = 0;
+ for (i = 5; i < linelen; i++) {
+ if (cfgline[i] == ' ' || cfgline[i] == '=' || cfgline[i] == '\t' || cfgline[i] == '\n' || cfgline[i] == '\r') {
break;
} else {
- name[j]=cfgline[i];
+ name[j] = cfgline[i];
j++;
}
}
/* get new line if no usable name was found */
- if (strlen(name)==0) {
+ if (strlen(name) == 0) {
continue;
}
/* search value */
- j=0;
- for (i++; i<linelen; i++) {
- if (cfgline[i]=='\n' || cfgline[i]=='\r') {
+ j = 0;
+ for (i++; i < linelen; i++) {
+ if (cfgline[i] == '\n' || cfgline[i] == '\r') {
break;
- } else if (cfgline[i]=='\"') {
- if (j==0) {
+ } else if (cfgline[i] == '\"') {
+ if (j == 0) {
continue;
} else {
break;
}
} else {
- if (j==0 && (cfgline[i]==' ' || cfgline[i]=='=' || cfgline[i]=='\t')) {
+ if (j == 0 && (cfgline[i] == ' ' || cfgline[i] == '=' || cfgline[i] == '\t')) {
continue;
} else {
- value[j]=cfgline[i];
+ value[j] = cfgline[i];
j++;
}
}
}
/* get new line if no usable value was found */
- if ((strlen(value)==0) || (!isdigit(value[0])) ) {
+ if ((strlen(value) == 0) || (!isdigit(value[0]))) {
continue;
}
/* add interface and limit to list if value is within limits */
ivalue = strtol(value, (char **)NULL, 0);
- if (ivalue<0 || ivalue>BWMAX) {
+ if (ivalue < 0 || ivalue > BWMAX) {
snprintf(errorstring, 1024, "Invalid value \"%ld\" for MaxBW%s, ignoring parameter.", ivalue, name);
printe(PT_Config);
} else {
#if defined(__linux__)
if (cfg.is64bit == -2) {
- #if HAVE_DECL_IFLA_STATS64
+#if HAVE_DECL_IFLA_STATS64
ifinfo.is64bit = 1;
- #else
+#else
ifinfo.is64bit = 0;
- #endif
+#endif
} else {
ifinfo.is64bit = (short)cfg.is64bit;
}
}
#endif
- if (strcmp(iface, "default")==0) {
+ if (strcmp(iface, "default") == 0) {
strncpy_nt(inface, cfg.iface, 32);
} else {
strncpy_nt(inface, iface, 32);
#if defined(__linux__) || defined(CHECK_VNSTAT)
/* try getting interface info from /proc */
- if (readproc(inface)==1) {
+ if (readproc(inface) == 1) {
ifinfo.timestamp = time(NULL);
return 1;
} else {
}
/* try getting interface info from /sys */
- if (readsysclassnet(inface)==1) {
+ if (readsysclassnet(inface) == 1) {
ifinfo.timestamp = time(NULL);
return 1;
}
-#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
- if (readifaddrs(inface)==1) {
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
+ if (readifaddrs(inface) == 1) {
ifinfo.timestamp = time(NULL);
return 1;
}
*ifacelist[0] = '\0';
#if defined(__linux__) || defined(CHECK_VNSTAT)
- if ((fp=fopen(PROCNETDEV, "r"))!=NULL) {
+ if ((fp = fopen(PROCNETDEV, "r")) != NULL) {
/* make list of interfaces */
- while (fgets(procline, 512, fp)!=NULL) {
+ while (fgets(procline, 512, fp) != NULL) {
sscanf(procline, "%63s", temp);
- if (strlen(temp)>0 && (isdigit(temp[(strlen(temp)-1)]) || temp[(strlen(temp)-1)]==':')) {
+ if (strlen(temp) > 0 && (isdigit(temp[(strlen(temp) - 1)]) || temp[(strlen(temp) - 1)] == ':')) {
sscanf(temp, "%31[^':']s", interface);
- *ifacelist = (char *)realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(interface) + 2 ) * sizeof(char)) );
+ *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(interface) + 2) * sizeof(char)));
if (*ifacelist == NULL) {
panicexit(__FILE__, __LINE__);
}
speed = getifspeed(interface);
if (speed > 0) {
snprintf(temp, 64, "(%u Mbit) ", speed);
- *ifacelist = (char *)realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) );
+ *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(temp) + 1) * sizeof(char)));
if (*ifacelist == NULL) {
panicexit(__FILE__, __LINE__);
}
} else {
- if ((dp=opendir(SYSCLASSNET))!=NULL) {
+ if ((dp = opendir(SYSCLASSNET)) != NULL) {
/* make list of interfaces */
- while ((di=readdir(dp))) {
+ while ((di = readdir(dp))) {
if (di->d_name[0] == '.' || strlen(di->d_name) > 31) {
continue;
}
- *ifacelist = (char *)realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(di->d_name) + 2 ) * sizeof(char)) );
+ *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(di->d_name) + 2) * sizeof(char)));
if (*ifacelist == NULL) {
panicexit(__FILE__, __LINE__);
}
speed = getifspeed(di->d_name);
if (speed > 0) {
snprintf(temp, 64, "(%u Mbit) ", speed);
- *ifacelist = (char *)realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) );
+ *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(temp) + 1) * sizeof(char)));
if (*ifacelist == NULL) {
panicexit(__FILE__, __LINE__);
}
if (ifa->ifa_addr->sa_family != AF_LINK || strlen(ifa->ifa_name) > 31) {
continue;
}
- *ifacelist = realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(ifa->ifa_name) + 2 ) * sizeof(char)) );
+ *ifacelist = realloc(*ifacelist, ((strlen(*ifacelist) + strlen(ifa->ifa_name) + 2) * sizeof(char)));
if (*ifacelist == NULL) {
panicexit(__FILE__, __LINE__);
}
speed = getifspeed(ifa->ifa_name);
if (speed > 0) {
snprintf(temp, 64, "(%u Mbit) ", speed);
- *ifacelist = realloc(*ifacelist, ( ( strlen(*ifacelist) + strlen(temp) + 1 ) * sizeof(char)) );
+ *ifacelist = realloc(*ifacelist, ((strlen(*ifacelist) + strlen(temp) + 1) * sizeof(char)));
if (*ifacelist == NULL) {
panicexit(__FILE__, __LINE__);
}
char temp[4][64], procline[512], *proclineptr, ifaceid[33];
int check;
- if ((fp=fopen(PROCNETDEV, "r"))==NULL) {
+ if ((fp = fopen(PROCNETDEV, "r")) == NULL) {
if (debug)
printf("Error: Unable to read %s: %s\n", PROCNETDEV, strerror(errno));
return 0;
strcat(ifaceid, ":");
check = 0;
- while (fgets(procline, 512, fp)!=NULL) {
+ while (fgets(procline, 512, fp) != NULL) {
sscanf(procline, "%63s", temp[0]);
- if (strncmp(ifaceid, temp[0], strlen(ifaceid))==0) {
+ if (strncmp(ifaceid, temp[0], strlen(ifaceid)) == 0) {
/* if (debug)
printf("\n%s\n", procline); */
check = 1;
}
fclose(fp);
- if (check==0) {
+ if (check == 0) {
if (debug)
printf("Requested interface \"%s\" not found.\n", iface);
return 0;
/* get rx and tx from procline */
proclineptr = strchr(procline, ':');
- sscanf(proclineptr+1, "%63s %63s %*s %*s %*s %*s %*s %*s %63s %63s", temp[0], temp[1], temp[2], temp[3]);
+ sscanf(proclineptr + 1, "%63s %63s %*s %*s %*s %*s %*s %*s %63s %63s", temp[0], temp[1], temp[2], temp[3]);
ifinfo.rx = strtoull(temp[0], (char **)NULL, 0);
ifinfo.tx = strtoull(temp[2], (char **)NULL, 0);
/* rx bytes */
snprintf(file, 76, "%s/rx_bytes", path);
- if ((fp=fopen(file, "r"))==NULL) {
+ if ((fp = fopen(file, "r")) == NULL) {
if (debug)
printf("Unable to read: %s - %s\n", file, strerror(errno));
return 0;
} else {
- if (fgets(buffer, 64, fp)!=NULL) {
+ if (fgets(buffer, 64, fp) != NULL) {
ifinfo.rx = strtoull(buffer, (char **)NULL, 0);
} else {
fclose(fp);
/* tx bytes */
snprintf(file, 76, "%s/tx_bytes", path);
- if ((fp=fopen(file, "r"))==NULL) {
+ if ((fp = fopen(file, "r")) == NULL) {
if (debug)
printf("Unable to read: %s - %s\n", file, strerror(errno));
return 0;
} else {
- if (fgets(buffer, 64, fp)!=NULL) {
+ if (fgets(buffer, 64, fp) != NULL) {
ifinfo.tx = strtoull(buffer, (char **)NULL, 0);
} else {
fclose(fp);
/* rx packets */
snprintf(file, 76, "%s/rx_packets", path);
- if ((fp=fopen(file, "r"))==NULL) {
+ if ((fp = fopen(file, "r")) == NULL) {
if (debug)
printf("Unable to read: %s - %s\n", file, strerror(errno));
return 0;
} else {
- if (fgets(buffer, 64, fp)!=NULL) {
+ if (fgets(buffer, 64, fp) != NULL) {
ifinfo.rxp = strtoull(buffer, (char **)NULL, 0);
} else {
fclose(fp);
/* tx packets */
snprintf(file, 76, "%s/tx_packets", path);
- if ((fp=fopen(file, "r"))==NULL) {
+ if ((fp = fopen(file, "r")) == NULL) {
if (debug)
printf("Unable to read: %s - %s\n", file, strerror(errno));
return 0;
} else {
- if (fgets(buffer, 64, fp)!=NULL) {
+ if (fgets(buffer, 64, fp) != NULL) {
ifinfo.txp = strtoull(buffer, (char **)NULL, 0);
} else {
fclose(fp);
snprintf(file, 64, "%s/%s/speed", SYSCLASSNET, iface);
- if ((fp=fopen(file, "r"))==NULL) {
+ if ((fp = fopen(file, "r")) == NULL) {
if (debug)
printf("Unable to open: %s - %s\n", file, strerror(errno));
return 0;
} else {
- if (fgets(buffer, 64, fp)!=NULL) {
+ if (fgets(buffer, 64, fp) != NULL) {
speed = strtoull(buffer, (char **)NULL, 0);
} else {
if (debug)
}
fclose(fp);
-#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
struct if_data ifd;
#endif
if (debug)
- printf("getifspeed: \"%s\": %"PRIu64"\n", iface, speed);
+ printf("getifspeed: \"%s\": %" PRIu64 "\n", iface, speed);
if (speed > 1000000) {
speed = 0;
void colorinitcheck(const char *color, const int value, const char *cfgtext, const int *rgb)
{
- if (value==-1) {
+ if (value == -1) {
printf("Error: ImageColorAllocate failed.\n");
printf(" C: \"%s\" T: \"%s\" RGB: %d/%d/%d\n", color, cfgtext, rgb[0], rgb[1], rgb[2]);
exit(EXIT_FAILURE);
/* background, edges */
gdImageFill(ic->im, 0, 0, ic->cbackground);
if (ic->showedge) {
- gdImageRectangle(ic->im, 0, 0, width-1, height-1, ic->cedge);
+ gdImageRectangle(ic->im, 0, 0, width - 1, height - 1, ic->cedge);
}
/* titlebox with title */
if (ic->showheader) {
- gdImageFilledRectangle(ic->im, 2+ic->showedge, 2+ic->showedge, width-3-ic->showedge, 24, ic->cheader);
- gdImageString(ic->im, gdFontGetGiant(), 12, 5+ic->showedge, (unsigned char*)title, ic->cheadertitle);
+ gdImageFilledRectangle(ic->im, 2 + ic->showedge, 2 + ic->showedge, width - 3 - ic->showedge, 24, ic->cheader);
+ gdImageString(ic->im, gdFontGetGiant(), 12, 5 + ic->showedge, (unsigned char *)title, ic->cheadertitle);
}
/* date */
if (!ic->showheader || ic->altdate) {
- gdImageString(ic->im, gdFontGetTiny(), 5+ic->showedge, height-12-ic->showedge, (unsigned char*)datestring, ic->cvnstat);
+ gdImageString(ic->im, gdFontGetTiny(), 5 + ic->showedge, height - 12 - ic->showedge, (unsigned char *)datestring, ic->cvnstat);
} else {
- gdImageString(ic->im, gdFontGetTiny(), width-(((int)strlen(datestring))*gdFontGetTiny()->w+12), 9+ic->showedge, (unsigned char*)datestring, ic->cheaderdate);
+ gdImageString(ic->im, gdFontGetTiny(), width - (((int)strlen(datestring)) * gdFontGetTiny()->w + 12), 9 + ic->showedge, (unsigned char *)datestring, ic->cheaderdate);
}
/* generator */
- gdImageString(ic->im, gdFontGetTiny(), width-114-ic->showedge, height-12-ic->showedge, (unsigned char*)"vnStat / Teemu Toivola", ic->cvnstat);
+ gdImageString(ic->im, gdFontGetTiny(), width - 114 - ic->showedge, height - 12 - ic->showedge, (unsigned char *)"vnStat / Teemu Toivola", ic->cvnstat);
}
void drawlegend(IMAGECONTENT *ic, const int x, const int y)
}
/* color legend */
- gdImageString(ic->im, gdFontGetSmall(), x, y, (unsigned char*)"rx tx", ic->ctext);
- gdImageFilledRectangle(ic->im, x-12, y+4, x-6, y+10, ic->crx);
- gdImageRectangle(ic->im, x-12, y+4, x-6, y+10, ic->ctext);
- gdImageFilledRectangle(ic->im, x+30, y+4, x+36, y+10, ic->ctx);
- gdImageRectangle(ic->im, x+30, y+4, x+36, y+10, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), x, y, (unsigned char *)"rx tx", ic->ctext);
+ gdImageFilledRectangle(ic->im, x - 12, y + 4, x - 6, y + 10, ic->crx);
+ gdImageRectangle(ic->im, x - 12, y + 4, x - 6, y + 10, ic->ctext);
+ gdImageFilledRectangle(ic->im, x + 30, y + 4, x + 36, y + 10, ic->ctx);
+ gdImageRectangle(ic->im, x + 30, y + 4, x + 36, y + 10, ic->ctext);
}
void drawbar(IMAGECONTENT *ic, const int x, const int y, const int len, const uint64_t rx, const uint64_t tx, const uint64_t max)
{
int l, width = len;
- if ((rx+tx) < max) {
- width=(int)(((rx+tx)/(float)max)*len);
- } else if ((rx+tx) > max || max == 0) {
+ if ((rx + tx) < max) {
+ width = (int)(((rx + tx) / (float)max) * len);
+ } else if ((rx + tx) > max || max == 0) {
return;
}
}
if (tx > rx) {
- l=(int)(rintf((rx/(float)(rx+tx)*width)));
+ l = (int)(rintf((rx / (float)(rx + tx) * width)));
if (l > 0) {
- gdImageFilledRectangle(ic->im, x, y+YBEGINOFFSET, x+l, y+YENDOFFSET, ic->crx);
- gdImageRectangle(ic->im, x, y+YBEGINOFFSET, x+l, y+YENDOFFSET, ic->crxd);
+ gdImageFilledRectangle(ic->im, x, y + YBEGINOFFSET, x + l, y + YENDOFFSET, ic->crx);
+ gdImageRectangle(ic->im, x, y + YBEGINOFFSET, x + l, y + YENDOFFSET, ic->crxd);
}
- gdImageFilledRectangle(ic->im, x+l, y+YBEGINOFFSET, x+width, y+YENDOFFSET, ic->ctx);
- gdImageRectangle(ic->im, x+l, y+YBEGINOFFSET, x+width, y+YENDOFFSET, ic->ctxd);
+ gdImageFilledRectangle(ic->im, x + l, y + YBEGINOFFSET, x + width, y + YENDOFFSET, ic->ctx);
+ gdImageRectangle(ic->im, x + l, y + YBEGINOFFSET, x + width, y + YENDOFFSET, ic->ctxd);
} else {
- l=(int)(rintf((tx/(float)(rx+tx)*width)));
+ l = (int)(rintf((tx / (float)(rx + tx) * width)));
- gdImageFilledRectangle(ic->im, x, y+YBEGINOFFSET, x+(width-l), y+YENDOFFSET, ic->crx);
- gdImageRectangle(ic->im, x, y+YBEGINOFFSET, x+(width-l), y+YENDOFFSET, ic->crxd);
+ gdImageFilledRectangle(ic->im, x, y + YBEGINOFFSET, x + (width - l), y + YENDOFFSET, ic->crx);
+ gdImageRectangle(ic->im, x, y + YBEGINOFFSET, x + (width - l), y + YENDOFFSET, ic->crxd);
if (l > 0) {
- gdImageFilledRectangle(ic->im, x+(width-l), y+YBEGINOFFSET, x+width, y+YENDOFFSET, ic->ctx);
- gdImageRectangle(ic->im, x+(width-l), y+YBEGINOFFSET, x+width, y+YENDOFFSET, ic->ctxd);
+ gdImageFilledRectangle(ic->im, x + (width - l), y + YBEGINOFFSET, x + width, y + YENDOFFSET, ic->ctx);
+ gdImageRectangle(ic->im, x + (width - l), y + YBEGINOFFSET, x + width, y + YENDOFFSET, ic->ctxd);
}
}
}
{
int l;
- l = (int)((rx/(float)max)*len);
+ l = (int)((rx / (float)max) * len);
if (l > 0) {
- gdImageFilledRectangle(ic->im, x, y+(len-l), x+7, y+len, ic->crx);
+ gdImageFilledRectangle(ic->im, x, y + (len - l), x + 7, y + len, ic->crx);
}
- l = (int)((tx/(float)max)*len);
+ l = (int)((tx / (float)max) * len);
if (l > 0) {
- gdImageFilledRectangle(ic->im, x+5, y+(len-l), x+12, y+len, ic->ctx);
+ gdImageFilledRectangle(ic->im, x + 5, y + (len - l), x + 12, y + len, ic->ctx);
}
}
{
int rxarc = 0, txarc = 0;
- if ( (int)(rxp + txp) > 0 ) {
+ if ((int)(rxp + txp) > 0) {
rxarc = (int)(360 * (rxp / (float)100));
- if ( (int)(rxp + txp) == 100 ) {
+ if ((int)(rxp + txp) == 100) {
txarc = 360 - rxarc;
} else {
txarc = (int)(360 * (txp / (float)100));
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 0, 360, ic->cbgoffset, 0);
if (txarc) {
- gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill);
if (txarc >= 5) {
- gdImageFill(ic->im, x+1, y-(DOUTRAD/2-3), ic->ctx);
+ gdImageFill(ic->im, x + 1, y - (DOUTRAD / 2 - 3), ic->ctx);
}
- gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+ gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill);
}
if (rxarc) {
- gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
if (rxarc >= 5) {
- gdImageFill(ic->im, (int)(x+(DOUTRAD/2-3)*cos(((270*2+2*txarc+rxarc)/2)*M_PI/180)), (int)(y+(DOUTRAD/2-3)*sin(((270*2+2*txarc+rxarc)/2)*M_PI/180)), ic->crx);
+ gdImageFill(ic->im, (int)(x + (DOUTRAD / 2 - 3) * cos(((270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), (int)(y + (DOUTRAD / 2 - 3) * sin(((270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), ic->crx);
}
- gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
+ gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
}
// remove center from background filled circle, making it a donut
- gdImageFilledArc(ic->im, x, y, DINRAD-2, DINRAD-2, 0, 360, ic->cbackground, 0);
+ gdImageFilledArc(ic->im, x, y, DINRAD - 2, DINRAD - 2, 0, 360, ic->cbackground, 0);
}
void drawdonut_libgd_native(IMAGECONTENT *ic, const int x, const int y, const float rxp, const float txp)
{
int rxarc = 0, txarc = 0;
- if ( (int)(rxp + txp) > 0 ) {
+ if ((int)(rxp + txp) > 0) {
rxarc = (int)(360 * (rxp / (float)100));
- if ( (int)(rxp + txp) == 100 ) {
+ if ((int)(rxp + txp) == 100) {
txarc = 360 - rxarc;
} else {
txarc = (int)(360 * (txp / (float)100));
gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 0, 360, ic->cbgoffset, 0);
if (txarc) {
- gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctx, 0);
- gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
- gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270+txarc, ic->ctxd, gdEdged|gdNoFill);
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270 + txarc, ic->ctx, 0);
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill);
+ gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill);
}
if (rxarc) {
- gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crx, 0);
- gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
- gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270+txarc, 270+txarc+rxarc, ic->crxd, gdEdged|gdNoFill);
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270 + txarc, 270 + txarc + rxarc, ic->crx, 0);
+ gdImageFilledArc(ic->im, x, y, DOUTRAD, DOUTRAD, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
+ gdImageFilledArc(ic->im, x, y, DINRAD, DINRAD, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill);
}
// remove center from background filled circle, making it a donut
- gdImageFilledArc(ic->im, x, y, DINRAD-2, DINRAD-2, 0, 360, ic->cbackground, 0);
+ gdImageFilledArc(ic->im, x, y, DINRAD - 2, DINRAD - 2, 0, 360, ic->cbackground, 0);
}
void drawhours(IMAGECONTENT *ic, const int x, const int y, const int rate)
{
- int i, tmax=0, s=0, step, prev=0, diff=0, chour;
+ int i, tmax = 0, s = 0, step, prev = 0, diff = 0, chour;
float ratediv;
- uint64_t max=1, scaleunit=0;
+ uint64_t max = 1, scaleunit = 0;
char buffer[32];
struct tm *d;
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;
HOURDATA hourdata[24];
- for (i=0; i<24; i++) {
+ for (i = 0; i < 24; i++) {
hourdata[i].rx = hourdata[i].tx = 0;
hourdata[i].date = 0;
}
while (datalist_i != NULL) {
d = localtime(&datalist_i->timestamp);
- if (hourdata[d->tm_hour].date != 0 || ic->interface.updated-datalist_i->timestamp > 86400) {
+ if (hourdata[d->tm_hour].date != 0 || ic->interface.updated - datalist_i->timestamp > 86400) {
datalist_i = datalist_i->next;
continue;
}
chour = localtime(&ic->current)->tm_hour;
if (cfg.rateunit) {
- ratediv = 450; /* x * 8 / 3600 */
+ ratediv = 450; /* x * 8 / 3600 */
} else {
ratediv = 3600;
}
for (i = 0; i < 24; i++) {
/* convert hourly transfer to hourly rate if needed */
if (rate) {
- if ((ic->current-hourdata[i].date) > 3600) {
+ if ((ic->current - hourdata[i].date) > 3600) {
hourdata[i].rx = (uint64_t)(hourdata[i].rx / ratediv);
hourdata[i].tx = (uint64_t)(hourdata[i].tx / ratediv);
} else {
step = 1;
}
- for (i=step; (uint64_t)(scaleunit*(unsigned int)i) <= max; i=i+step) {
+ for (i = step; (uint64_t)(scaleunit * (unsigned int)i) <= max; i = i + step) {
s = (int)(121 * ((scaleunit * (unsigned int)i) / (float)max));
- gdImageLine(ic->im, x+36, y+124-s, x+460, y+124-s, ic->cline);
- gdImageLine(ic->im, x+36, y+124-((s+prev)/2), x+460, y+124-((s+prev)/2), ic->clinel);
- gdImageString(ic->im, gdFontGetTiny(), x+16, y+121-s, (unsigned char*)getimagevalue(scaleunit*(unsigned int)i, 3, rate), ic->ctext);
+ gdImageLine(ic->im, x + 36, y + 124 - s, x + 460, y + 124 - s, ic->cline);
+ gdImageLine(ic->im, x + 36, y + 124 - ((s + prev) / 2), x + 460, y + 124 - ((s + prev) / 2), ic->clinel);
+ gdImageString(ic->im, gdFontGetTiny(), x + 16, y + 121 - s, (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, rate), ic->ctext);
prev = s;
}
s = (int)(121 * ((scaleunit * (unsigned int)i) / (float)max));
- if ( ((s+prev)/2) <= 128 ) {
- gdImageLine(ic->im, x+36, y+124-((s+prev)/2), x+460, y+124-((s+prev)/2), ic->clinel);
+ if (((s + prev) / 2) <= 128) {
+ gdImageLine(ic->im, x + 36, y + 124 - ((s + prev) / 2), x + 460, y + 124 - ((s + prev) / 2), ic->clinel);
} else {
i = i - step;
}
/* scale text */
- gdImageStringUp(ic->im, gdFontGetTiny(), x-2, y+60+(rate*10), (unsigned char*)getimagescale(scaleunit * (unsigned int)i, rate), ic->ctext);
+ gdImageStringUp(ic->im, gdFontGetTiny(), x - 2, y + 60 + (rate * 10), (unsigned char *)getimagescale(scaleunit * (unsigned int)i, rate), ic->ctext);
/* x-axis values and poles */
for (i = 0; i < 24; i++) {
- s = tmax-i;
- if (s<0) {
- s+=24;
+ s = tmax - i;
+ if (s < 0) {
+ s += 24;
}
snprintf(buffer, 32, "%02d ", s);
- gdImageString(ic->im, gdFontGetTiny(), x+440-(i*17), y+128, (unsigned char*)buffer, ic->ctext);
- drawpole(ic, x+438-(i*17), y, 124, hourdata[s].rx, hourdata[s].tx, max);
+ gdImageString(ic->im, gdFontGetTiny(), x + 440 - (i * 17), y + 128, (unsigned char *)buffer, ic->ctext);
+ drawpole(ic, x + 438 - (i * 17), y, 124, hourdata[s].rx, hourdata[s].tx, max);
}
/* axis */
- gdImageLine(ic->im, x+36-4, y+124, x+466, y+124, ic->ctext);
- gdImageLine(ic->im, x+36, y-10, x+36, y+124+4, ic->ctext);
+ gdImageLine(ic->im, x + 36 - 4, y + 124, x + 466, y + 124, ic->ctext);
+ gdImageLine(ic->im, x + 36, y - 10, x + 36, y + 124 + 4, ic->ctext);
/* arrows */
- gdImageLine(ic->im, x+465, y+124, x+462, y+122, ic->ctext);
- gdImageLine(ic->im, x+465, y+124, x+462, y+126, ic->ctext);
- gdImageLine(ic->im, x+462, y+122, x+462, y+126, ic->ctext);
- gdImageLine(ic->im, x+36, y-9, x+38, y-6, ic->ctext);
- gdImageLine(ic->im, x+36, y-9, x+34, y-6, ic->ctext);
- gdImageLine(ic->im, x+34, y-6, x+38, y-6, ic->ctext);
+ gdImageLine(ic->im, x + 465, y + 124, x + 462, y + 122, ic->ctext);
+ gdImageLine(ic->im, x + 465, y + 124, x + 462, y + 126, ic->ctext);
+ gdImageLine(ic->im, x + 462, y + 122, x + 462, y + 126, ic->ctext);
+ gdImageLine(ic->im, x + 36, y - 9, x + 38, y - 6, ic->ctext);
+ gdImageLine(ic->im, x + 36, y - 9, x + 34, y - 6, ic->ctext);
+ gdImageLine(ic->im, x + 34, y - 6, x + 38, y - 6, ic->ctext);
}
void drawhourly(IMAGECONTENT *ic, const int rate)
}
layoutinit(ic, buffer, width, height);
- drawlegend(ic, 242, 183-headermod);
- drawhours(ic, 12, 46-headermod, rate);
+ drawlegend(ic, 242, 183 - headermod);
+ drawhours(ic, 12, 46 - headermod, rate);
}
void drawlist(IMAGECONTENT *ic, const char *listname)
if (datainfo.count) {
if (listtype == 4) { // top
- if (cfg.ostyle<=2) {
- drawlegend(ic, 398, 40-headermod);
+ if (cfg.ostyle <= 2) {
+ drawlegend(ic, 398, 40 - headermod);
}
current = time(NULL);
d = localtime(¤t);
strftime(daybuff, 16, stampformat, d);
} else { // everything else
- if (cfg.ostyle>2) {
- drawlegend(ic, 432, 40-headermod);
+ if (cfg.ostyle > 2) {
+ drawlegend(ic, 432, 40 - headermod);
} else {
- drawlegend(ic, 385, 40-headermod);
+ drawlegend(ic, 385, 40 - headermod);
}
}
}
textx = 10;
- texty = 40-headermod;
+ texty = 40 - headermod;
if (listtype == 4) { // top
snprintf(buffer, 512, " # day rx tx total");
}
if (cfg.ostyle > 2) {
strcat(buffer, " avg. rate");
- gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char*)buffer, ic->ctext);
- gdImageLine(ic->im, textx+2, texty+16, textx+392+offsetx, texty+16, ic->cline);
- gdImageLine(ic->im, textx+300+offsetx, texty+2, textx+300+offsetx, texty+40+offsety+(12*rowcount), ic->cline);
+ gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char *)buffer, ic->ctext);
+ gdImageLine(ic->im, textx + 2, texty + 16, textx + 392 + offsetx, texty + 16, ic->cline);
+ gdImageLine(ic->im, textx + 300 + offsetx, texty + 2, textx + 300 + offsetx, texty + 40 + offsety + (12 * rowcount), ic->cline);
} else {
- gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char*)buffer, ic->ctext);
- gdImageLine(ic->im, textx+2, texty+16, textx+296+offsetx, texty+16, ic->cline);
+ gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char *)buffer, ic->ctext);
+ gdImageLine(ic->im, textx + 2, texty + 16, textx + 296 + offsetx, texty + 16, ic->cline);
}
- gdImageLine(ic->im, textx+144+offsetx, texty+2, textx+144+offsetx, texty+40+offsety+(12*rowcount), ic->cline);
- gdImageLine(ic->im, textx+222+offsetx, texty+2, textx+222+offsetx, texty+40+offsety+(12*rowcount), ic->cline);
+ gdImageLine(ic->im, textx + 144 + offsetx, texty + 2, textx + 144 + offsetx, texty + 40 + offsety + (12 * rowcount), ic->cline);
+ gdImageLine(ic->im, textx + 222 + offsetx, texty + 2, textx + 222 + offsetx, texty + 40 + offsety + (12 * rowcount), ic->cline);
texty += 20;
strftime(datebuff, 16, cfg.dformat, d);
if (strcmp(daybuff, datebuff) != 0) {
snprintf(buffer, 32, " %s", datebuff);
- gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char *)buffer, ic->ctext);
texty += 12;
strcpy(daybuff, datebuff);
}
}
if (listtype == 4) {
- if (strftime(datebuff, 16, stampformat, d)<=8) {
+ if (strftime(datebuff, 16, stampformat, d) <= 8) {
snprintf(buffer, 32, " %2d %*s", i, getpadding(8, datebuff), datebuff);
strcat(buffer, " ");
} else {
}
if (strcmp(datebuff, daybuff) == 0) {
if (cfg.ostyle > 2) {
- gdImageFilledRectangle(ic->im, textx+2, texty+2, textx+422, texty+12, ic->cbgoffset);
+ gdImageFilledRectangle(ic->im, textx + 2, texty + 2, textx + 422, texty + 12, ic->cbgoffset);
} else {
- gdImageFilledRectangle(ic->im, textx+2, texty+2, textx+326, texty+12, ic->cbgoffset);
+ gdImageFilledRectangle(ic->im, textx + 2, texty + 2, textx + 326, texty + 12, ic->cbgoffset);
}
}
} else {
- if (strftime(datebuff, 16, stampformat, d)<=8) {
+ if (strftime(datebuff, 16, stampformat, d) <= 8) {
snprintf(buffer, 32, " %*s", getpadding(8, datebuff), datebuff);
strcat(buffer, " ");
} else {
strcat(buffer, " ");
strncat(buffer, getvalue(datalist_i->tx, 10, RT_Normal), 32);
strcat(buffer, " ");
- strncat(buffer, getvalue(datalist_i->rx+datalist_i->tx, 10, RT_Normal), 32);
- if (cfg.ostyle>2) {
+ strncat(buffer, getvalue(datalist_i->rx + datalist_i->tx, 10, RT_Normal), 32);
+ if (cfg.ostyle > 2) {
strcat(buffer, " ");
if (datalist_i->next == NULL) {
d = localtime(&ic->interface.updated);
if (listtype == 1) { // day
- e_secs = (uint64_t)(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+ e_secs = (uint64_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
} else if (listtype == 2) { // month
e_secs = (uint64_t)mosecs(datalist_i->timestamp, ic->interface.updated);
} else if (listtype == 3) { // year
- e_secs = (uint64_t)(d->tm_yday*86400+d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
+ e_secs = (uint64_t)(d->tm_yday * 86400 + d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600));
} else if (listtype == 4) { // top
e_secs = 86400;
} else if (listtype == 5) { // hour
- e_secs = (uint64_t)(d->tm_sec+(d->tm_min*60));
+ e_secs = (uint64_t)(d->tm_sec + (d->tm_min * 60));
} else if (listtype == 6) { // 5min
e_secs = 300;
}
} else if (listtype == 2) { // month
e_secs = (uint64_t)(dmonth(d->tm_mon) * 86400);
} else if (listtype == 3) { // year
- e_secs = (uint64_t)((365 + isleapyear(d->tm_year+1900)) * 86400);
+ e_secs = (uint64_t)((365 + isleapyear(d->tm_year + 1900)) * 86400);
} else if (listtype == 5) { // hour
e_secs = 3600;
} else if (listtype == 6) { // 5min
e_secs = 300;
}
}
- strncat(buffer, gettrafficrate(datalist_i->rx+datalist_i->tx, (time_t)e_secs, 14), 32);
+ strncat(buffer, gettrafficrate(datalist_i->rx + datalist_i->tx, (time_t)e_secs, 14), 32);
}
- gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx, texty, (unsigned char *)buffer, ic->ctext);
if (listtype == 4) { // top
- if (cfg.ostyle>2) {
- drawbar(ic, textx+428, texty+4, 52, datalist_i->rx, datalist_i->tx, datainfo.max);
+ if (cfg.ostyle > 2) {
+ drawbar(ic, textx + 428, texty + 4, 52, datalist_i->rx, datalist_i->tx, datainfo.max);
} else {
- drawbar(ic, textx+336, texty+4, 140, datalist_i->rx, datalist_i->tx, datainfo.max);
+ drawbar(ic, textx + 336, texty + 4, 140, datalist_i->rx, datalist_i->tx, datainfo.max);
}
} else { // everything else
- if (cfg.ostyle>2) {
- drawbar(ic, textx+400, texty+4, 78, datalist_i->rx, datalist_i->tx, datainfo.max);
+ if (cfg.ostyle > 2) {
+ drawbar(ic, textx + 400, texty + 4, 78, datalist_i->rx, datalist_i->tx, datainfo.max);
} else {
- drawbar(ic, textx+304, texty+4, 170, datalist_i->rx, datalist_i->tx, datainfo.max);
+ drawbar(ic, textx + 304, texty + 4, 170, datalist_i->rx, datalist_i->tx, datainfo.max);
}
}
texty += 12;
if (cfg.ostyle > 2) {
i += 46;
}
- gdImageString(ic->im, gdFontGetSmall(), textx+i, texty, (unsigned char*)"no data available", ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx + i, texty, (unsigned char *)"no data available", ic->ctext);
texty += 12;
}
if (cfg.ostyle > 2) {
- gdImageLine(ic->im, textx+2, texty+5, textx+392+offsetx, texty+5, ic->cline);
+ gdImageLine(ic->im, textx + 2, texty + 5, textx + 392 + offsetx, texty + 5, ic->cline);
} else {
- gdImageLine(ic->im, textx+2, texty+5, textx+296+offsetx, texty+5, ic->cline);
+ gdImageLine(ic->im, textx + 2, texty + 5, textx + 296 + offsetx, texty + 5, ic->cline);
}
if ((strlen(ic->dataend) == 0 && datainfo.count > 0 && listtype < 4) || (strlen(ic->dataend) > 0 && datainfo.count > 1 && listtype != 4)) {
d = localtime(&ic->interface.updated);
- if ( datalist_i->rx==0 || datalist_i->tx==0 || strlen(ic->dataend)>0) {
+ if (datalist_i->rx == 0 || datalist_i->tx == 0 || strlen(ic->dataend) > 0) {
e_rx = e_tx = 0;
} else {
div = 0;
strcat(buffer, " ");
strncat(buffer, getvalue(e_tx, 10, RT_Estimate), 32);
strcat(buffer, " ");
- strncat(buffer, getvalue(e_rx+e_tx, 10, RT_Estimate), 32);
+ strncat(buffer, getvalue(e_rx + e_tx, 10, RT_Estimate), 32);
} else {
if (datainfo.count < 100) {
- snprintf(datebuff, 16, "sum of %"PRIu32"", datainfo.count);
+ snprintf(datebuff, 16, "sum of %" PRIu32 "", datainfo.count);
} else {
snprintf(datebuff, 16, "sum");
}
strncat(buffer, getvalue(datainfo.sumrx + datainfo.sumtx, 10, RT_Normal), 32);
}
- gdImageString(ic->im, gdFontGetSmall(), textx, texty+8, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx, texty + 8, (unsigned char *)buffer, ic->ctext);
}
dbdatalistfree(&datalist);
headermod = 0;
}
- yesterday=ic->current-86400;
+ yesterday = ic->current - 86400;
ic->im = gdImageCreate(width, height);
}
/* today / latest day */
- if ( data_current->rx + data_current->tx == 0 ) {
+ if (data_current->rx + data_current->tx == 0) {
rxp = txp = 0;
} else {
- rxp = data_current->rx / (float)( data_current->rx + data_current->tx ) * 100;
+ rxp = data_current->rx / (float)(data_current->rx + data_current->tx) * 100;
txp = (float)100 - rxp;
}
/* do scaling if needed */
- if ( data_previous != NULL && (data_current->rx + data_current->tx) < (data_previous->rx + data_previous->tx) ) {
+ if (data_previous != NULL && (data_current->rx + data_current->tx) < (data_previous->rx + data_previous->tx)) {
mod = (data_current->rx + data_current->tx) / (float)(data_previous->rx + data_previous->tx);
rxp = rxp * mod;
txp = txp * mod;
offset = 85;
}
- drawdonut(ic, 150+offset, 75-headermod, rxp, txp);
+ drawdonut(ic, 150 + offset, 75 - headermod, rxp, txp);
- textx = 100+offset;
- texty = 30-headermod;
+ textx = 100 + offset;
+ texty = 30 - headermod;
/* get formated date for today */
d = localtime(&ic->current);
strftime(daytemp, 16, cfg.dformat, d);
/* change daytemp to today if formated days match */
- if (strcmp(datebuff, daytemp)==0) {
+ if (strcmp(datebuff, daytemp) == 0) {
strncpy_nt(daytemp, "today", 32);
}
snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp);
- gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetLarge(), textx - 54, texty - 1, (unsigned char *)buffer, ic->ctext);
if (cfg.summaryrate) {
d = localtime(&ic->interface.updated);
- snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx+data_current->tx, d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600), 15));
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+58, (unsigned char*)buffer, ic->ctext);
+ snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx + data_current->tx, d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600), 15));
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 58, (unsigned char *)buffer, ic->ctext);
} else {
texty += 7;
}
snprintf(buffer, 4, "rx ");
strncat(buffer, getvalue(data_current->rx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 18, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
strncat(buffer, getvalue(data_current->tx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 30, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(data_current->rx+data_current->tx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
+ strncat(buffer, getvalue(data_current->rx + data_current->tx, 12, RT_Normal), 32);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 44, (unsigned char *)buffer, ic->ctext);
/* yesterday */
if (data_previous != NULL) {
- if ( data_previous->rx + data_previous->tx == 0 ) {
+ if (data_previous->rx + data_previous->tx == 0) {
rxp = txp = 0;
} else {
- rxp = data_previous->rx / (float)( data_previous->rx + data_previous->tx ) * 100;
+ rxp = data_previous->rx / (float)(data_previous->rx + data_previous->tx) * 100;
txp = (float)100 - rxp;
}
/* do scaling if needed */
- if ( (data_previous->rx + data_previous->tx) < (data_current->rx + data_current->tx) ) {
+ if ((data_previous->rx + data_previous->tx) < (data_current->rx + data_current->tx)) {
mod = (data_previous->rx + data_previous->tx) / (float)(data_current->rx + data_current->tx);
rxp = rxp * mod;
txp = txp * mod;
}
- drawdonut(ic, 330, 75-headermod, rxp, txp);
+ drawdonut(ic, 330, 75 - headermod, rxp, txp);
textx = 280;
- texty = 30-headermod;
+ texty = 30 - headermod;
/* get formated date for yesterday */
d = localtime(&yesterday);
strftime(daytemp, 16, cfg.dformat, d);
/* change daytemp to yesterday if formated days match */
- if (strcmp(datebuff, daytemp)==0) {
+ if (strcmp(datebuff, daytemp) == 0) {
strncpy_nt(daytemp, "yesterday", 32);
}
snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp);
- gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetLarge(), textx - 54, texty - 1, (unsigned char *)buffer, ic->ctext);
if (cfg.summaryrate) {
- snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx+data_previous->tx, 86400, 15));
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+58, (unsigned char*)buffer, ic->ctext);
+ snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx + data_previous->tx, 86400, 15));
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 58, (unsigned char *)buffer, ic->ctext);
} else {
texty += 7;
}
snprintf(buffer, 4, "rx ");
strncat(buffer, getvalue(data_previous->rx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 18, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
strncat(buffer, getvalue(data_previous->tx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 30, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(data_previous->rx+data_previous->tx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
+ strncat(buffer, getvalue(data_previous->rx + data_previous->tx, 12, RT_Normal), 32);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 44, (unsigned char *)buffer, ic->ctext);
}
data_current = NULL;
}
/* current month */
- if ( data_current->rx + data_current->tx == 0 ) {
+ if (data_current->rx + data_current->tx == 0) {
rxp = txp = 0;
} else {
- rxp = data_current->rx / (float)( data_current->rx + data_current->tx ) * 100;
+ rxp = data_current->rx / (float)(data_current->rx + data_current->tx) * 100;
txp = (float)100 - rxp;
}
/* do scaling if needed */
- if ( data_previous != NULL && (data_current->rx + data_current->tx) < (data_previous->rx + data_previous->tx) ) {
+ if (data_previous != NULL && (data_current->rx + data_current->tx) < (data_previous->rx + data_previous->tx)) {
mod = (data_current->rx + data_current->tx) / (float)(data_previous->rx + data_previous->tx);
rxp = rxp * mod;
txp = txp * mod;
offset = 0;
}
- drawdonut(ic, 150+offset, 163-headermod, rxp, txp);
+ drawdonut(ic, 150 + offset, 163 - headermod, rxp, txp);
- textx = 100+offset;
- texty = 118-headermod;
+ textx = 100 + offset;
+ texty = 118 - headermod;
d = localtime(&data_current->timestamp);
strftime(daytemp, 16, cfg.mformat, d);
snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp);
- gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetLarge(), textx - 54, texty - 1, (unsigned char *)buffer, ic->ctext);
if (cfg.summaryrate) {
- snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx+data_current->tx, mosecs(data_current->timestamp, ic->interface.updated), 15));
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+58, (unsigned char*)buffer, ic->ctext);
+ snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx + data_current->tx, mosecs(data_current->timestamp, ic->interface.updated), 15));
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 58, (unsigned char *)buffer, ic->ctext);
} else {
texty += 7;
}
snprintf(buffer, 4, "rx ");
strncat(buffer, getvalue(data_current->rx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 18, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
strncat(buffer, getvalue(data_current->tx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 30, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(data_current->rx+data_current->tx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
+ strncat(buffer, getvalue(data_current->rx + data_current->tx, 12, RT_Normal), 32);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 44, (unsigned char *)buffer, ic->ctext);
/* previous month */
if (data_previous != NULL) {
- if ( data_previous->rx + data_previous->tx == 0 ) {
+ if (data_previous->rx + data_previous->tx == 0) {
rxp = txp = 0;
} else {
- rxp = data_previous->rx / (float)( data_previous->rx + data_previous->tx ) * 100;
+ rxp = data_previous->rx / (float)(data_previous->rx + data_previous->tx) * 100;
txp = (float)100 - rxp;
}
/* do scaling if needed */
- if ( (data_previous->rx + data_previous->tx) < (data_current->rx + data_current->tx) ) {
+ if ((data_previous->rx + data_previous->tx) < (data_current->rx + data_current->tx)) {
mod = (data_previous->rx + data_previous->tx) / (float)(data_current->rx + data_current->tx);
rxp = rxp * mod;
txp = txp * mod;
}
- drawdonut(ic, 330, 163-headermod, rxp, txp);
+ drawdonut(ic, 330, 163 - headermod, rxp, txp);
textx = 280;
- texty = 118-headermod;
+ texty = 118 - headermod;
d = localtime(&data_previous->timestamp);
strftime(daytemp, 16, cfg.mformat, d);
snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp);
- gdImageString(ic->im, gdFontGetLarge(), textx-54, texty-1, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetLarge(), textx - 54, texty - 1, (unsigned char *)buffer, ic->ctext);
if (cfg.summaryrate) {
- snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx+data_previous->tx, dmonth(d->tm_mon)*86400, 15));
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+58, (unsigned char*)buffer, ic->ctext);
+ snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx + data_previous->tx, dmonth(d->tm_mon) * 86400, 15));
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 58, (unsigned char *)buffer, ic->ctext);
} else {
texty += 7;
}
snprintf(buffer, 4, "rx ");
strncat(buffer, getvalue(data_previous->rx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+18, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 18, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
strncat(buffer, getvalue(data_previous->tx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+30, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 30, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(data_previous->rx+data_previous->tx, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx-74, texty+44, (unsigned char*)buffer, ic->ctext);
+ strncat(buffer, getvalue(data_previous->rx + data_previous->tx, 12, RT_Normal), 32);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 74, texty + 44, (unsigned char *)buffer, ic->ctext);
}
data_current = NULL;
/* all time */
textx = 385;
- texty = 57-headermod;
+ texty = 57 - headermod;
- gdImageString(ic->im, gdFontGetLarge(), textx+12, texty, (unsigned char*)"all time", ic->ctext);
+ gdImageString(ic->im, gdFontGetLarge(), textx + 12, texty, (unsigned char *)"all time", ic->ctext);
snprintf(buffer, 4, "rx ");
strncat(buffer, getvalue(ic->interface.rxtotal, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx, texty+24, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx, texty + 24, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, "tx ");
strncat(buffer, getvalue(ic->interface.txtotal, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx, texty+36, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx, texty + 36, (unsigned char *)buffer, ic->ctext);
snprintf(buffer, 4, " = ");
- strncat(buffer, getvalue(ic->interface.rxtotal+ic->interface.txtotal, 12, RT_Normal), 32);
- gdImageString(ic->im, gdFontGetSmall(), textx, texty+50, (unsigned char*)buffer, ic->ctext);
+ strncat(buffer, getvalue(ic->interface.rxtotal + ic->interface.txtotal, 12, RT_Normal), 32);
+ gdImageString(ic->im, gdFontGetSmall(), textx, texty + 50, (unsigned char *)buffer, ic->ctext);
d = localtime(&ic->interface.created);
strftime(datebuff, 16, cfg.tformat, d);
snprintf(daytemp, 24, "since %s", datebuff);
snprintf(buffer, 32, "%23s", daytemp);
- gdImageString(ic->im, gdFontGetSmall(), textx-48, texty+70, (unsigned char*)buffer, ic->ctext);
+ gdImageString(ic->im, gdFontGetSmall(), textx - 48, texty + 70, (unsigned char *)buffer, ic->ctext);
- drawlegend(ic, 410, 155-headermod);
+ drawlegend(ic, 410, 155 - headermod);
/* hours if requested */
switch (type) {
case 1:
- drawhours(ic, 500, 46-headermod, rate);
+ drawhours(ic, 500, 46 - headermod, rate);
break;
case 2:
- drawhours(ic, 12, 215-headermod, rate);
+ drawhours(ic, 12, 215 - headermod, rate);
break;
default:
break;
offset = 0;
}
- snprintf(hex, 3, "%c%c", input[(0+offset)], input[(1+offset)]);
+ snprintf(hex, 3, "%c%c", input[(0 + offset)], input[(1 + offset)]);
snprintf(dec, 4, "%d", (int)strtol(hex, NULL, 16));
rgb[0] = atoi(dec);
- snprintf(hex, 3, "%c%c", input[(2+offset)], input[(3+offset)]);
+ snprintf(hex, 3, "%c%c", input[(2 + offset)], input[(3 + offset)]);
snprintf(dec, 4, "%d", (int)strtol(hex, NULL, 16));
rgb[1] = atoi(dec);
- snprintf(hex, 3, "%c%c", input[(4+offset)], input[(5+offset)]);
+ snprintf(hex, 3, "%c%c", input[(4 + offset)], input[(5 + offset)]);
snprintf(dec, 4, "%d", (int)strtol(hex, NULL, 16));
rgb[2] = atoi(dec);
printf("m%d (%d): %d, %d, %d -> ", offset, force, rgb[0], rgb[1], rgb[2]);
}
- for (i=0; i<3; i++) {
- if ((rgb[i]+offset)>255 || (rgb[i]+offset)<0) {
+ for (i = 0; i < 3; i++) {
+ if ((rgb[i] + offset) > 255 || (rgb[i] + offset) < 0) {
overflow++;
}
}
/* positive offset gives lighter color, negative darker if forced */
/* otherwise the direction is changed depending on possible overflows */
- for (i=0; i<3; i++) {
- if (overflow<2 || force) {
- if ((rgb[i]+offset)>255) {
+ for (i = 0; i < 3; i++) {
+ if (overflow < 2 || force) {
+ if ((rgb[i] + offset) > 255) {
rgb[i] = 255;
- } else if ((rgb[i]+offset)<0) {
+ } else if ((rgb[i] + offset) < 0) {
rgb[i] = 0;
} else {
rgb[i] += offset;
}
} else {
- if ((rgb[i]-offset)<0) {
+ if ((rgb[i] - offset) < 0) {
rgb[i] = 0;
- } else if ((rgb[i]-offset)>255) {
+ } else if ((rgb[i] - offset) > 255) {
rgb[i] = 255;
} else {
rgb[i] -= offset;
int i, declen = 0, unit = 0, p = 1024;
uint64_t limit;
- if (b==0){
+ if (b == 0) {
snprintf(buffer, 64, "%*s", len, "--");
} else {
if (rate && (getunit() == 2 || getunit() == 4)) {
p = 1000;
unit = getunit();
}
- for (i=UNITPREFIXCOUNT-1; i>0; i--) {
- limit = (uint64_t)(pow(p, i-1)) * 1000;
+ for (i = UNITPREFIXCOUNT - 1; i > 0; i--) {
+ limit = (uint64_t)(pow(p, i - 1)) * 1000;
if (b >= limit) {
- snprintf(buffer, 64, "%*.*f", len, declen, b/(double)(getunitdivisor(unit, i+1)));
+ snprintf(buffer, 64, "%*.*f", len, declen, b / (double)(getunitdivisor(unit, i + 1)));
return buffer;
}
}
- snprintf(buffer, 64, "%*"PRIu64"", len, b);
+ snprintf(buffer, 64, "%*" PRIu64 "", len, b);
}
return buffer;
unit = getunit();
- if (b==0) {
+ if (b == 0) {
snprintf(buffer, 8, "--");
} else {
if (rate) {
if (unit == 2 || unit == 4) {
p = 1000;
}
- while (div < UNITPREFIXCOUNT && b >= (pow(p, div-1) * 1000)) {
+ while (div < UNITPREFIXCOUNT && b >= (pow(p, div - 1) * 1000)) {
div++;
}
snprintf(buffer, 8, "%s", getrateunitprefix(unit, div));
} else {
- while (div < UNITPREFIXCOUNT && b >= (pow(p, div-1) * 1000)) {
+ while (div < UNITPREFIXCOUNT && b >= (pow(p, div - 1) * 1000)) {
div++;
}
snprintf(buffer, 8, "%s", getunitprefix(div));
}
/* get unit */
- for (i=0; result>=div; i++) {
+ for (i = 0; result >= div; i++) {
result = result / div;
}
/* round result depending of scale */
- if (result>=300) {
- result = result/4 + (100 - ((result/4) % 100));
- } else if (result>20) {
- result = result/4 + (10 - ((result/4) % 10));
+ if (result >= 300) {
+ result = result / 4 + (100 - ((result / 4) % 100));
+ } else if (result > 20) {
+ result = result / 4 + (10 - ((result / 4) % 10));
} else {
- result = result/4;
+ result = result / 4;
}
/* put unit back */
#ifndef IMAGE_H
#define IMAGE_H
-#include <gd.h> /* libgd2-dev libgd2 */
-#include <gdfontt.h> /* gdFontGetTiny() */
-#include <gdfonts.h> /* gdFontGetSmall() */
-#include <gdfontmb.h> /* gdFontGetMediumBold() */
-#include <gdfontl.h> /* gdFontGetLarge() */
-#include <gdfontg.h> /* gdFontGetGiant() */
+#include <gd.h> /* libgd2-dev libgd2 */
+#include <gdfontt.h> /* gdFontGetTiny() */
+#include <gdfonts.h> /* gdFontGetSmall() */
+#include <gdfontmb.h> /* gdFontGetMediumBold() */
+#include <gdfontl.h> /* gdFontGetLarge() */
+#include <gdfontg.h> /* gdFontGetGiant() */
/* rectangle size */
#define YBEGINOFFSET (-1)
#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__FreeBSD_kernel__)
- #if defined(__clang__)
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wreserved-id-macro"
- #endif
- #define _XOPEN_SOURCE 600
- #if defined(__clang__)
- #pragma clang diagnostic pop
- #endif
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreserved-id-macro"
+#endif
+#define _XOPEN_SOURCE 600
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
#endif
/* enable wcswidth on kFreeBSD */
#if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
- #define __USE_XOPEN
+#define __USE_XOPEN
#endif
#include "common.h"
#include "misc.h"
}
}
- free = (uint64_t)(buf.f_bavail/(float)1024) * buf.f_bsize;
+ free = (uint64_t)(buf.f_bavail / (float)1024) * buf.f_bsize;
if (debug) {
printf("bsize %d\n", (int)buf.f_bsize);
printf("bfree %lu\n", (unsigned long int)buf.f_bfree);
printf("bavail %lu\n", (unsigned long int)buf.f_bavail);
printf("ffree %lu\n", (unsigned long int)buf.f_ffree);
- printf("%"PRIu64" free space left\n", free);
+ printf("%" PRIu64 " free space left\n", free);
}
- /* the database is less than 3kB but let's require */
- /* 1MB to be on the safe side, anyway, the filesystem should */
+ /* the database is likely to be less than 200 kiB but let's require */
+ /* 1 MiB to be on the safe side, anyway, the filesystem should */
/* always have more free space than that */
- if (free<=1024) {
+ if (free <= 1024) {
return 0;
} else {
return 1;
default:
snprintf(errorstring, 1024, "DEBUG: Unknown signal %d", sig);
break;
-
}
printe(PT_Info);
}
uint64_t getbtime(void)
{
- uint64_t result=0;
+ uint64_t result = 0;
#if defined(__linux__)
FILE *fp;
int check;
char temp[64], statline[128];
- if ((fp=fopen("/proc/stat","r"))==NULL) {
+ if ((fp = fopen("/proc/stat", "r")) == NULL) {
snprintf(errorstring, 1024, "Unable to read /proc/stat: %s", strerror(errno));
printe(PT_Error);
if (noexit) {
}
}
- check=0;
- while (fgets(statline,128,fp)!=NULL) {
- sscanf(statline,"%63s",temp);
- if (strcmp(temp,"btime")==0) {
+ check = 0;
+ while (fgets(statline, 128, fp) != NULL) {
+ sscanf(statline, "%63s", temp);
+ if (strcmp(temp, "btime") == 0) {
/* if (debug)
printf("\n%s\n",statline); */
- check=1;
+ check = 1;
break;
}
}
fclose(fp);
- if (check==0) {
+ if (check == 0) {
snprintf(errorstring, 1024, "btime missing from /proc/stat.");
printe(PT_Error);
if (noexit) {
}
}
- result = strtoull(statline+6, (char **)NULL, 0);
+ result = strtoull(statline + 6, (char **)NULL, 0);
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
struct timeval btm;
p = 1000;
}
- if ( (type == RT_Estimate) && (bytes == 0) ) {
- declen = len-(int)strlen(getunitprefix(2))-2;
+ if ((type == RT_Estimate) && (bytes == 0)) {
+ declen = len - (int)strlen(getunitprefix(2)) - 2;
if (declen < 2) {
declen = 2;
}
snprintf(buffer, 64, "%*s %*s", declen, "--", (int)strlen(getunitprefix(2)), " ");
} else {
- for (i=UNITPREFIXCOUNT-1; i>0; i--) {
- limit = (uint64_t)(pow(p, i-1)) * 1000;
+ for (i = UNITPREFIXCOUNT - 1; i > 0; i--) {
+ limit = (uint64_t)(pow(p, i - 1)) * 1000;
if (bytes >= limit) {
- if (i>1) {
- snprintf(buffer, 64, "%"DECCONV"*.*f %s", getunitspacing(len, 5), declen, bytes/(double)(getunitdivisor(cfg.unitmode, i+1)), getunitprefix(i+1));
+ if (i > 1) {
+ snprintf(buffer, 64, "%" DECCONV "*.*f %s", getunitspacing(len, 5), declen, bytes / (double)(getunitdivisor(cfg.unitmode, i + 1)), getunitprefix(i + 1));
} else {
if (type == RT_Estimate) {
declen = 0;
}
- snprintf(buffer, 64, "%"DECCONV"*.*f %s", getunitspacing(len, 2), declen, bytes/(double)(getunitdivisor(cfg.unitmode, i+1)), getunitprefix(i+1));
+ snprintf(buffer, 64, "%" DECCONV "*.*f %s", getunitspacing(len, 2), declen, bytes / (double)(getunitdivisor(cfg.unitmode, i + 1)), getunitprefix(i + 1));
}
return buffer;
}
}
- snprintf(buffer, 64, "%"DECCONV"*"PRIu64" %s", getunitspacing(len, 1), bytes, getunitprefix(1));
+ snprintf(buffer, 64, "%" DECCONV "*" PRIu64 " %s", getunitspacing(len, 1), bytes, getunitprefix(1));
}
return buffer;
int declen = cfg.defaultdecimals;
uint64_t b;
- if (interval==0) {
+ if (interval == 0) {
snprintf(buffer, 64, "%*s", len, "n/a");
return buffer;
}
}
} else {
b = bytes;
- if (interval < 5 && ( b / (uint64_t)interval ) < 1000) {
+ if (interval < 5 && (b / (uint64_t)interval) < 1000) {
declen = 0;
}
}
const char *getunitprefix(const int index)
{
+ /* clang-format off */
static const char *unitprefix[] = { "na",
"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", /* IEC - 1024^n */
"B", "KB", "MB", "GB", "TB", "PB", "EB", /* JEDEC - 1024^n */
"B", "kB", "MB", "GB", "TB", "PB", "EB" }; /* SI - 1000^n */
+ /* clang-format on */
- if (index>UNITPREFIXCOUNT) {
+ if (index > UNITPREFIXCOUNT) {
return unitprefix[0];
} else {
- return unitprefix[(cfg.unitmode*UNITPREFIXCOUNT)+index];
+ return unitprefix[(cfg.unitmode * UNITPREFIXCOUNT) + index];
}
}
const char *getrateunitprefix(const int unitmode, const int index)
{
+ /* clang-format off */
static const char *rateunitprefix[] = { "na",
"B/s", "KiB/s", "MiB/s", "GiB/s", "TiB/s", "PiB/s", "EiB/s", /* IEC - 1024^n */
"B/s", "KB/s", "MB/s", "GB/s", "TB/s", "PB/s", "EB/s", /* JEDEC - 1024^n */
"B/s", "kB/s", "MB/s", "GB/s", "TB/s", "PB/s", "EB/s", /* SI - 1000^n */
"bit/s", "Kibit/s", "Mibit/s", "Gibit/s", "Tibit/s", "Pibit/s", "Eibit/s", /* IEC - 1024^n */
"bit/s", "kbit/s", "Mbit/s", "Gbit/s", "Tbit/s", "Pbit/s", "Ebit/s" }; /* SI - 1000^n */
+ /* clang-format on */
- if (index>UNITPREFIXCOUNT) {
+ if (index > UNITPREFIXCOUNT) {
return rateunitprefix[0];
} else {
- return rateunitprefix[(unitmode*UNITPREFIXCOUNT)+index];
+ return rateunitprefix[(unitmode * UNITPREFIXCOUNT) + index];
}
}
uint64_t getunitdivisor(const int unitmode, const int index)
{
- if (index>UNITPREFIXCOUNT) {
+ if (index > UNITPREFIXCOUNT) {
return 1;
} else {
if (unitmode == 2 || unitmode == 4) {
- return (uint64_t)(pow(1000, index-1));
+ return (uint64_t)(pow(1000, index - 1));
} else {
- return (uint64_t)(pow(1024, index-1));
+ return (uint64_t)(pow(1024, index - 1));
}
}
}
p = 1000;
}
- for (i=UNITPREFIXCOUNT-1; i>0; i--)
- {
- limit = (uint64_t)(pow(p, i-1)) * 1000;
+ for (i = UNITPREFIXCOUNT - 1; i > 0; i--) {
+ limit = (uint64_t)(pow(p, i - 1)) * 1000;
if (rate >= limit) {
- l = getratespacing(len, unit, i+1);
- snprintf(buffer, 64, "%"DECCONV"*.2f %s", l, rate/(double)(getunitdivisor(unit, i+1)), getrateunitprefix(unit, i+1));
+ l = getratespacing(len, unit, i + 1);
+ snprintf(buffer, 64, "%" DECCONV "*.2f %s", l, rate / (double)(getunitdivisor(unit, i + 1)), getrateunitprefix(unit, i + 1));
return buffer;
}
}
l = getratespacing(len, unit, 1);
- snprintf(buffer, 64, "%"DECCONV"*.*f %s", l, declen, rate/(double)(getunitdivisor(unit, 1)), getrateunitprefix(unit, 1));
+ snprintf(buffer, 64, "%" DECCONV "*.*f %s", l, declen, rate / (double)(getunitdivisor(unit, 1)), getrateunitprefix(unit, 1));
return buffer;
}
{
short valid;
unsigned int len, i, t;
- const char *templates[] = { "dddd-dd-dd dd:dd", "dddd-dd-dd" };
+ const char *templates[] = {"dddd-dd-dd dd:dd", "dddd-dd-dd"};
len = (unsigned int)strlen(str);
if (len > strlen(templates[0])) {
return 0;
}
- for (t=0; t<2; t++) {
+ for (t = 0; t < 2; t++) {
if (len != strlen(templates[t])) {
continue;
}
valid = 1;
- for (i=0; i<strlen(templates[t]); i++) {
- switch(templates[t][i]) {
+ for (i = 0; i < strlen(templates[t]); i++) {
+ switch (templates[t][i]) {
case 'd':
if (!isdigit(str[i])) {
valid = 0;
}
/* less than 2 seconds doesn't produce good results */
- if (sampletime<2) {
+ if (sampletime < 2) {
printf("Error: Time for sampling too short.\n");
exit(EXIT_FAILURE);
}
snprintf(buffer, 256, "Sampling %s (%u seconds average)", iface, sampletime);
printf("%s", buffer);
fflush(stdout);
- sleep(sampletime/3);
+ sleep(sampletime / 3);
printf(".");
fflush(stdout);
- sleep(sampletime/3);
+ sleep(sampletime / 3);
printf(".");
fflush(stdout);
- sleep(sampletime/3);
+ sleep(sampletime / 3);
printf(".");
fflush(stdout);
- if ((sampletime/3)*3!=sampletime) {
- sleep(sampletime-((sampletime/3)*3));
+ if ((sampletime / 3) * 3 != sampletime) {
+ sleep(sampletime - ((sampletime / 3) * 3));
}
cursortocolumn(1);
/* show the difference in a readable format or json */
if (!json) {
- printf("%"PRIu64" packets sampled in %d seconds\n", rxp+txp, sampletime);
+ printf("%" PRIu64 " packets sampled in %d seconds\n", rxp + txp, sampletime);
printf("Traffic average for %s\n", iface);
- printf("\n rx %s %5"PRIu64" packets/s\n", gettrafficrate(rx, sampletime, 15), (uint64_t)(rxp/sampletime));
- printf(" tx %s %5"PRIu64" packets/s\n\n", gettrafficrate(tx, sampletime, 15), (uint64_t)(txp/sampletime));
+ printf("\n rx %s %5" PRIu64 " packets/s\n", gettrafficrate(rx, sampletime, 15), (uint64_t)(rxp / sampletime));
+ printf(" tx %s %5" PRIu64 " packets/s\n\n", gettrafficrate(tx, sampletime, 15), (uint64_t)(txp / sampletime));
} else {
printf("{\"jsonversion\":\"%d\",", JSONVERSION_TR);
printf("\"vnstatversion\":\"%s\",", getversion());
printf("\"sampletime\":%u,", sampletime);
printf("\"rx\":{");
printf("\"ratestring\":\"%s\",", gettrafficrate(rx, sampletime, 0));
- printf("\"bytespersecond\":%"PRIu64",", (uint64_t)(rx/sampletime));
- printf("\"packetspersecond\":%"PRIu64",", (uint64_t)(rxp/sampletime));
- printf("\"bytes\":%"PRIu64",", rx);
- printf("\"packets\":%"PRIu64"", rxp);
+ printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(rx / sampletime));
+ printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(rxp / sampletime));
+ printf("\"bytes\":%" PRIu64 ",", rx);
+ printf("\"packets\":%" PRIu64 "", rxp);
printf("},");
printf("\"tx\":{");
printf("\"ratestring\":\"%s\",", gettrafficrate(tx, sampletime, 0));
- printf("\"bytespersecond\":%"PRIu64",", (uint64_t)(tx/sampletime));
- printf("\"packetspersecond\":%"PRIu64",", (uint64_t)(txp/sampletime));
- printf("\"bytes\":%"PRIu64",", tx);
- printf("\"packets\":%"PRIu64"", txp);
+ printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(tx / sampletime));
+ printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(txp / sampletime));
+ printf("\"bytes\":%" PRIu64 ",", tx);
+ printf("\"packets\":%" PRIu64 "", txp);
printf("}}\n");
}
}
}
/* set some defaults */
- rxtotal=txtotal=rxptotal=txptotal=rxpmax=txpmax=0;
- rxpmin=txpmin=rxmin=txmin=MAX64;
- rxmax=txmax=0;
+ rxtotal = txtotal = rxptotal = txptotal = rxpmax = txpmax = 0;
+ rxpmin = txpmin = rxmin = txmin = MAX64;
+ rxmax = txmax = 0;
timeslept = 0;
timespent = (uint64_t)time(NULL);
}
/* loop until user gets bored */
- while (intsignal==0) {
+ while (intsignal == 0) {
timeslept = (uint64_t)time(NULL);
txptotal += txp;
/* update min & max */
- if (rxmin>rx) { rxmin = rx; }
- if (txmin>tx) { txmin = tx; }
- if (rxmax<rx) { rxmax = rx; }
- if (txmax<tx) { txmax = tx; }
- if (rxpmin>rxp) { rxpmin = rxp; }
- if (txpmin>txp) { txpmin = txp; }
- if (rxpmax<rxp) { rxpmax = rxp; }
- if (txpmax<txp) { txpmax = txp; }
+ if (rxmin > rx) {
+ rxmin = rx;
+ }
+ if (txmin > tx) {
+ txmin = tx;
+ }
+ if (rxmax < rx) {
+ rxmax = rx;
+ }
+ if (txmax < tx) {
+ txmax = tx;
+ }
+ if (rxpmin > rxp) {
+ rxpmin = rxp;
+ }
+ if (txpmin > txp) {
+ txpmin = txp;
+ }
+ if (rxpmax < rxp) {
+ rxpmax = rxp;
+ }
+ if (txpmax < txp) {
+ txpmax = txp;
+ }
/* show the difference in a readable format or json */
if (!json) {
if (mode == 0) {
/* packets per second visible */
- snprintf(buffer, 128, " rx: %s %*"PRIu64" p/s", gettrafficrate(rx, LIVETIME, ratewidth), ppswidth, (uint64_t)rxp/LIVETIME);
- snprintf(buffer2, 128, " %*s tx: %s %*"PRIu64" p/s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), ppswidth, (uint64_t)txp/LIVETIME);
+ snprintf(buffer, 128, " rx: %s %*" PRIu64 " p/s", gettrafficrate(rx, LIVETIME, ratewidth), ppswidth, (uint64_t)rxp / LIVETIME);
+ snprintf(buffer2, 128, " %*s tx: %s %*" PRIu64 " p/s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), ppswidth, (uint64_t)txp / LIVETIME);
} else {
/* total transfer amount visible */
snprintf(buffer, 128, " rx: %s %s", gettrafficrate(rx, LIVETIME, ratewidth), getvalue(rxtotal, 1, RT_Normal));
}
strcat(buffer, buffer2);
- if (cfg.ostyle!=4 || !debug) {
+ if (cfg.ostyle != 4 || !debug) {
cursortocolumn(1);
eraseline();
}
- if (cfg.ostyle!=4) {
+ if (cfg.ostyle != 4) {
printf("%s", buffer);
fflush(stdout);
} else {
printf("%s\n", buffer);
}
} else {
- printf("{\"index\":%"PRIu64",", index);
- printf("\"seconds\":%"PRIu64",", (uint64_t)time(NULL) - timespent);
+ printf("{\"index\":%" PRIu64 ",", index);
+ printf("\"seconds\":%" PRIu64 ",", (uint64_t)time(NULL) - timespent);
printf("\"rx\":{");
printf("\"ratestring\":\"%s\",", gettrafficrate(rx, LIVETIME, 0));
- printf("\"bytespersecond\":%"PRIu64",", (uint64_t)(rx/LIVETIME));
- printf("\"packetspersecond\":%"PRIu64",", (uint64_t)(rxp/LIVETIME));
- printf("\"bytes\":%"PRIu64",", rx);
- printf("\"packets\":%"PRIu64",", rxp);
- printf("\"totalbytes\":%"PRIu64",", rxtotal);
- printf("\"totalpackets\":%"PRIu64"", rxptotal);
+ printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(rx / LIVETIME));
+ printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(rxp / LIVETIME));
+ printf("\"bytes\":%" PRIu64 ",", rx);
+ printf("\"packets\":%" PRIu64 ",", rxp);
+ printf("\"totalbytes\":%" PRIu64 ",", rxtotal);
+ printf("\"totalpackets\":%" PRIu64 "", rxptotal);
printf("},");
printf("\"tx\":{");
printf("\"ratestring\":\"%s\",", gettrafficrate(tx, LIVETIME, 0));
- printf("\"bytespersecond\":%"PRIu64",", (uint64_t)(tx/LIVETIME));
- printf("\"packetspersecond\":%"PRIu64",", (uint64_t)(txp/LIVETIME));
- printf("\"bytes\":%"PRIu64",", tx);
- printf("\"packets\":%"PRIu64",", txp);
- printf("\"totalbytes\":%"PRIu64",", txtotal);
- printf("\"totalpackets\":%"PRIu64"", txptotal);
+ printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(tx / LIVETIME));
+ printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(txp / LIVETIME));
+ printf("\"bytes\":%" PRIu64 ",", tx);
+ printf("\"packets\":%" PRIu64 ",", txp);
+ printf("\"totalbytes\":%" PRIu64 ",", txtotal);
+ printf("\"totalpackets\":%" PRIu64 "", txptotal);
printf("}}\n");
index++;
}
}
/* print some statistics if enough time did pass */
- if (!json && timespent>=10) {
+ if (!json && timespent >= 10) {
printf("\n %s / traffic statistics\n\n", iface);
printf(" min %s", gettrafficrate(rxmin, LIVETIME, 15));
printf(" | %s\n", gettrafficrate(txmin, LIVETIME, 15));
printf("--------------------------------------+------------------\n");
- printf(" packets %12"PRIu64" | %12"PRIu64"\n", rxptotal, txptotal);
+ printf(" packets %12" PRIu64 " | %12" PRIu64 "\n", rxptotal, txptotal);
printf("--------------------------------------+------------------\n");
- printf(" max %9"PRIu64" p/s | %9"PRIu64" p/s\n", rxpmax/LIVETIME, txpmax/LIVETIME);
- printf(" average %9"PRIu64" p/s | %9"PRIu64" p/s\n", rxptotal/timespent, txptotal/timespent);
- printf(" min %9"PRIu64" p/s | %9"PRIu64" p/s\n", rxpmin/LIVETIME, txpmin/LIVETIME);
+ printf(" max %9" PRIu64 " p/s | %9" PRIu64 " p/s\n", rxpmax / LIVETIME, txpmax / LIVETIME);
+ printf(" average %9" PRIu64 " p/s | %9" PRIu64 " p/s\n", rxptotal / timespent, txptotal / timespent);
+ printf(" min %9" PRIu64 " p/s | %9" PRIu64 " p/s\n", rxpmin / LIVETIME, txpmin / LIVETIME);
printf("--------------------------------------+------------------\n");
- if (timespent<=60) {
- printf(" time %9"PRIu64" seconds\n", timespent);
+ if (timespent <= 60) {
+ printf(" time %9" PRIu64 " seconds\n", timespent);
} else {
- printf(" time %7.2f minutes\n", timespent/(double)60);
+ printf(" time %7.2f minutes\n", timespent / (double)60);
}
printf("\n");
} else if (json) {
- printf("{\"seconds\":%"PRIu64",", timespent);
- printf("\"rx\":{");
- printf("\"maxratestring\":\"%s\",", gettrafficrate(rxmax, LIVETIME, 0));
- printf("\"averageratestring\":\"%s\",", gettrafficrate(rxtotal, (time_t)timespent, 0));
- printf("\"minratestring\":\"%s\",", gettrafficrate(rxmin, LIVETIME, 0));
- printf("\"totalbytes\":%"PRIu64",", rxtotal);
- printf("\"maxbytes\":%"PRIu64",", rxmax);
- printf("\"minbytes\":%"PRIu64",", rxmin);
- printf("\"totalpackets\":%"PRIu64",", rxptotal);
- printf("\"maxpackets\":%"PRIu64",", rxpmax);
- printf("\"minpackets\":%"PRIu64"", rxpmin);
- printf("},");
- printf("\"tx\":{");
- printf("\"maxratestring\":\"%s\",", gettrafficrate(txmax, LIVETIME, 0));
- printf("\"averageratestring\":\"%s\",", gettrafficrate(txtotal, (time_t)timespent, 0));
- printf("\"minratestring\":\"%s\",", gettrafficrate(txmin, LIVETIME, 0));
- printf("\"totalbytes\":%"PRIu64",", txtotal);
- printf("\"maxbytes\":%"PRIu64",", txmax);
- printf("\"minbytes\":%"PRIu64",", txmin);
- printf("\"totalpackets\":%"PRIu64",", txptotal);
- printf("\"maxpackets\":%"PRIu64",", txpmax);
- printf("\"minpackets\":%"PRIu64"", txpmin);
- printf("}}\n");
+ printf("{\"seconds\":%" PRIu64 ",", timespent);
+ printf("\"rx\":{");
+ printf("\"maxratestring\":\"%s\",", gettrafficrate(rxmax, LIVETIME, 0));
+ printf("\"averageratestring\":\"%s\",", gettrafficrate(rxtotal, (time_t)timespent, 0));
+ printf("\"minratestring\":\"%s\",", gettrafficrate(rxmin, LIVETIME, 0));
+ printf("\"totalbytes\":%" PRIu64 ",", rxtotal);
+ printf("\"maxbytes\":%" PRIu64 ",", rxmax);
+ printf("\"minbytes\":%" PRIu64 ",", rxmin);
+ printf("\"totalpackets\":%" PRIu64 ",", rxptotal);
+ printf("\"maxpackets\":%" PRIu64 ",", rxpmax);
+ printf("\"minpackets\":%" PRIu64 "", rxpmin);
+ printf("},");
+ printf("\"tx\":{");
+ printf("\"maxratestring\":\"%s\",", gettrafficrate(txmax, LIVETIME, 0));
+ printf("\"averageratestring\":\"%s\",", gettrafficrate(txtotal, (time_t)timespent, 0));
+ printf("\"minratestring\":\"%s\",", gettrafficrate(txmin, LIVETIME, 0));
+ printf("\"totalbytes\":%" PRIu64 ",", txtotal);
+ printf("\"maxbytes\":%" PRIu64 ",", txmax);
+ printf("\"minbytes\":%" PRIu64 ",", txmin);
+ printf("\"totalpackets\":%" PRIu64 ",", txptotal);
+ printf("\"maxpackets\":%" PRIu64 ",", txpmax);
+ printf("\"minpackets\":%" PRIu64 "", txpmin);
+ printf("}}\n");
}
}
#include "fs.h"
#include "vnstat.h"
-int main(int argc, char *argv[]) {
+int main(int argc, char *argv[])
+{
int currentarg;
DIR *dir = NULL;
/* early check for debug and config parameter */
if (argc > 1) {
- for (currentarg=1; currentarg<argc; currentarg++) {
- if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
+ for (currentarg = 1; currentarg < argc; currentarg++) {
+ if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
debug = 1;
printf("Debug enabled, vnstat %s\n", VERSION);
- } else if (strcmp(argv[currentarg],"--config")==0) {
- if (currentarg+1<argc) {
- strncpy_nt(p.cfgfile, argv[currentarg+1], 512);
+ } else if (strcmp(argv[currentarg], "--config") == 0) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(p.cfgfile, argv[currentarg + 1], 512);
if (debug)
printf("Used config file: %s\n", p.cfgfile);
currentarg++;
strncpy_nt(p.dirname, cfg.dbdir, 512);
/* parse parameters, maybe not the best way but... */
- for (currentarg=1; currentarg<argc; currentarg++) {
+ for (currentarg = 1; currentarg < argc; currentarg++) {
if (debug)
- printf("arg %d: \"%s\"\n",currentarg,argv[currentarg]);
- if (strcmp(argv[currentarg],"--longhelp")==0) {
+ printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]);
+ if (strcmp(argv[currentarg], "--longhelp") == 0) {
showlonghelp(&p);
return 0;
- } else if ((strcmp(argv[currentarg],"-?")==0) || (strcmp(argv[currentarg],"--help")==0)) {
+ } else if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help") == 0)) {
showhelp(&p);
return 0;
- } else if ((strcmp(argv[currentarg],"-i")==0) || (strcmp(argv[currentarg],"--iface")==0)) {
- if (currentarg+1<argc) {
- if (strlen(argv[currentarg+1]) > 31) {
+ } else if ((strcmp(argv[currentarg], "-i") == 0) || (strcmp(argv[currentarg], "--iface") == 0)) {
+ if (currentarg + 1 < argc) {
+ if (strlen(argv[currentarg + 1]) > 31) {
printf("Error: Interface name is limited to 31 characters.\n");
return 1;
}
- strncpy_nt(p.interface, argv[currentarg+1], 32);
+ strncpy_nt(p.interface, argv[currentarg + 1], 32);
p.defaultiface = 0;
if (debug)
printf("Used interface: %s\n", p.interface);
printf("Error: Interface for %s missing.\n", argv[currentarg]);
return 1;
}
- } else if (strcmp(argv[currentarg],"--config")==0) {
+ } else if (strcmp(argv[currentarg], "--config") == 0) {
/* config has already been parsed earlier so nothing to do here */
currentarg++;
continue;
- } else if (strcmp(argv[currentarg],"--setalias")==0 || strcmp(argv[currentarg],"--nick")==0) {
- if (currentarg+1<argc) {
- strncpy_nt(p.alias, argv[currentarg+1], 32);
+ } else if (strcmp(argv[currentarg], "--setalias") == 0 || strcmp(argv[currentarg], "--nick") == 0) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(p.alias, argv[currentarg + 1], 32);
if (debug)
printf("Used alias: %s\n", p.alias);
p.setalias = 1;
printf("Error: Alias for %s missing.\n", argv[currentarg]);
return 1;
}
- } else if ((strcmp(argv[currentarg],"--style"))==0) {
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ } else if ((strcmp(argv[currentarg], "--style")) == 0) {
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
if (cfg.ostyle > 4 || cfg.ostyle < 0) {
printf("Error: Invalid style parameter \"%d\" for --style.\n", cfg.ostyle);
printf(" Valid parameters:\n");
printf(" and show raw values in --oneline\n");
return 1;
}
- cfg.ostyle = atoi(argv[currentarg+1]);
+ cfg.ostyle = atoi(argv[currentarg + 1]);
if (debug)
printf("Style changed: %d\n", cfg.ostyle);
currentarg++;
printf(" and show raw values in --oneline\n");
return 1;
}
- } else if ((strcmp(argv[currentarg],"--dbdir"))==0) {
- if (currentarg+1<argc) {
- strncpy_nt(p.dirname, argv[currentarg+1], 512);
+ } else if ((strcmp(argv[currentarg], "--dbdir")) == 0) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(p.dirname, argv[currentarg + 1], 512);
if (debug)
printf("DatabaseDir: \"%s\"\n", p.dirname);
currentarg++;
printf("Error: Directory for %s missing.\n", argv[currentarg]);
return 1;
}
- } else if ((strcmp(argv[currentarg],"--locale"))==0) {
- if (currentarg+1<argc) {
- setlocale(LC_ALL, argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "--locale")) == 0) {
+ if (currentarg + 1 < argc) {
+ setlocale(LC_ALL, argv[currentarg + 1]);
if (debug)
- printf("Locale: \"%s\"\n", argv[currentarg+1]);
+ printf("Locale: \"%s\"\n", argv[currentarg + 1]);
currentarg++;
continue;
} else {
printf("Error: Locale for %s missing.\n", argv[currentarg]);
return 1;
}
- } else if (strcmp(argv[currentarg],"--add")==0) {
- p.addiface=1;
- p.query=0;
- } else if ((strcmp(argv[currentarg],"-u")==0) || (strcmp(argv[currentarg],"--update")==0)) {
+ } else if (strcmp(argv[currentarg], "--add") == 0) {
+ p.addiface = 1;
+ p.query = 0;
+ } else if ((strcmp(argv[currentarg], "-u") == 0) || (strcmp(argv[currentarg], "--update") == 0)) {
printf("Error: The \"%s\" parameter is not supported in this version.\n", argv[currentarg]);
return 1;
- } else if ((strcmp(argv[currentarg],"-q")==0) || (strcmp(argv[currentarg],"--query")==0)) {
- p.query=1;
- } else if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
- debug=1;
- } else if ((strcmp(argv[currentarg],"-d")==0) || (strcmp(argv[currentarg],"--days")==0)) {
- cfg.qmode=1;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listdays = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "-q") == 0) || (strcmp(argv[currentarg], "--query") == 0)) {
+ p.query = 1;
+ } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
+ debug = 1;
+ } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--days") == 0)) {
+ cfg.qmode = 1;
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listdays = atoi(argv[currentarg + 1]);
if (cfg.listdays < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-m")==0) || (strcmp(argv[currentarg],"--months")==0)) {
- cfg.qmode=2;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listmonths = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "-m") == 0) || (strcmp(argv[currentarg], "--months") == 0)) {
+ cfg.qmode = 2;
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listmonths = atoi(argv[currentarg + 1]);
if (cfg.listmonths < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-t")==0) || (strcmp(argv[currentarg],"--top")==0)) {
- cfg.qmode=3;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listtop = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "-t") == 0) || (strcmp(argv[currentarg], "--top") == 0)) {
+ cfg.qmode = 3;
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listtop = atoi(argv[currentarg + 1]);
if (cfg.listtop < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-s")==0) || (strcmp(argv[currentarg],"--short")==0)) {
- cfg.qmode=5;
- } else if ((strcmp(argv[currentarg],"-y")==0) || (strcmp(argv[currentarg],"--years")==0)) {
- cfg.qmode=6;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listyears = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--short") == 0)) {
+ cfg.qmode = 5;
+ } else if ((strcmp(argv[currentarg], "-y") == 0) || (strcmp(argv[currentarg], "--years") == 0)) {
+ cfg.qmode = 6;
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listyears = atoi(argv[currentarg + 1]);
if (cfg.listyears < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-hg")==0) || (strcmp(argv[currentarg],"--hoursgraph")==0)) {
- cfg.qmode=7;
- } else if ((strcmp(argv[currentarg],"-h")==0) || (strcmp(argv[currentarg],"--hours")==0)) {
- cfg.qmode=11;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listhours = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "-hg") == 0) || (strcmp(argv[currentarg], "--hoursgraph") == 0)) {
+ cfg.qmode = 7;
+ } else if ((strcmp(argv[currentarg], "-h") == 0) || (strcmp(argv[currentarg], "--hours") == 0)) {
+ cfg.qmode = 11;
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listhours = atoi(argv[currentarg + 1]);
if (cfg.listhours < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-5")==0) || (strcmp(argv[currentarg],"--fiveminutes")==0)) {
- cfg.qmode=12;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listfivemins = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "-5") == 0) || (strcmp(argv[currentarg], "--fiveminutes") == 0)) {
+ cfg.qmode = 12;
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listfivemins = atoi(argv[currentarg + 1]);
if (cfg.listfivemins < 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]);
return 1;
}
currentarg++;
}
- } else if (strcmp(argv[currentarg],"--oneline")==0) {
- cfg.qmode=9;
- if (currentarg+1<argc && argv[currentarg+1][0]!='-') {
- if (argv[currentarg+1][0]=='b') {
+ } else if (strcmp(argv[currentarg], "--oneline") == 0) {
+ cfg.qmode = 9;
+ if (currentarg + 1 < argc && argv[currentarg + 1][0] != '-') {
+ if (argv[currentarg + 1][0] == 'b') {
cfg.ostyle = 4;
currentarg++;
} else {
- printf("Error: Invalid mode parameter \"%s\" for --oneline.\n", argv[currentarg+1]);
+ printf("Error: Invalid mode parameter \"%s\" for --oneline.\n", argv[currentarg + 1]);
printf(" Valid parameters:\n");
printf(" (none) - automatically scaled units visible\n");
printf(" b - all values in bytes\n");
return 1;
}
}
- } else if (strcmp(argv[currentarg],"--xml")==0) {
- if (currentarg+1<argc && argv[currentarg+1][0]!='-' && !isdigit(argv[currentarg+1][0])) {
- p.xmlmode = argv[currentarg+1][0];
- if (strlen(argv[currentarg+1])!=1 || strchr("afhdmyt", p.xmlmode)==NULL) {
- printf("Error: Invalid mode parameter \"%s\" for --xml.\n", argv[currentarg+1]);
+ } else if (strcmp(argv[currentarg], "--xml") == 0) {
+ if (currentarg + 1 < argc && argv[currentarg + 1][0] != '-' && !isdigit(argv[currentarg + 1][0])) {
+ p.xmlmode = argv[currentarg + 1][0];
+ if (strlen(argv[currentarg + 1]) != 1 || strchr("afhdmyt", p.xmlmode) == NULL) {
+ printf("Error: Invalid mode parameter \"%s\" for --xml.\n", argv[currentarg + 1]);
printf(" Valid parameters:\n");
printf(" a - all (default)\n");
printf(" f - only 5 minutes\n");
}
currentarg++;
}
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listjsonxml = atoi(argv[currentarg+1]);
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listjsonxml = atoi(argv[currentarg + 1]);
if (cfg.listjsonxml < 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]);
return 1;
}
currentarg++;
}
- cfg.qmode=8;
- } else if (strcmp(argv[currentarg],"--json")==0) {
- if (currentarg+1<argc && argv[currentarg+1][0]!='-' && !isdigit(argv[currentarg+1][0])) {
- p.jsonmode = argv[currentarg+1][0];
- if (strlen(argv[currentarg+1])!=1 || strchr("afhdmyt", p.jsonmode)==NULL) {
- printf("Error: Invalid mode parameter \"%s\" for --json.\n", argv[currentarg+1]);
+ cfg.qmode = 8;
+ } else if (strcmp(argv[currentarg], "--json") == 0) {
+ if (currentarg + 1 < argc && argv[currentarg + 1][0] != '-' && !isdigit(argv[currentarg + 1][0])) {
+ p.jsonmode = argv[currentarg + 1][0];
+ if (strlen(argv[currentarg + 1]) != 1 || strchr("afhdmyt", p.jsonmode) == NULL) {
+ printf("Error: Invalid mode parameter \"%s\" for --json.\n", argv[currentarg + 1]);
printf(" Valid parameters:\n");
printf(" a - all (default)\n");
printf(" f - only 5 minutes\n");
}
currentarg++;
}
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listjsonxml = atoi(argv[currentarg+1]);
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listjsonxml = atoi(argv[currentarg + 1]);
if (cfg.listjsonxml < 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]);
return 1;
}
currentarg++;
}
- cfg.qmode=10;
- } else if ((strcmp(argv[currentarg],"-ru")==0) || (strcmp(argv[currentarg],"--rateunit"))==0) {
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.qmode = 10;
+ } else if ((strcmp(argv[currentarg], "-ru") == 0) || (strcmp(argv[currentarg], "--rateunit")) == 0) {
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
if (cfg.rateunit > 1 || cfg.rateunit < 0) {
printf("Error: Invalid parameter \"%d\" for --rateunit.\n", cfg.rateunit);
printf(" Valid parameters:\n");
printf(" 1 - bits\n");
return 1;
}
- cfg.rateunit = atoi(argv[currentarg+1]);
+ cfg.rateunit = atoi(argv[currentarg + 1]);
if (debug)
printf("Rateunit changed: %d\n", cfg.rateunit);
currentarg++;
if (debug)
printf("Rateunit changed: %d\n", cfg.rateunit);
}
- } else if ((strcmp(argv[currentarg],"-tr")==0) || (strcmp(argv[currentarg],"--traffic")==0)) {
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.sampletime=atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "-tr") == 0) || (strcmp(argv[currentarg], "--traffic") == 0)) {
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.sampletime = atoi(argv[currentarg + 1]);
currentarg++;
- p.traffic=1;
- p.query=0;
+ p.traffic = 1;
+ p.query = 0;
continue;
}
- p.traffic=1;
- p.query=0;
- } else if ((strcmp(argv[currentarg],"-l")==0) || (strcmp(argv[currentarg],"--live")==0)) {
- if (currentarg+1<argc && argv[currentarg+1][0]!='-') {
- if (!isdigit(argv[currentarg+1][0]) || p.livemode > 1 || p.livemode < 0) {
- printf("Error: Invalid mode parameter \"%s\" for -l / --live.\n", argv[currentarg+1]);
+ p.traffic = 1;
+ p.query = 0;
+ } else if ((strcmp(argv[currentarg], "-l") == 0) || (strcmp(argv[currentarg], "--live") == 0)) {
+ if (currentarg + 1 < argc && argv[currentarg + 1][0] != '-') {
+ if (!isdigit(argv[currentarg + 1][0]) || p.livemode > 1 || p.livemode < 0) {
+ printf("Error: Invalid mode parameter \"%s\" for -l / --live.\n", argv[currentarg + 1]);
printf(" Valid parameters:\n");
printf(" 0 - show packets per second (default)\n");
printf(" 1 - show transfer counters\n");
return 1;
}
- p.livemode = atoi(argv[currentarg+1]);
+ p.livemode = atoi(argv[currentarg + 1]);
currentarg++;
}
- p.livetraffic=1;
- p.query=0;
- } else if (strcmp(argv[currentarg],"--force")==0) {
- p.force=1;
- } else if (strcmp(argv[currentarg],"--showconfig")==0) {
+ p.livetraffic = 1;
+ p.query = 0;
+ } else if (strcmp(argv[currentarg], "--force") == 0) {
+ p.force = 1;
+ } else if (strcmp(argv[currentarg], "--showconfig") == 0) {
printcfgfile();
return 0;
- } else if (strcmp(argv[currentarg],"--remove")==0) {
- p.removeiface=1;
- p.query=0;
- } else if ((strcmp(argv[currentarg],"-b")==0) || (strcmp(argv[currentarg],"--begin")==0)) {
- if (currentarg+1<argc) {
- if (!validatedatetime(argv[currentarg+1])) {
+ } else if (strcmp(argv[currentarg], "--remove") == 0) {
+ p.removeiface = 1;
+ p.query = 0;
+ } else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[currentarg], "--begin") == 0)) {
+ if (currentarg + 1 < argc) {
+ if (!validatedatetime(argv[currentarg + 1])) {
printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
return 1;
}
- strncpy_nt(p.databegin, argv[currentarg+1], 18);
+ strncpy_nt(p.databegin, argv[currentarg + 1], 18);
currentarg++;
} else {
printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]);
return 1;
}
- } else if ((strcmp(argv[currentarg],"-e")==0) || (strcmp(argv[currentarg],"--end")==0)) {
- if (currentarg+1<argc) {
- if (!validatedatetime(argv[currentarg+1])) {
+ } else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[currentarg], "--end") == 0)) {
+ if (currentarg + 1 < argc) {
+ if (!validatedatetime(argv[currentarg + 1])) {
printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
return 1;
}
- strncpy_nt(p.dataend, argv[currentarg+1], 18);
+ strncpy_nt(p.dataend, argv[currentarg + 1], 18);
currentarg++;
} else {
printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]);
return 1;
}
- } else if (strcmp(argv[currentarg],"--iflist")==0) {
+ } else if (strcmp(argv[currentarg], "--iflist") == 0) {
getiflist(&p.ifacelist, 1);
printf("Available interfaces: %s\n", p.ifacelist);
free(p.ifacelist);
return 0;
- } 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());
return 0;
} else {
- printf("Unknown parameter \"%s\". Use --help for help.\n",argv[currentarg]);
+ printf("Unknown parameter \"%s\". Use --help for help.\n", argv[currentarg]);
return 1;
}
-
}
/* open database and see if it contains any interfaces */
if (!p.traffic && !p.livetraffic) {
- if ((dir=opendir(p.dirname))!=NULL) {
+ if ((dir = opendir(p.dirname)) != NULL) {
if (debug)
printf("Dir OK\n");
closedir(dir);
}
p.ifcount = db_getinterfacecount();
if (debug)
- printf("%"PRIu64" interface(s) found\n", p.ifcount);
+ printf("%" PRIu64 " interface(s) found\n", p.ifcount);
if (p.ifcount > 1) {
strncpy_nt(p.definterface, cfg.iface, 32);
}
} else {
printf("Error: Unable to open database directory \"%s\": %s\n", p.dirname, strerror(errno));
- if (errno==ENOENT) {
+ if (errno == ENOENT) {
printf("The vnStat daemon should have created this directory when started.\n");
printf("Check that it is configured and running. See also \"man vnstatd\".\n");
} else {
}
}
}
- p.interface[31]='\0';
+ p.interface[31] = '\0';
/* parameter handlers */
handleremoveinterface(&p);
void initparams(PARAMS *p)
{
- noexit = 0; /* allow functions to exit in case of error */
- debug = 0; /* debug disabled by default */
+ noexit = 0; /* allow functions to exit in case of error */
+ debug = 0; /* debug disabled by default */
disableprints = 0; /* let prints be visible */
p->addiface = 0;
}
/* show all interfaces if -i isn't specified */
- if (p->ifcount==0) {
+ if (p->ifcount == 0) {
/* printf("No database found.\n"); */
- p->query=0;
- } else if ((cfg.qmode==0 || cfg.qmode==8 || cfg.qmode==10) && (p->ifcount>1)) {
+ p->query = 0;
+ } else if ((cfg.qmode == 0 || cfg.qmode == 8 || cfg.qmode == 10) && (p->ifcount > 1)) {
- if (cfg.qmode==0) {
- if (cfg.ostyle!=0) {
+ if (cfg.qmode == 0) {
+ if (cfg.ostyle != 0) {
printf("\n rx / tx / total / estimated\n");
} else {
printf("\n rx / tx / total\n");
}
- } else if (cfg.qmode==8) {
+ } else if (cfg.qmode == 8) {
xmlheader();
- } else if (cfg.qmode==10) {
+ } else if (cfg.qmode == 10) {
jsonheader();
}
strncpy_nt(p->interface, dbifl_i->interface, 32);
if (debug)
printf("\nProcessing interface \"%s\"...\n", p->interface);
- if (cfg.qmode==0) {
+ if (cfg.qmode == 0) {
showdb(p->interface, 5, "", "");
- } else if (cfg.qmode==8) {
+ } else if (cfg.qmode == 8) {
showxml(p->interface, p->xmlmode, p->databegin, p->dataend);
- } else if (cfg.qmode==10) {
+ } else if (cfg.qmode == 10) {
showjson(p->interface, ifcount, p->jsonmode, p->databegin, p->dataend);
}
ifcount++;
}
dbiflistfree(&dbifl);
- if (cfg.qmode==8) {
+ if (cfg.qmode == 8) {
xmlfooter();
- } else if (cfg.qmode==10) {
+ } else if (cfg.qmode == 10) {
jsonfooter();
}
- /* show in qmode if there's only one file or qmode!=0 */
+ /* show in qmode if there's only one file or qmode!=0 */
} else {
showoneinterface(p, p->interface);
}
void showoneinterface(PARAMS *p, const char *interface)
{
if (!db_getinterfacecountbyname(p->interface)) {
- if (strchr(p->interface, '+') == NULL) {
+ 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 database or given interfaces aren't unique.\n");
exit(EXIT_FAILURE);
}
- if (cfg.qmode==5) {
- if (cfg.ostyle!=0) {
+ if (cfg.qmode == 5) {
+ if (cfg.ostyle != 0) {
printf("\n rx / tx / total / estimated\n");
} else {
printf("\n rx / tx / total\n");
}
}
- if (cfg.qmode!=8 && cfg.qmode!=10) {
+ if (cfg.qmode != 8 && cfg.qmode != 10) {
showdb(interface, cfg.qmode, p->databegin, p->dataend);
- } else if (cfg.qmode==8) {
+ } else if (cfg.qmode == 8) {
xmlheader();
showxml(p->interface, p->xmlmode, p->databegin, p->dataend);
xmlfooter();
- } else if (cfg.qmode==10) {
+ } else if (cfg.qmode == 10) {
jsonheader();
showjson(p->interface, 0, p->jsonmode, p->databegin, p->dataend);
jsonfooter();
/* early check for debug and config parameter */
if (argc > 1) {
- for (currentarg=1; currentarg<argc; currentarg++) {
- if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
+ for (currentarg = 1; currentarg < argc; currentarg++) {
+ if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
debug = 1;
printf("Debug enabled, vnstatd %s\n", VERSION);
- } else if (strcmp(argv[currentarg],"--config")==0) {
- if (currentarg+1<argc) {
- strncpy_nt(s.cfgfile, argv[currentarg+1], 512);
+ } else if (strcmp(argv[currentarg], "--config") == 0) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(s.cfgfile, argv[currentarg + 1], 512);
if (debug)
printf("Used config file: %s\n", s.cfgfile);
currentarg++;
strncpy_nt(s.user, cfg.daemonuser, 33);
strncpy_nt(s.group, cfg.daemongroup, 33);
s.updateinterval = cfg.updateinterval;
- s.saveinterval = cfg.saveinterval*60;
+ s.saveinterval = cfg.saveinterval * 60;
/* parse parameters, maybe not the best way but... */
- for (currentarg=1; currentarg<argc; currentarg++) {
+ for (currentarg = 1; currentarg < argc; currentarg++) {
if (debug)
- printf("arg %d: \"%s\"\n",currentarg,argv[currentarg]);
- if ((strcmp(argv[currentarg],"-?")==0) || (strcmp(argv[currentarg],"--help")==0)) {
+ printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]);
+ if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help") == 0)) {
break;
- } else if (strcmp(argv[currentarg],"--config")==0) {
+ } else if (strcmp(argv[currentarg], "--config") == 0) {
/* config has already been parsed earlier so nothing to do here */
currentarg++;
continue;
- } else if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
+ } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
debug = 1;
- } else if ((strcmp(argv[currentarg],"-d")==0) || (strcmp(argv[currentarg],"--daemon")==0)) {
+ } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--daemon") == 0)) {
s.rundaemon = 1;
s.showhelp = 0;
- } else if ((strcmp(argv[currentarg],"-n")==0) || (strcmp(argv[currentarg],"--nodaemon")==0)) {
+ } else if ((strcmp(argv[currentarg], "-n") == 0) || (strcmp(argv[currentarg], "--nodaemon") == 0)) {
s.showhelp = 0;
- } else if ((strcmp(argv[currentarg],"-s")==0) || (strcmp(argv[currentarg],"--sync")==0)) {
+ } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--sync") == 0)) {
s.sync = 1;
- } else if ((strcmp(argv[currentarg],"-u")==0) || (strcmp(argv[currentarg],"--user")==0)) {
- if (currentarg+1<argc) {
- strncpy_nt(s.user, argv[currentarg+1], 33);
+ } else if ((strcmp(argv[currentarg], "-u") == 0) || (strcmp(argv[currentarg], "--user") == 0)) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(s.user, argv[currentarg + 1], 33);
if (debug)
printf("Requested user: \"%s\"\n", s.user);
currentarg++;
printf("Error: User for --user missing.\n");
return 1;
}
- } else if ((strcmp(argv[currentarg],"-g")==0) || (strcmp(argv[currentarg],"--group")==0)) {
- if (currentarg+1<argc) {
- strncpy_nt(s.group, argv[currentarg+1], 33);
+ } else if ((strcmp(argv[currentarg], "-g") == 0) || (strcmp(argv[currentarg], "--group") == 0)) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(s.group, argv[currentarg + 1], 33);
if (debug)
printf("Requested group: \"%s\"\n", s.group);
currentarg++;
printf("Error: Group for --group missing.\n");
return 1;
}
- } else if (strcmp(argv[currentarg],"--noadd")==0) {
+ } else if (strcmp(argv[currentarg], "--noadd") == 0) {
s.noadd = 1;
- } else if (strcmp(argv[currentarg],"--alwaysadd")==0) {
+ } else if (strcmp(argv[currentarg], "--alwaysadd") == 0) {
s.alwaysadd = 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 daemon %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
return 0;
- } else if ((strcmp(argv[currentarg],"-p")==0) || (strcmp(argv[currentarg],"--pidfile")==0)) {
- if (currentarg+1<argc) {
- strncpy_nt(cfg.pidfile, argv[currentarg+1], 512);
+ } else if ((strcmp(argv[currentarg], "-p") == 0) || (strcmp(argv[currentarg], "--pidfile") == 0)) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(cfg.pidfile, argv[currentarg + 1], 512);
cfg.pidfile[511] = '\0';
if (debug)
printf("Used pid file: %s\n", cfg.pidfile);
return 1;
}
} else {
- printf("Unknown arg \"%s\". Use --help for help.\n",argv[currentarg]);
+ printf("Unknown arg \"%s\". Use --help for help.\n", argv[currentarg]);
return 1;
}
}
s.running = 1;
#if defined(__linux__)
- #if HAVE_DECL_IFLA_STATS64
+#if HAVE_DECL_IFLA_STATS64
snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid:%d 64-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid());
- #else
+#else
snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid:%d 32-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid());
- #endif
+#endif
#else
snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid:%d)", getversion(), (int)getpid(), (int)getuid(), (int)getgid());
#endif
if (s.dbifcount == 0) {
filldatabaselist(&s);
- /* update data cache */
+ /* update data cache */
} else {
s.prevdbupdate = s.current - (s.current % s.updateinterval);
/* early check for debug and config parameter */
if (argc > 1) {
- for (currentarg=1; currentarg<argc; currentarg++) {
- if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
+ for (currentarg = 1; currentarg < argc; currentarg++) {
+ if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) {
debug = 1;
printf("Debug enabled, vnstati %s\n", VERSION);
- } else if (strcmp(argv[currentarg],"--config")==0) {
- if (currentarg+1<argc) {
- strncpy_nt(p.cfgfile, argv[currentarg+1], 512);
+ } else if (strcmp(argv[currentarg], "--config") == 0) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(p.cfgfile, argv[currentarg + 1], 512);
if (debug)
printf("Used config file: %s\n", p.cfgfile);
currentarg++;
ic.current = time(NULL);
/* parse parameters */
- for (currentarg=1; currentarg<argc; currentarg++) {
+ for (currentarg = 1; currentarg < argc; currentarg++) {
if (debug)
- printf("arg %d: \"%s\"\n",currentarg,argv[currentarg]);
- if ((strcmp(argv[currentarg],"-?")==0) || (strcmp(argv[currentarg],"--help"))==0) {
+ printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]);
+ if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help")) == 0) {
p.help = 1;
- } else if ((strcmp(argv[currentarg],"-i")==0) || (strcmp(argv[currentarg],"--iface"))==0) {
- if (currentarg+1<argc) {
- if (strlen(argv[currentarg+1]) > 31) {
+ } else if ((strcmp(argv[currentarg], "-i") == 0) || (strcmp(argv[currentarg], "--iface")) == 0) {
+ if (currentarg + 1 < argc) {
+ if (strlen(argv[currentarg + 1]) > 31) {
printf("Error: Interface name is limited to 31 characters.\n");
return 1;
}
- strncpy_nt(p.interface, argv[currentarg+1], 32);
+ strncpy_nt(p.interface, argv[currentarg + 1], 32);
if (debug)
printf("Used interface: \"%s\"\n", p.interface);
currentarg++;
printf("Error: Interface for -i missing.\n");
return 1;
}
- } else if ((strcmp(argv[currentarg],"-o")==0) || (strcmp(argv[currentarg],"--output"))==0) {
- if (currentarg+1<argc) {
- strncpy_nt(p.filename, argv[currentarg+1], 512);
+ } else if ((strcmp(argv[currentarg], "-o") == 0) || (strcmp(argv[currentarg], "--output")) == 0) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(p.filename, argv[currentarg + 1], 512);
if (debug)
printf("Output file: \"%s\"\n", p.filename);
currentarg++;
printf("Error: Filename for -o missing.\n");
return 1;
}
- } else if ((strcmp(argv[currentarg],"-c")==0) || (strcmp(argv[currentarg],"--cache"))==0) {
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- p.cache = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "-c") == 0) || (strcmp(argv[currentarg], "--cache")) == 0) {
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ p.cache = atoi(argv[currentarg + 1]);
if (debug)
printf("Cache time: %d minutes\n", p.cache);
currentarg++;
printf("Error: Parameter for -c missing or invalid.\n");
return 1;
}
- } else if ((strcmp(argv[currentarg],"--style"))==0) {
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.ostyle = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "--style")) == 0) {
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.ostyle = atoi(argv[currentarg + 1]);
if (cfg.ostyle > 3 || cfg.ostyle < 0) {
printf("Error: Invalid style parameter \"%d\" for --style.\n", cfg.ostyle);
return 1;
printf("Error: Style parameter for --style missing.\n");
return 1;
}
- } else if ((strcmp(argv[currentarg],"--transparent"))==0) {
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.transbg = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "--transparent")) == 0) {
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.transbg = atoi(argv[currentarg + 1]);
if (cfg.transbg > 1 || cfg.transbg < 0) {
printf("Error: Invalid parameter \"%d\" for --transparent.\n", cfg.transbg);
return 1;
if (debug)
printf("Transparency changed: %d\n", cfg.transbg);
}
- } else if ((strcmp(argv[currentarg],"--dbdir"))==0) {
- if (currentarg+1<argc) {
- strncpy_nt(cfg.dbdir, argv[currentarg+1], 512);
+ } else if ((strcmp(argv[currentarg], "--dbdir")) == 0) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(cfg.dbdir, argv[currentarg + 1], 512);
if (debug)
printf("DatabaseDir: \"%s\"\n", cfg.dbdir);
currentarg++;
printf("Error: Directory for --dbdir missing.\n");
return 1;
}
- } else if ((strcmp(argv[currentarg],"--locale"))==0) {
- if (currentarg+1<argc) {
- setlocale(LC_ALL, argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "--locale")) == 0) {
+ if (currentarg + 1 < argc) {
+ setlocale(LC_ALL, argv[currentarg + 1]);
if (debug)
- printf("Locale: \"%s\"\n", argv[currentarg+1]);
+ printf("Locale: \"%s\"\n", argv[currentarg + 1]);
currentarg++;
continue;
} else {
printf("Error: Locale for --locale missing.\n");
return 1;
}
- } else if (strcmp(argv[currentarg],"--config")==0) {
+ } else if (strcmp(argv[currentarg], "--config") == 0) {
/* config has already been parsed earlier so nothing to do here */
currentarg++;
continue;
- } else if ((strcmp(argv[currentarg],"--headertext"))==0) {
- if (currentarg+1<argc) {
- strncpy_nt(ic.headertext, argv[currentarg+1], 65);
+ } else if ((strcmp(argv[currentarg], "--headertext")) == 0) {
+ if (currentarg + 1 < argc) {
+ strncpy_nt(ic.headertext, argv[currentarg + 1], 65);
if (debug)
printf("Header text: \"%s\"\n", ic.headertext);
currentarg++;
printf("Error: Text string parameter for --headertext missing.\n");
return 1;
}
- } else if (strcmp(argv[currentarg],"--altdate")==0) {
+ } else if (strcmp(argv[currentarg], "--altdate") == 0) {
ic.altdate = 1;
- } else if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug"))==0) {
+ } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug")) == 0) {
debug = 1;
- } else if ((strcmp(argv[currentarg],"-d")==0) || (strcmp(argv[currentarg],"--days"))==0) {
+ } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--days")) == 0) {
cfg.qmode = 1;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listdays = atoi(argv[currentarg+1]);
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listdays = atoi(argv[currentarg + 1]);
if (cfg.listdays < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-m")==0) || (strcmp(argv[currentarg],"--months"))==0) {
+ } else if ((strcmp(argv[currentarg], "-m") == 0) || (strcmp(argv[currentarg], "--months")) == 0) {
cfg.qmode = 2;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listmonths = atoi(argv[currentarg+1]);
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listmonths = atoi(argv[currentarg + 1]);
if (cfg.listmonths < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-t")==0) || (strcmp(argv[currentarg],"--top"))==0) {
+ } else if ((strcmp(argv[currentarg], "-t") == 0) || (strcmp(argv[currentarg], "--top")) == 0) {
cfg.qmode = 3;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listtop = atoi(argv[currentarg+1]);
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listtop = atoi(argv[currentarg + 1]);
if (cfg.listtop < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-y")==0) || (strcmp(argv[currentarg],"--years"))==0) {
+ } else if ((strcmp(argv[currentarg], "-y") == 0) || (strcmp(argv[currentarg], "--years")) == 0) {
cfg.qmode = 4;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listyears = atoi(argv[currentarg+1]);
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listyears = atoi(argv[currentarg + 1]);
if (cfg.listyears < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-h")==0) || (strcmp(argv[currentarg],"--hours"))==0) {
+ } else if ((strcmp(argv[currentarg], "-h") == 0) || (strcmp(argv[currentarg], "--hours")) == 0) {
cfg.qmode = 8;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listhours = atoi(argv[currentarg+1]);
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listhours = atoi(argv[currentarg + 1]);
if (cfg.listhours < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-5")==0) || (strcmp(argv[currentarg],"--fiveminutes"))==0) {
+ } else if ((strcmp(argv[currentarg], "-5") == 0) || (strcmp(argv[currentarg], "--fiveminutes")) == 0) {
cfg.qmode = 9;
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.listfivemins = atoi(argv[currentarg+1]);
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.listfivemins = atoi(argv[currentarg + 1]);
if (cfg.listfivemins < 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]);
return 1;
}
currentarg++;
}
- } else if ((strcmp(argv[currentarg],"-s")==0) || (strcmp(argv[currentarg],"--summary"))==0) {
+ } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--summary")) == 0) {
cfg.qmode = 5;
- } else if ((strcmp(argv[currentarg],"-hg")==0) || (strcmp(argv[currentarg],"--hoursgraph"))==0) {
+ } else if ((strcmp(argv[currentarg], "-hg") == 0) || (strcmp(argv[currentarg], "--hoursgraph")) == 0) {
cfg.qmode = 7;
- } else if ((strcmp(argv[currentarg],"-hs")==0) || (strcmp(argv[currentarg],"--hsummary"))==0) {
+ } else if ((strcmp(argv[currentarg], "-hs") == 0) || (strcmp(argv[currentarg], "--hsummary")) == 0) {
cfg.qmode = 51;
- } else if ((strcmp(argv[currentarg],"-vs")==0) || (strcmp(argv[currentarg],"--vsummary"))==0) {
+ } else if ((strcmp(argv[currentarg], "-vs") == 0) || (strcmp(argv[currentarg], "--vsummary")) == 0) {
cfg.qmode = 52;
- } else if ((strcmp(argv[currentarg],"-nh")==0) || (strcmp(argv[currentarg],"--noheader"))==0) {
+ } else if ((strcmp(argv[currentarg], "-nh") == 0) || (strcmp(argv[currentarg], "--noheader")) == 0) {
ic.showheader = 0;
- } else if ((strcmp(argv[currentarg],"-ne")==0) || (strcmp(argv[currentarg],"--noedge"))==0) {
+ } else if ((strcmp(argv[currentarg], "-ne") == 0) || (strcmp(argv[currentarg], "--noedge")) == 0) {
ic.showedge = 0;
- } else if ((strcmp(argv[currentarg],"-nl")==0) || (strcmp(argv[currentarg],"--nolegend"))==0) {
+ } else if ((strcmp(argv[currentarg], "-nl") == 0) || (strcmp(argv[currentarg], "--nolegend")) == 0) {
ic.showlegend = 0;
- } else if ((strcmp(argv[currentarg],"-ru")==0) || (strcmp(argv[currentarg],"--rateunit"))==0) {
- if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
- cfg.rateunit = atoi(argv[currentarg+1]);
+ } else if ((strcmp(argv[currentarg], "-ru") == 0) || (strcmp(argv[currentarg], "--rateunit")) == 0) {
+ if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) {
+ cfg.rateunit = atoi(argv[currentarg + 1]);
if (cfg.rateunit > 1 || cfg.rateunit < 0) {
printf("Error: Invalid parameter \"%d\" for --rateunit.\n", cfg.rateunit);
printf(" Valid parameters:\n");
if (debug)
printf("Rateunit changed: %d\n", cfg.rateunit);
}
- } else if ((strcmp(argv[currentarg],"-b")==0) || (strcmp(argv[currentarg],"--begin")==0)) {
- if (currentarg+1<argc) {
- if (!validatedatetime(argv[currentarg+1])) {
+ } else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[currentarg], "--begin") == 0)) {
+ if (currentarg + 1 < argc) {
+ if (!validatedatetime(argv[currentarg + 1])) {
printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
return 1;
}
- strncpy_nt(ic.databegin, argv[currentarg+1], 18);
+ strncpy_nt(ic.databegin, argv[currentarg + 1], 18);
currentarg++;
} else {
printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]);
return 1;
}
- } else if ((strcmp(argv[currentarg],"-e")==0) || (strcmp(argv[currentarg],"--end")==0)) {
- if (currentarg+1<argc) {
- if (!validatedatetime(argv[currentarg+1])) {
+ } else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[currentarg], "--end") == 0)) {
+ if (currentarg + 1 < argc) {
+ if (!validatedatetime(argv[currentarg + 1])) {
printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n");
return 1;
}
- strncpy_nt(ic.dataend, argv[currentarg+1], 18);
+ strncpy_nt(ic.dataend, argv[currentarg + 1], 18);
currentarg++;
} else {
printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]);
return 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 image output %s by Teemu Toivola <tst at iki dot fi>\n", getversion());
return 0;
} else {
- printf("Unknown arg \"%s\". Use --help for help.\n",argv[currentarg]);
+ printf("Unknown arg \"%s\". Use --help for help.\n", argv[currentarg]);
return 1;
}
}
void initiparams(IPARAMS *p)
{
- noexit = 0; /* allow functions to exit in case of error */
- debug = 0; /* debug disabled by default */
+ noexit = 0; /* allow functions to exit in case of error */
+ debug = 0; /* debug disabled by default */
disableprints = 0; /* let prints be visible */
p->interface[0] = '\0';
p->filename[0] = '\0';
{
struct stat filestat;
- if (p->cache==0 || p->filename[0]=='-') {
+ if (p->cache == 0 || p->filename[0] == '-') {
return;
}
- if (stat(p->filename, &filestat)==0) {
- if ((ic->current-filestat.st_mtime)<(p->cache*60)) {
+ if (stat(p->filename, &filestat) == 0) {
+ if ((ic->current - filestat.st_mtime) < (p->cache * 60)) {
if (debug)
- printf("Using cached file (%d<%d).\n", (int)(ic->current-filestat.st_mtime), p->cache*60);
+ printf("Using cached file (%d<%d).\n", (int)(ic->current - filestat.st_mtime), p->cache * 60);
exit(EXIT_SUCCESS);
}
} else {
/* abort if error is something else than file not found */
- if (errno!=ENOENT) {
+ if (errno != ENOENT) {
printf("Error: Getting status for file \"%s\" failed: %s (%d)\n", p->filename, strerror(errno), errno);
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
if (!db_getinterfacecountbyname(p->interface)) {
- if (strchr(p->interface, '+') == NULL) {
+ 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 database or given interfaces aren't unique.\n");
void openoutput(IPARAMS *p)
{
- if (p->filename[0]!='-') {
- if ((p->pngout = fopen(p->filename, "w"))==NULL) {
+ if (p->filename[0] != '-') {
+ if ((p->pngout = fopen(p->filename, "w")) == NULL) {
printf("Error: Opening file \"%s\" for output failed: %s\n", p->filename, strerror(errno));
exit(EXIT_FAILURE);
}
} else {
/* output to stdout */
- if ((p->pngout = fdopen(1, "w"))==NULL) {
+ if ((p->pngout = fdopen(1, "w")) == NULL) {
printf("Error: Opening stdout for output failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
END_TEST
#if defined(__clang__)
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wused-but-marked-unused"
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wused-but-marked-unused"
#endif
START_TEST(dmonth_return_within_range)
{
}
END_TEST
#if defined(__clang__)
- #pragma clang diagnostic pop
+#pragma clang diagnostic pop
#endif
START_TEST(leapyears_are_known)
a = 1;
b = 0;
- ck_assert(countercalc(&a, &b, 0)==(MAX32-1));
- ck_assert(countercalc(&a, &b, -1)==(MAX32-1));
+ ck_assert(countercalc(&a, &b, 0) == (MAX32 - 1));
+ ck_assert(countercalc(&a, &b, -1) == (MAX32 - 1));
}
END_TEST
a = 1;
b = 0;
- ck_assert(countercalc(&a, &b, 1)==(MAX64-1));
+ ck_assert(countercalc(&a, &b, 1) == (MAX64 - 1));
}
END_TEST
{
uint64_t a, b;
- a = MAX32+1;
+ a = MAX32 + 1;
b = 0;
- ck_assert(countercalc(&a, &b, 1)==(MAX64-MAX32-1));
+ ck_assert(countercalc(&a, &b, 1) == (MAX64 - MAX32 - 1));
}
END_TEST
{
uint64_t a, b;
- a = MAX32-1;
+ a = MAX32 - 1;
b = 0;
- ck_assert(countercalc(&a, &b, 0)==1);
- ck_assert(countercalc(&a, &b, -1)==1);
+ ck_assert(countercalc(&a, &b, 0) == 1);
+ ck_assert(countercalc(&a, &b, -1) == 1);
}
END_TEST
{
uint64_t a, b;
- a = MAX32+1;
+ a = MAX32 + 1;
b = 0;
- ck_assert(countercalc(&a, &b, 0)==(MAX64-MAX32-1));
- ck_assert(countercalc(&a, &b, -1)==(MAX64-MAX32-1));
+ ck_assert(countercalc(&a, &b, 0) == (MAX64 - MAX32 - 1));
+ ck_assert(countercalc(&a, &b, -1) == (MAX64 - MAX32 - 1));
}
END_TEST
{
uint64_t a, b;
- a = MAX32-1;
+ a = MAX32 - 1;
b = 0;
- ck_assert(countercalc(&a, &b, 1)==(MAX64-MAX32+1));
+ ck_assert(countercalc(&a, &b, 1) == (MAX64 - MAX32 + 1));
}
END_TEST
{
uint64_t a, b;
- a = MAX64-1;
+ a = MAX64 - 1;
b = 0;
- ck_assert(countercalc(&a, &b, 1)==1);
+ ck_assert(countercalc(&a, &b, 1) == 1);
}
END_TEST
int ret;
uint32_t limit;
cfg.maxbw = 10;
- ret = ibwget("does_not_exist", &limit);
+ ret = ibwget("does_not_exist", &limit);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(limit, 10);
}
ck_assert_int_eq(loadcfg(CFGFILE), 1);
ck_assert_int_eq(ibwloadcfg(CFGFILE), 1);
cfg.maxbw = 10;
- ret = ibwget("ethnone", &limit);
+ ret = ibwget("ethnone", &limit);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(limit, 8);
}
{
int ret;
char target[32];
- struct cfgsetting cset[] = {{ "unused", target, 0, 32, 0 }};
+ struct cfgsetting cset[] = {{"unused", target, 0, 32, 0}};
ret = setcfgvalue(&cset[0], "one", "unused");
ck_assert_int_eq(ret, 1);
START_TEST(setcfgvalue_can_set_ints)
{
int ret, target;
- struct cfgsetting cset[] = {{ "unused", 0, &target, 0, 0 }};
+ struct cfgsetting cset[] = {{"unused", 0, &target, 0, 0}};
ret = setcfgvalue(&cset[0], "1", "unused");
ck_assert_int_eq(ret, 1);
{
int ret;
char target[10];
- struct cfgsetting cset[] = {{ "unused", target, 0, 5, 0 }};
+ struct cfgsetting cset[] = {{"unused", target, 0, 5, 0}};
ret = setcfgvalue(&cset[0], "one", "unused");
ck_assert_int_eq(ret, 1);
START_TEST(setcfgvalue_can_do_nothing)
{
int ret;
- struct cfgsetting cset[] = {{ "unused", 0, 0, 0, 0 }};
+ struct cfgsetting cset[] = {{"unused", 0, 0, 0, 0}};
ret = setcfgvalue(&cset[0], "nothing", "unused");
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(s.dbretrycount, 1);
- for (i=1; i<DBRETRYLIMIT-1; i++) {
+ for (i = 1; i < DBRETRYLIMIT - 1; i++) {
handledatabaseerror(&s);
}
- ck_assert_int_eq(s.dbretrycount, DBRETRYLIMIT-1);
+ ck_assert_int_eq(s.dbretrycount, DBRETRYLIMIT - 1);
}
END_TEST
ck_assert_int_eq(s.dbretrycount, 1);
- for (i=1; i<DBRETRYLIMIT; i++) {
+ for (i = 1; i < DBRETRYLIMIT; i++) {
handledatabaseerror(&s);
}
}
disable_logprints();
dcache = NULL;
- for (i=0; i<100; i++) {
+ for (i = 0; i < 100; i++) {
snprintf(buffer, 8, "eth%d", i);
ret = datacache_add(&dcache, buffer, 0);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("something");
ck_assert_int_eq(ret, 1);
- for (i=1; i<100; i++) {
- ret = db_addtraffic_dated("something", (uint64_t)i*1234, (uint64_t)i*2345, (uint64_t)i*85000);
+ for (i = 1; i < 100; i++) {
+ ret = db_addtraffic_dated("something", (uint64_t)i * 1234, (uint64_t)i * 2345, (uint64_t)i * 85000);
ck_assert_int_eq(ret, 1);
}
suppress_output();
- for (i=0; i<=4; i++) {
+ for (i = 0; i <= 4; i++) {
cfg.ostyle = i;
showdb("something", 0, "", "");
showdb("something", 1, "", "");
suppress_output();
- for (i=0; i<=4; i++) {
+ for (i = 0; i <= 4; i++) {
cfg.ostyle = i;
showdb("something", 0, "", "");
showdb("something", 1, "", "");
suppress_output();
- for (i=0; i<=4; i++) {
+ for (i = 0; i <= 4; i++) {
cfg.ostyle = i;
showdb("something", 0, "", "");
showdb("something", 1, "", "");
suppress_output();
- for (i=0; i<=4; i++) {
+ for (i = 0; i <= 4; i++) {
cfg.ostyle = i;
showdb("something", 0, "", "");
showdb("something", 1, "", "");
data.totaltxk = 2;
data.currx = 456;
data.curtx = 654;
- for (i=0; i<24; i++) {
+ for (i = 0; i < 24; i++) {
data.hour[i].date = 788911200 + 3600 * i;
- data.hour[i].rx = (uint64_t)(12 * (i+1));
- data.hour[i].tx = (uint64_t)(23 * (i+1));
+ data.hour[i].rx = (uint64_t)(12 * (i + 1));
+ data.hour[i].tx = (uint64_t)(23 * (i + 1));
}
- for (i=0; i<30; i++) {
- data.day[i].date = 788911200 + 86400 * (29-i);
+ for (i = 0; i < 30; i++) {
+ data.day[i].date = 788911200 + 86400 * (29 - i);
data.day[i].used = 1;
data.day[i].rx = (uint64_t)(34 * i);
data.day[i].tx = (uint64_t)(45 * i);
}
- for (i=0; i<12; i++) {
- data.month[i].month = 788911200 + 2678400 * (11-i);
+ for (i = 0; i < 12; i++) {
+ data.month[i].month = 788911200 + 2678400 * (11 - i);
data.month[i].used = 1;
data.month[i].rx = (uint64_t)(56 * i);
data.month[i].tx = (uint64_t)(67 * i);
}
- for (i=0; i<10; i++) {
+ for (i = 0; i < 10; i++) {
data.top10[i].date = 788911200 + 86400 * i;
data.top10[i].used = 1;
- data.top10[i].rx = (uint64_t)(89 * (9-i+1));
- data.top10[i].tx = (uint64_t)(90 * (9-i+1));
+ data.top10[i].rx = (uint64_t)(89 * (9 - i + 1));
+ data.top10[i].tx = (uint64_t)(90 * (9 - i + 1));
}
ck_assert_int_eq(clean_testdbdir(), 1);
ck_assert_str_eq(info.alias, data.nick);
ck_assert_int_eq(info.active, data.active);
- ck_assert_int_eq(info.rxtotal, (data.totalrx*1024*1024)+(uint64_t)(data.totalrxk*1024));
- ck_assert_int_eq(info.txtotal, (data.totaltx*1024*1024)+(uint64_t)(data.totaltxk*1024));
+ ck_assert_int_eq(info.rxtotal, (data.totalrx * 1024 * 1024) + (uint64_t)(data.totalrxk * 1024));
+ ck_assert_int_eq(info.txtotal, (data.totaltx * 1024 * 1024) + (uint64_t)(data.totaltxk * 1024));
ck_assert_int_eq(info.rxcounter, data.currx);
ck_assert_int_eq(info.txcounter, data.curtx);
ck_assert_int_ge(info.created, data.created);
ck_assert_int_eq(datainfo.count, 30);
datalist_i = datalist;
i = 29;
- while (datalist_i != NULL)
- {
- ck_assert_int_eq(datalist_i->rx, data.day[i].rx*1024*1024);
- ck_assert_int_eq(datalist_i->tx, data.day[i].tx*1024*1024);
+ while (datalist_i != NULL) {
+ ck_assert_int_eq(datalist_i->rx, data.day[i].rx * 1024 * 1024);
+ ck_assert_int_eq(datalist_i->tx, data.day[i].tx * 1024 * 1024);
datalist_i = datalist_i->next;
i--;
}
ck_assert_int_eq(datainfo.count, 12);
datalist_i = datalist;
i = 11;
- while (datalist_i != NULL)
- {
- ck_assert_int_eq(datalist_i->rx, data.month[i].rx*1024*1024);
- ck_assert_int_eq(datalist_i->tx, data.month[i].tx*1024*1024);
+ while (datalist_i != NULL) {
+ ck_assert_int_eq(datalist_i->rx, data.month[i].rx * 1024 * 1024);
+ ck_assert_int_eq(datalist_i->tx, data.month[i].tx * 1024 * 1024);
datalist_i = datalist_i->next;
i--;
}
ck_assert_int_eq(datainfo.count, 24);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- ck_assert_int_eq(datalist_i->rx, data.hour[i].rx*1024);
- ck_assert_int_eq(datalist_i->tx, data.hour[i].tx*1024);
+ while (datalist_i != NULL) {
+ ck_assert_int_eq(datalist_i->rx, data.hour[i].rx * 1024);
+ ck_assert_int_eq(datalist_i->tx, data.hour[i].tx * 1024);
datalist_i = datalist_i->next;
i++;
}
ck_assert_int_eq(datainfo.count, 10);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- ck_assert_int_eq(datalist_i->rx, data.top10[i].rx*1024*1024);
- ck_assert_int_eq(datalist_i->tx, data.top10[i].tx*1024*1024);
+ while (datalist_i != NULL) {
+ ck_assert_int_eq(datalist_i->rx, data.top10[i].rx * 1024 * 1024);
+ ck_assert_int_eq(datalist_i->tx, data.top10[i].tx * 1024 * 1024);
datalist_i = datalist_i->next;
i++;
}
}
/* make sure version stays correct */
- data->version=LEGACYDBVERSION;
+ data->version = LEGACYDBVERSION;
- if ((testdb=fopen(file,"w"))==NULL) {
+ if ((testdb = fopen(file, "w")) == NULL) {
snprintf(errorstring, 1024, "Unable to open database \"%s\" for writing: %s", file, strerror(errno));
printe(PT_Error);
return 0;
}
/* update timestamp when not merging */
- if (newdb!=2) {
- data->lastupdated=time(NULL);
+ if (newdb != 2) {
+ data->lastupdated = time(NULL);
}
- if (fwrite(data,sizeof(DATA),1,testdb)==0) {
+ if (fwrite(data, sizeof(DATA), 1, testdb) == 0) {
snprintf(errorstring, 1024, "Unable to write database \"%s\": %s", file, strerror(errno));
printe(PT_Error);
fclose(testdb);
printf("db: Database \"%s\" saved.\n", file);
}
fclose(testdb);
- if ((newdb) && (noexit==0)) {
+ if ((newdb) && (noexit == 0)) {
snprintf(errorstring, 1024, "-> A new database has been created.");
printe(PT_Info);
matchdbownerwithdirowner(dirname);
b = fileno(bf);
/* copy data */
- while((bytes = (int)read(c, buffer, sizeof(buffer))) > 0) {
+ while ((bytes = (int)read(c, buffer, sizeof(buffer))) > 0) {
if (write(b, buffer, (size_t)bytes) < 0) {
close(c);
fclose(bf);
iter = dc;
ret = datacache_seek(&iter, "eth3");
- for (i=1; i<=10; i++) {
- ret = xferlog_add(&iter->log, (time_t)i, (uint64_t)i*10, (uint64_t)i*20);
+ for (i = 1; i <= 10; i++) {
+ ret = xferlog_add(&iter->log, (time_t)i, (uint64_t)i * 10, (uint64_t)i * 20);
ck_assert_int_eq(ret, 1);
}
ck_assert_int_eq(iter->log->timestamp, 10);
START_TEST(db_getiflist_lists_interfaces)
{
int ret;
- dbiflist *dbifl = NULL, *dbifl_i = NULL;;
+ dbiflist *dbifl = NULL, *dbifl_i = NULL;
+ ;
defaultcfg();
ret = db_addinterface("ethtest");
ck_assert_int_eq(ret, 1);
- for (i=1; i<=6; i++) {
+ for (i = 1; i <= 6; i++) {
ret = db_insertdata("month", "ethtest", 1, 2, get_timestamp(2000, i, 1, 0, 0));
ck_assert_int_eq(ret, 1);
}
ck_assert_int_eq(datainfo.count, 6);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-01-01");
ck_assert_int_eq(datainfo.count, 6);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-01-01");
ck_assert_int_eq(datainfo.count, 6);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-01-01");
ck_assert_int_eq(datainfo.count, 3);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-02-01");
ck_assert_int_eq(datainfo.count, 4);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-03-01");
ck_assert_int_eq(datainfo.count, 3);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-03-01");
ck_assert_int_eq(datainfo.count, 4);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-01-01");
ck_assert_int_eq(datainfo.count, 3);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-02-01");
ck_assert_int_eq(datainfo.count, 1);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-04-01");
ck_assert_int_eq(datainfo.count, 3);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-03-01");
ret = db_addinterface("ethtest");
ck_assert_int_eq(ret, 1);
- for (j=2; j<5; j++) {
- for (i=0; i<24; i++) {
+ for (j = 2; j < 5; j++) {
+ for (i = 0; i < 24; i++) {
ret = db_insertdata("hour", "ethtest", 1, 2, get_timestamp(2002, 2, j, i, 0));
ck_assert_int_eq(ret, 1);
}
ck_assert_int_eq(datainfo.count, 72);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2002-02-02 00:00");
ck_assert_int_eq(datainfo.count, 72);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2002-02-02 00:00");
ck_assert_int_eq(datainfo.count, 72);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2002-02-02 00:00");
ck_assert_int_eq(datainfo.count, 22);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2002-02-02 20:00");
ck_assert_int_eq(datainfo.count, 52);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2002-02-02 20:00");
ck_assert_int_eq(datainfo.count, 11);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2002-02-02 20:00");
ck_assert_int_eq(datainfo.count, 21);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2002-02-02 00:00");
ck_assert_int_eq(datainfo.count, 5);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2002-02-02 16:00");
ck_assert_int_eq(datainfo.count, 1);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2002-02-02 20:00");
ret = db_addinterface("ethother");
ck_assert_int_eq(ret, 1);
- for (i=1; i<=20; i++) {
+ for (i = 1; i <= 20; i++) {
ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
ck_assert_int_eq(ret, 1);
ret = db_addtraffic_dated("ethother", 3, 7, get_timestamp(2000, 2, i, 0, 0));
ck_assert_int_eq(datainfo.count, 1);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-02-01");
ret = db_addinterface("ethtest");
ck_assert_int_eq(ret, 1);
- for (i=1; i<=20; i++) {
+ for (i = 1; i <= 20; i++) {
ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
ck_assert_int_eq(ret, 1);
}
ck_assert_int_eq(datainfo.count, 1);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-02-01");
ret = db_addinterface("ethtest");
ck_assert_int_eq(ret, 1);
- for (i=1; i<=20; i++) {
+ for (i = 1; i <= 20; i++) {
ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
ck_assert_int_eq(ret, 1);
}
ck_assert_int_eq(datainfo.count, 2);
datalist_i = datalist;
i = 0;
- while (datalist_i != NULL)
- {
- switch(i) {
+ while (datalist_i != NULL) {
+ switch (i) {
case 0:
strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
ck_assert_str_eq(timestamp, "2000-01-01");
step = 1;
}
- for (i=step; (uint64_t)(scaleunit * (unsigned int)i) <= max; i=i+step) {
+ for (i = step; (uint64_t)(scaleunit * (unsigned int)i) <= max; i = i + step) {
s = (int)(121 * ((scaleunit * (unsigned int)i) / (float)max));
prev = s;
}
s = (int)(121 * ((scaleunit * (unsigned int)i) / (float)max));
- if ( ((s+prev)/2) <= 128 ) {
+ if (((s + prev) / 2) <= 128) {
;
} else {
i = i - step;
/* line 1 */
x = 40;
y = 80;
- gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+105, (unsigned char*)"libgd bug workaround", ic.ctext);
+ gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 105, (unsigned char *)"libgd bug workaround", ic.ctext);
drawdonut(&ic, x, y, (float)0, (float)0);
- drawdonut(&ic, x+55, y, (float)50, (float)50);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 50/50", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)50, (float)50);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 50/50", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)100, (float)0);
- drawdonut(&ic, x+55, y, (float)0, (float)100);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"100/0 - 0/100", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)0, (float)100);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"100/0 - 0/100", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)60, (float)40);
- drawdonut(&ic, x+55, y, (float)40, (float)60);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"60/40 - 40/60", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)40, (float)60);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"60/40 - 40/60", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)75, (float)25);
- drawdonut(&ic, x+55, y, (float)25, (float)75);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"75/25 - 25/75", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)25, (float)75);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"75/25 - 25/75", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)90, (float)10);
- drawdonut(&ic, x+55, y, (float)10, (float)90);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"90/10 - 10/90", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)10, (float)90);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"90/10 - 10/90", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)95, (float)5);
- drawdonut(&ic, x+55, y, (float)5, (float)95);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"95/5 - 5/95", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)5, (float)95);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"95/5 - 5/95", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)99, (float)1);
- drawdonut(&ic, x+55, y, (float)1, (float)99);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99/1 - 1/99", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)1, (float)99);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99/1 - 1/99", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)99.9, (float)0.1);
- drawdonut(&ic, x+55, y, (float)0.1, (float)99.9);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99.9/0.1 - 0.1/99.9", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)0.1, (float)99.9);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99.9/0.1 - 0.1/99.9", ic.ctext);
/* line 2 */
x = 40;
y = 160;
drawdonut(&ic, x, y, (float)0, (float)0);
- drawdonut(&ic, x+55, y, (float)25, (float)25);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 25/25", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)25, (float)25);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 25/25", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)50, (float)0);
- drawdonut(&ic, x+55, y, (float)0, (float)50);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"50/0 - 0/50", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)0, (float)50);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"50/0 - 0/50", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)40, (float)30);
- drawdonut(&ic, x+55, y, (float)30, (float)40);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"40/30 - 30/40", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)30, (float)40);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"40/30 - 30/40", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)30, (float)20);
- drawdonut(&ic, x+55, y, (float)20, (float)30);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"30/20 - 20/30", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)20, (float)30);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"30/20 - 20/30", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)20, (float)10);
- drawdonut(&ic, x+55, y, (float)10, (float)20);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"20/10 - 10/20", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)10, (float)20);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"20/10 - 10/20", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)15, (float)5);
- drawdonut(&ic, x+55, y, (float)5, (float)15);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"15/5 - 5/15", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)5, (float)15);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"15/5 - 5/15", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)10, (float)1);
- drawdonut(&ic, x+55, y, (float)1, (float)10);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"10/1 - 1/10", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)1, (float)10);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"10/1 - 1/10", ic.ctext);
x += 130;
drawdonut(&ic, x, y, (float)1, (float)0.1);
- drawdonut(&ic, x+55, y, (float)0.1, (float)1);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"1.0/0.1 - 0.1/1.0", ic.ctext);
+ drawdonut(&ic, x + 55, y, (float)0.1, (float)1);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"1.0/0.1 - 0.1/1.0", ic.ctext);
/* line 3 */
x = 40;
y = 270;
- gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+105, (unsigned char*)"libgd native", ic.ctext);
+ gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 105, (unsigned char *)"libgd native", ic.ctext);
drawdonut_libgd_native(&ic, x, y, (float)0, (float)0);
- drawdonut_libgd_native(&ic, x+55, y, (float)50, (float)50);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 50/50", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)50, (float)50);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 50/50", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)100, (float)0);
- drawdonut_libgd_native(&ic, x+55, y, (float)0, (float)100);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"100/0 - 0/100", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)0, (float)100);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"100/0 - 0/100", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)60, (float)40);
- drawdonut_libgd_native(&ic, x+55, y, (float)40, (float)60);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"60/40 - 40/60", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)40, (float)60);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"60/40 - 40/60", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)75, (float)25);
- drawdonut_libgd_native(&ic, x+55, y, (float)25, (float)75);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"75/25 - 25/75", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)25, (float)75);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"75/25 - 25/75", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)90, (float)10);
- drawdonut_libgd_native(&ic, x+55, y, (float)10, (float)90);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"90/10 - 10/90", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)10, (float)90);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"90/10 - 10/90", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)95, (float)5);
- drawdonut_libgd_native(&ic, x+55, y, (float)5, (float)95);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"95/5 - 5/95", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)5, (float)95);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"95/5 - 5/95", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)99, (float)1);
- drawdonut_libgd_native(&ic, x+55, y, (float)1, (float)99);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99/1 - 1/99", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)1, (float)99);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99/1 - 1/99", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)99.9, (float)0.1);
- drawdonut_libgd_native(&ic, x+55, y, (float)0.1, (float)99.9);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"99.9/0.1 - 0.1/99.9", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)0.1, (float)99.9);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99.9/0.1 - 0.1/99.9", ic.ctext);
/* line 4 */
x = 40;
y = 350;
drawdonut_libgd_native(&ic, x, y, (float)0, (float)0);
- drawdonut_libgd_native(&ic, x+55, y, (float)25, (float)25);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"0/0 - 25/25", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)25, (float)25);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 25/25", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)50, (float)0);
- drawdonut_libgd_native(&ic, x+55, y, (float)0, (float)50);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"50/0 - 0/50", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)0, (float)50);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"50/0 - 0/50", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)40, (float)30);
- drawdonut_libgd_native(&ic, x+55, y, (float)30, (float)40);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"40/30 - 30/40", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)30, (float)40);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"40/30 - 30/40", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)30, (float)20);
- drawdonut_libgd_native(&ic, x+55, y, (float)20, (float)30);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"30/20 - 20/30", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)20, (float)30);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"30/20 - 20/30", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)20, (float)10);
- drawdonut_libgd_native(&ic, x+55, y, (float)10, (float)20);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"20/10 - 10/20", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)10, (float)20);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"20/10 - 10/20", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)15, (float)5);
- drawdonut_libgd_native(&ic, x+55, y, (float)5, (float)15);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"15/5 - 5/15", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)5, (float)15);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"15/5 - 5/15", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)10, (float)1);
- drawdonut_libgd_native(&ic, x+55, y, (float)1, (float)10);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"10/1 - 1/10", ic.ctext);
+ drawdonut_libgd_native(&ic, x + 55, y, (float)1, (float)10);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"10/1 - 1/10", ic.ctext);
x += 130;
drawdonut_libgd_native(&ic, x, y, (float)1, (float)0.1);
- drawdonut_libgd_native(&ic, x+55, y, (float)0.1, (float)1);
- gdImageString(ic.im, gdFontGetSmall(), x-20, y+30, (unsigned char*)"1.0/0.1 - 0.1/1.0", ic.ctext);
-
+ drawdonut_libgd_native(&ic, x + 55, y, (float)0.1, (float)1);
+ gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"1.0/0.1 - 0.1/1.0", ic.ctext);
gdImagePng(ic.im, pngout);
ret = fclose(pngout);
x = 40;
y = 70;
- gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+15, (unsigned char*)"50.0%", ic.ctext);
+ gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 15, (unsigned char *)"50.0%", ic.ctext);
- for (i=50.0; i>=0; i-=(float)0.2) {
+ for (i = 50.0; i >= 0; i -= (float)0.2) {
drawdonut(&ic, x, y, i, i);
x += 55;
- if (x>1000) {
+ if (x > 1000) {
x = 40;
y += 60;
- snprintf(buffer, 6, "%3.1f%%", (double)i-0.2);
- gdImageStringUp(ic.im, gdFontGetSmall(), 1, y+15, (unsigned char*)buffer, ic.ctext);
+ snprintf(buffer, 6, "%3.1f%%", (double)i - 0.2);
+ gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 15, (unsigned char *)buffer, ic.ctext);
}
}
- gdImageString(ic.im, gdFontGetGiant(), 1020, 40, (unsigned char*)"Giant - The quick brown fox jumps over the lazy dog", ic.ctext);
- gdImageString(ic.im, gdFontGetLarge(), 1020, 60, (unsigned char*)"Large - The quick brown fox jumps over the lazy dog", ic.ctext);
- gdImageString(ic.im, gdFontGetMediumBold(), 1020, 80, (unsigned char*)"MediumBold - The quick brown fox jumps over the lazy dog", ic.ctext);
- gdImageString(ic.im, gdFontGetSmall(), 1020, 100, (unsigned char*)"Small - The quick brown fox jumps over the lazy dog", ic.ctext);
- gdImageString(ic.im, gdFontGetTiny(), 1020, 120, (unsigned char*)"Tiny - The quick brown fox jumps over the lazy dog", ic.ctext);
+ gdImageString(ic.im, gdFontGetGiant(), 1020, 40, (unsigned char *)"Giant - The quick brown fox jumps over the lazy dog", ic.ctext);
+ gdImageString(ic.im, gdFontGetLarge(), 1020, 60, (unsigned char *)"Large - The quick brown fox jumps over the lazy dog", ic.ctext);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1020, 80, (unsigned char *)"MediumBold - The quick brown fox jumps over the lazy dog", ic.ctext);
+ gdImageString(ic.im, gdFontGetSmall(), 1020, 100, (unsigned char *)"Small - The quick brown fox jumps over the lazy dog", ic.ctext);
+ gdImageString(ic.im, gdFontGetTiny(), 1020, 120, (unsigned char *)"Tiny - The quick brown fox jumps over the lazy dog", ic.ctext);
drawlegend(&ic, 1230, 140);
drawpole(&ic, 1210, 360, 400, 0, 100, 130);
drawpole(&ic, 1230, 360, 400, 100, 0, 130);
-
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 400, (unsigned char*)"Color: ctext", ic.ctext);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 420, (unsigned char*)"Color: cedge", ic.cedge);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 440, (unsigned char*)"Color: cheader", ic.cheader);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 460, (unsigned char*)"Color: cheadertitle", ic.cheadertitle);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 480, (unsigned char*)"Color: cheaderdate", ic.cheaderdate);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 500, (unsigned char*)"Color: cline", ic.cline);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 520, (unsigned char*)"Color: clinel", ic.clinel);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 540, (unsigned char*)"Color: cbackground", ic.cbackground);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 560, (unsigned char*)"Color: cvnstat", ic.cvnstat);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 580, (unsigned char*)"Color: cbgoffset", ic.cbgoffset);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 600, (unsigned char*)"Color: crx", ic.crx);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 620, (unsigned char*)"Color: crxd", ic.crxd);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 640, (unsigned char*)"Color: ctx", ic.ctx);
- gdImageString(ic.im, gdFontGetMediumBold(), 1280, 660, (unsigned char*)"Color: ctxd", ic.ctxd);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 400, (unsigned char *)"Color: ctext", ic.ctext);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 420, (unsigned char *)"Color: cedge", ic.cedge);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 440, (unsigned char *)"Color: cheader", ic.cheader);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 460, (unsigned char *)"Color: cheadertitle", ic.cheadertitle);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 480, (unsigned char *)"Color: cheaderdate", ic.cheaderdate);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 500, (unsigned char *)"Color: cline", ic.cline);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 520, (unsigned char *)"Color: clinel", ic.clinel);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 540, (unsigned char *)"Color: cbackground", ic.cbackground);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 560, (unsigned char *)"Color: cvnstat", ic.cvnstat);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 580, (unsigned char *)"Color: cbgoffset", ic.cbgoffset);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 600, (unsigned char *)"Color: crx", ic.crx);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 620, (unsigned char *)"Color: crxd", ic.crxd);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 640, (unsigned char *)"Color: ctx", ic.ctx);
+ gdImageString(ic.im, gdFontGetMediumBold(), 1280, 660, (unsigned char *)"Color: ctxd", ic.ctxd);
gdImagePng(ic.im, pngout);
ret = fclose(pngout);
END_TEST
#if defined(__clang__)
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wused-but-marked-unused"
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wused-but-marked-unused"
#endif
START_TEST(getunitprefix_returns_something_with_all_cfg_combinations)
{
int j;
cfg.unitmode = _i;
- for (j=1; j<=(UNITPREFIXCOUNT+1); j++) {
+ for (j = 1; j <= (UNITPREFIXCOUNT + 1); j++) {
string = getunitprefix(j);
ck_assert_int_gt(strlen(string), 0);
}
const char *string;
int j;
- for (j=1; j<=(UNITPREFIXCOUNT+1); j++) {
+ for (j = 1; j <= (UNITPREFIXCOUNT + 1); j++) {
string = getrateunitprefix(_i, j);
ck_assert_int_gt(strlen(string), 0);
}
int j;
char div[16];
- for (j=1; j<=(UNITPREFIXCOUNT+1); j++) {
- snprintf(div, 15, "%"PRIu64"", getunitdivisor(_i, j));
- if (j>UNITPREFIXCOUNT) {
+ for (j = 1; j <= (UNITPREFIXCOUNT + 1); j++) {
+ snprintf(div, 15, "%" PRIu64 "", getunitdivisor(_i, j));
+ if (j > UNITPREFIXCOUNT) {
ck_assert_str_eq(div, "1");
} else {
ck_assert_str_ne(div, "0");
}
END_TEST
#if defined(__clang__)
- #pragma clang diagnostic pop
+#pragma clang diagnostic pop
#endif
START_TEST(spacecheck_does_not_check_when_not_configured)
{
int i, j;
- for (i=0; i<=1; i++) {
+ for (i = 0; i <= 1; i++) {
cfg.rateunit = i;
- for (j=0; j<=2; j++) {
+ for (j = 0; j <= 2; j++) {
cfg.unitmode = j;
ck_assert_str_eq(gettrafficrate(1, 0, 0), "n/a");
}
cfg.defaultdecimals = 2;
cfg.unitmode = 0;
cfg.rateunit = 0;
- ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.00 KiB/s");
+ ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.00 KiB/s");
ck_assert_str_eq(gettrafficrate(102400, 1, 12), "100.00 KiB/s");
ck_assert_str_eq(gettrafficrate(102400, 1, 14), " 100.00 KiB/s");
- ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s");
- ck_assert_str_eq(gettrafficrate(900, 1, 7), "900 B/s");
+ ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s");
+ ck_assert_str_eq(gettrafficrate(900, 1, 7), "900 B/s");
ck_assert_str_eq(gettrafficrate(900, 1, 12), " 900 B/s");
ck_assert_str_eq(gettrafficrate(900, 1, 14), " 900 B/s");
}
debug = 1;
intsignal = 0;
disable_logprints();
- ck_assert(signal(SIGINT, sighandler)!=SIG_ERR);
- ck_assert(signal(SIGHUP, sighandler)!=SIG_ERR);
- ck_assert(signal(SIGTERM, sighandler)!=SIG_ERR);
+ ck_assert(signal(SIGINT, sighandler) != SIG_ERR);
+ ck_assert(signal(SIGHUP, sighandler) != SIG_ERR);
+ ck_assert(signal(SIGTERM, sighandler) != SIG_ERR);
ck_assert_int_eq(kill(getpid(), SIGINT), 0);
ck_assert_int_eq(intsignal, SIGINT);
create_testdir();
- if (stat(TESTDBDIR, &statbuf)!=0) {
- if (errno==ENOENT) {
- if (mkdir(TESTDBDIR, 0755)==0) {
+ if (stat(TESTDBDIR, &statbuf) != 0) {
+ if (errno == ENOENT) {
+ if (mkdir(TESTDBDIR, 0755) == 0) {
return 1;
}
}
ck_abort_msg("error \"%s\" while removing directory \"%s\", please remove it manually", strerror(errno), TESTDBDIR);
}
- if (mkdir(TESTDBDIR, 0755)!=0) {
+ if (mkdir(TESTDBDIR, 0755) != 0) {
ck_abort_msg("error \"%s\" while creating directory \"%s\"", strerror(errno), TESTDBDIR);
}
{
struct stat statbuf;
- if (stat(TESTDIR, &statbuf)!=0) {
- if (errno==ENOENT) {
- if (mkdir(TESTDIR, 0755)==0) {
+ if (stat(TESTDIR, &statbuf) != 0) {
+ if (errno == ENOENT) {
+ if (mkdir(TESTDIR, 0755) == 0) {
return 1;
}
}
{
struct stat statbuf;
- if (stat(directory, &statbuf)!=0) {
- if (errno==ENOENT) {
+ if (stat(directory, &statbuf) != 0) {
+ if (errno == ENOENT) {
if (mkdir(directory, 0755) != 0) {
ck_abort_msg("error \"%s\" while creating directory \"%s\"", strerror(errno), directory);
}
struct dirent *di = NULL;
char entryname[512];
- if ((dir=opendir(directory))==NULL) {
- if (errno==ENOENT) {
+ if ((dir = opendir(directory)) == NULL) {
+ if (errno == ENOENT) {
return 1;
} else {
return 0;
}
}
- while ((di=readdir(dir))) {
+ while ((di = readdir(dir))) {
switch (di->d_type) {
case DT_LNK:
case DT_REG:
snprintf(entryname, 512, "%s/%s", directory, di->d_name);
- if (unlink(entryname)!=0) {
+ if (unlink(entryname) != 0) {
closedir(dir);
return 0;
}
break;
case DT_DIR:
- if (strcmp(di->d_name, ".")==0 || strcmp(di->d_name, "..")==0) {
+ if (strcmp(di->d_name, ".") == 0 || strcmp(di->d_name, "..") == 0) {
continue;
}
snprintf(entryname, 512, "%s/%s", directory, di->d_name);
}
}
closedir(dir);
- if (rmdir(directory)!=0) {
+ if (rmdir(directory) != 0) {
return 0;
}
char filename[512];
snprintf(filename, 512, "%s/%s", TESTDBDIR, iface);
- if ((fp=fopen(filename, "w"))==NULL) {
+ if ((fp = fopen(filename, "w")) == NULL) {
ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
}
fclose(fp);
char filename[512];
snprintf(filename, 512, "%s/%s", TESTDBDIR, iface);
- if (stat(filename, &statbuf)!=0) {
- if (errno==ENOENT) {
+ if (stat(filename, &statbuf) != 0) {
+ if (errno == ENOENT) {
return 0;
}
ck_abort_msg("error \"%s\" while inspecting file \"%s\"", strerror(errno), filename);
FILE *devfp;
char filename[512];
- if (strcmp(mode, "w") != 0 && strcmp(mode, "a") != 0) {
+ if (strcmp(mode, "w") != 0 && strcmp(mode, "a") != 0) {
ck_abort_msg("error: only w and a modes are supported");
}
create_directory(TESTPROCDIR);
snprintf(filename, 512, "%s/dev", TESTPROCDIR);
- if ((devfp=fopen(filename, mode))==NULL) {
+ if ((devfp = fopen(filename, mode)) == NULL) {
ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
}
if (speed != 0) {
snprintf(filename, 512, "%s/%s/speed", TESTSYSCLASSNETDIR, iface);
- if ((devfp=fopen(filename, "w"))==NULL) {
+ if ((devfp = fopen(filename, "w")) == NULL) {
ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
}
fprintf(devfp, "%d\n", speed);
}
snprintf(filename, 512, "%s/%s/statistics/rx_bytes", TESTSYSCLASSNETDIR, iface);
- if ((devfp=fopen(filename, "w"))==NULL) {
+ if ((devfp = fopen(filename, "w")) == NULL) {
ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
}
fprintf(devfp, "%d\n", rx);
fclose(devfp);
snprintf(filename, 512, "%s/%s/statistics/tx_bytes", TESTSYSCLASSNETDIR, iface);
- if ((devfp=fopen(filename, "w"))==NULL) {
+ if ((devfp = fopen(filename, "w")) == NULL) {
ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
}
fprintf(devfp, "%d\n", tx);
fclose(devfp);
snprintf(filename, 512, "%s/%s/statistics/rx_packets", TESTSYSCLASSNETDIR, iface);
- if ((devfp=fopen(filename, "w"))==NULL) {
+ if ((devfp = fopen(filename, "w")) == NULL) {
ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
}
fprintf(devfp, "%d\n", rxp);
fclose(devfp);
snprintf(filename, 512, "%s/%s/statistics/tx_packets", TESTSYSCLASSNETDIR, iface);
- if ((devfp=fopen(filename, "w"))==NULL) {
+ if ((devfp = fopen(filename, "w")) == NULL) {
ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename);
}
fprintf(devfp, "%d\n", txp);