Skip to content

Commit aecc436

Browse files
committed
Add --version flag to print version
1 parent f89e531 commit aecc436

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

check_interfaces.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ returncode_t print_output(struct configuration_struct *config, struct ifStruct *
114114
long double starttime, struct ifStruct *interfaces, String *out, char **if_vars,
115115
unsigned int number_of_matched_interfaces, struct timeval *tv, int uptime,
116116
int ifNumber);
117+
void print_version(void);
117118

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

1273-
enum {
1274-
PORT_OPTION = CHAR_MAX + 1
1275-
};
1274+
enum { PORT_OPTION = CHAR_MAX + 1, VERSION_OPTION = CHAR_MAX + 2 };
12761275

12771276
void parse_and_check_commandline(int argc, char **argv,
12781277
struct configuration_struct *config) {
@@ -1315,6 +1314,7 @@ void parse_and_check_commandline(int argc, char **argv,
13151314
{"sleep", required_argument, NULL, 3},
13161315
{"retries", required_argument, NULL, 4},
13171316
{"max-repetitions", required_argument, NULL, 5},
1317+
{"version", no_argument, NULL, VERSION_OPTION},
13181318
{NULL, 0, NULL, 0}};
13191319

13201320
while ((opt = getopt_long(argc, argv,
@@ -1415,6 +1415,8 @@ void parse_and_check_commandline(int argc, char **argv,
14151415
case 5:
14161416
config->pdu_max_repetitions = strtol(optarg, NULL, 10);
14171417
break;
1418+
case VERSION_OPTION:
1419+
print_version();
14181420
case '?':
14191421
default:
14201422
exit(usage(progname));
@@ -1478,6 +1480,13 @@ void parse_and_check_commandline(int argc, char **argv,
14781480
setenv("MIBS", "", 1);
14791481
}
14801482

1483+
void print_version(void) {
1484+
#ifdef PACKAGE_VERSION
1485+
puts(PACKAGE_VERSION);
1486+
#endif // PACKAGE_VERSION
1487+
exit(0);
1488+
}
1489+
14811490
int usage(char *progname) {
14821491
int i;
14831492
printf(
@@ -1532,6 +1541,7 @@ int usage(char *progname) {
15321541
printf(" --max-repetitions\t\tsee "
15331542
"<http://www.net-snmp.org/docs/man/snmpbulkwalk.html>\n");
15341543
printf(" --port\t\tPort (default 161)\n");
1544+
printf(" --version\t\tPrint program version\n");
15351545
printf("\n");
15361546
return 3;
15371547
}

0 commit comments

Comments
 (0)