Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 24 additions & 2 deletions check_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ int main(int argc, char *argv[]) {
.err_tolerance = 50,
.coll_tolerance = -1,
.hostname = 0,
.port = "161",
.user = 0,
.auth_proto = 0,
.auth_pass = 0,
Expand Down Expand Up @@ -194,17 +195,29 @@ int main(int argc, char *argv[]) {
gettimeofday(&tv, &tz);
starttime = (long double)tv.tv_sec + (((long double)tv.tv_usec) / 1000000);

// +1 for the `:` between hostname and port
size_t peername_max_len = strlen(config.hostname) + strlen(config.port) + 1;
char *peername = calloc(1, peername_max_len+1);
if (peername == NULL) {
printf("Failed to allocate memory at %d in %s\n", __LINE__, __FUNCTION__);
exit(3);
}

strlcpy(peername, config.hostname, peername_max_len+1);
strlcat(peername, ":", peername_max_len+1);
strlcat(peername, config.port, peername_max_len+1);

#ifdef DEBUG
benchmark_start("Start SNMP session");
#endif
if (config.user)
/* use snmpv3 */
ss = start_session_v3(&session, config.user, config.auth_proto,
config.auth_pass, config.priv_proto,
config.priv_pass, config.hostname,
config.priv_pass, peername,
config.global_timeout, config.session_retries);
else
ss = start_session(&session, config.community, config.hostname,
ss = start_session(&session, config.community, peername,
config.mode, config.global_timeout,
config.session_retries);
#ifdef DEBUG
Expand Down Expand Up @@ -1257,6 +1270,10 @@ bool fetch_interface_names(struct configuration_struct* config, char **oid_names
return true;
}

enum {
PORT_OPTION = CHAR_MAX + 1
};

void parse_and_check_commandline(int argc, char **argv,
struct configuration_struct *config) {
int opt;
Expand All @@ -1277,6 +1294,7 @@ void parse_and_check_commandline(int argc, char **argv,
{"errors", required_argument, NULL, 'e'},
{"out-errors", required_argument, NULL, 'f'},
{"hostname", required_argument, NULL, 'h'},
{"port", required_argument, NULL, PORT_OPTION},
{"auth-proto", required_argument, NULL, 'j'},
{"auth-phrase", required_argument, NULL, 'J'},
{"priv-proto", required_argument, NULL, 'k'},
Expand Down Expand Up @@ -1332,6 +1350,9 @@ void parse_and_check_commandline(int argc, char **argv,
case 'h':
config->hostname = optarg;
break;
case PORT_OPTION:
config->port = optarg;
break;
case 'j':
config->auth_proto = optarg;
break;
Expand Down Expand Up @@ -1510,6 +1531,7 @@ int usage(char *progname) {
printf(" --retries\t\thow often to retry before giving up\n");
printf(" --max-repetitions\t\tsee "
"<http://www.net-snmp.org/docs/man/snmpbulkwalk.html>\n");
printf(" --port\t\tPort (default 161)\n");
printf("\n");
return 3;
}
1 change: 1 addition & 0 deletions snmp_bulkget.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ typedef struct configuration_struct {
int err_tolerance;
int coll_tolerance;
char *hostname;
char* port;
char *user;
char *auth_proto;
char *auth_pass;
Expand Down