Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --version flag to print version #42

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions check_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ returncode_t print_output(struct configuration_struct *config, struct ifStruct *
long double starttime, struct ifStruct *interfaces, String *out, char **if_vars,
unsigned int number_of_matched_interfaces, struct timeval *tv, int uptime,
int ifNumber);
void print_version(void);

int main(int argc, char *argv[]) {
netsnmp_session session, *ss;
Expand Down Expand Up @@ -1270,9 +1271,7 @@ bool fetch_interface_names(struct configuration_struct* config, char **oid_names
return true;
}

enum {
PORT_OPTION = CHAR_MAX + 1
};
enum { PORT_OPTION = CHAR_MAX + 1, VERSION_OPTION = CHAR_MAX + 2 };

void parse_and_check_commandline(int argc, char **argv,
struct configuration_struct *config) {
Expand Down Expand Up @@ -1315,6 +1314,7 @@ void parse_and_check_commandline(int argc, char **argv,
{"sleep", required_argument, NULL, 3},
{"retries", required_argument, NULL, 4},
{"max-repetitions", required_argument, NULL, 5},
{"version", no_argument, NULL, VERSION_OPTION},
{NULL, 0, NULL, 0}};

while ((opt = getopt_long(argc, argv,
Expand Down Expand Up @@ -1415,6 +1415,8 @@ void parse_and_check_commandline(int argc, char **argv,
case 5:
config->pdu_max_repetitions = strtol(optarg, NULL, 10);
break;
case VERSION_OPTION:
print_version();
case '?':
default:
exit(usage(progname));
Expand Down Expand Up @@ -1478,6 +1480,13 @@ void parse_and_check_commandline(int argc, char **argv,
setenv("MIBS", "", 1);
}

void print_version(void) {
#ifdef PACKAGE_VERSION
puts(PACKAGE_VERSION);
#endif // PACKAGE_VERSION
exit(0);
}

int usage(char *progname) {
int i;
printf(
Expand Down Expand Up @@ -1532,6 +1541,7 @@ int usage(char *progname) {
printf(" --max-repetitions\t\tsee "
"<http://www.net-snmp.org/docs/man/snmpbulkwalk.html>\n");
printf(" --port\t\tPort (default 161)\n");
printf(" --version\t\tPrint program version\n");
printf("\n");
return 3;
}