@@ -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
118119int main (int argc , char * argv []) {
119120 netsnmp_session session , * ss ;
@@ -1285,9 +1286,7 @@ bool fetch_interface_names(struct configuration_struct* config, char **oid_names
12851286 return true;
12861287}
12871288
1288- enum {
1289- PORT_OPTION = CHAR_MAX + 1
1290- };
1289+ enum { PORT_OPTION = CHAR_MAX + 1 , VERSION_OPTION = CHAR_MAX + 2 };
12911290
12921291void parse_and_check_commandline (int argc , char * * argv ,
12931292 struct configuration_struct * config ) {
@@ -1330,6 +1329,7 @@ void parse_and_check_commandline(int argc, char **argv,
13301329 {"sleep" , required_argument , NULL , 3 },
13311330 {"retries" , required_argument , NULL , 4 },
13321331 {"max-repetitions" , required_argument , NULL , 5 },
1332+ {"version" , no_argument , NULL , VERSION_OPTION },
13331333 {NULL , 0 , NULL , 0 }};
13341334
13351335 while ((opt = getopt_long (argc , argv ,
@@ -1430,6 +1430,8 @@ void parse_and_check_commandline(int argc, char **argv,
14301430 case 5 :
14311431 config -> pdu_max_repetitions = strtol (optarg , NULL , 10 );
14321432 break ;
1433+ case VERSION_OPTION :
1434+ print_version ();
14331435 case '?' :
14341436 default :
14351437 exit (usage (progname ));
@@ -1493,6 +1495,13 @@ void parse_and_check_commandline(int argc, char **argv,
14931495 setenv ("MIBS" , "" , 1 );
14941496}
14951497
1498+ void print_version (void ) {
1499+ #ifdef PACKAGE_VERSION
1500+ puts (PACKAGE_VERSION );
1501+ #endif // PACKAGE_VERSION
1502+ exit (0 );
1503+ }
1504+
14961505int usage (char * progname ) {
14971506 int i ;
14981507 printf (
@@ -1547,6 +1556,7 @@ int usage(char *progname) {
15471556 printf (" --max-repetitions\t\tsee "
15481557 "<http://www.net-snmp.org/docs/man/snmpbulkwalk.html>\n" );
15491558 printf (" --port\t\tPort (default 161)\n" );
1559+ printf (" --version\t\tPrint program version\n" );
15501560 printf ("\n" );
15511561 return 3 ;
15521562}
0 commit comments