version 1.14, 2019/10/07 07:39:50 |
version 1.15, 2019/10/08 08:41:31 |
|
|
struct snmp_agent *snmpc_connect(char *, char *); |
struct snmp_agent *snmpc_connect(char *, char *); |
int snmpc_parseagent(char *, char *); |
int snmpc_parseagent(char *, char *); |
int snmpc_print(struct ber_element *); |
int snmpc_print(struct ber_element *); |
__dead void snmpc_printerror(enum snmp_error, char *); |
__dead void snmpc_printerror(enum snmp_error, struct ber_element *, int, |
|
const char *); |
char *snmpc_hex2bin(char *, size_t *); |
char *snmpc_hex2bin(char *, size_t *); |
struct ber_element *snmpc_varbindparse(int, char *[]); |
struct ber_element *snmpc_varbindparse(int, char *[]); |
void usage(void); |
void usage(void); |
|
|
int i; |
int i; |
int class; |
int class; |
unsigned type; |
unsigned type; |
|
char *hint = NULL; |
|
|
if (argc < 2) |
if (argc < 2) |
usage(); |
usage(); |
|
|
|
|
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, &errorstatus, |
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, &errorstatus, |
&errorindex, &varbind); |
&errorindex, &varbind); |
if (errorstatus != 0) |
if (errorstatus != 0) { |
snmpc_printerror((enum snmp_error) errorstatus, |
if (errorindex >= 1 && errorindex <= argc) |
argv[errorindex - 1]); |
hint = argv[errorindex - 1]; |
|
snmpc_printerror((enum snmp_error) errorstatus, varbind, |
|
errorindex, hint); |
|
} |
|
|
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
printf("Received report:\n"); |
printf("Received report:\n"); |
|
|
struct timespec start, finish; |
struct timespec start, finish; |
struct snmp_agent *agent; |
struct snmp_agent *agent; |
const char *oids; |
const char *oids; |
char oidstr[SNMP_MAX_OID_STRLEN]; |
|
int n = 0, prev_cmp; |
int n = 0, prev_cmp; |
int errorstatus, errorindex; |
int errorstatus, errorindex; |
int class; |
int class; |
|
|
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, |
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, |
&errorstatus, &errorindex, &varbind); |
&errorstatus, &errorindex, &varbind); |
if (errorstatus != 0) |
if (errorstatus != 0) |
snmpc_printerror((enum snmp_error) errorstatus, |
snmpc_printerror((enum snmp_error) errorstatus, varbind, |
argv[errorindex - 1]); |
errorindex, oids); |
|
|
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
printf("Received report:\n"); |
printf("Received report:\n"); |
|
|
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, |
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, |
&errorstatus, &errorindex, &varbind); |
&errorstatus, &errorindex, &varbind); |
if (errorstatus != 0) { |
if (errorstatus != 0) { |
smi_oid2string(&noid, oidstr, sizeof(oidstr), |
snmpc_printerror((enum snmp_error) errorstatus, varbind, |
oid_lookup); |
errorindex, NULL); |
snmpc_printerror((enum snmp_error) errorstatus, oidstr); |
|
} |
} |
|
|
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
|
|
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, |
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, |
&errorstatus, &errorindex, &varbind); |
&errorstatus, &errorindex, &varbind); |
if (errorstatus != 0) |
if (errorstatus != 0) |
snmpc_printerror((enum snmp_error) errorstatus, |
snmpc_printerror((enum snmp_error) errorstatus, varbind, |
argv[errorindex - 1]); |
errorindex, oids); |
|
|
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
printf("Received report:\n"); |
printf("Received report:\n"); |
|
|
int errorstatus, errorindex; |
int errorstatus, errorindex; |
int class; |
int class; |
unsigned type; |
unsigned type; |
|
char *hint = NULL; |
|
|
if (argc < 4) |
if (argc < 4) |
usage(); |
usage(); |
|
|
if (pledge("stdio", NULL) == -1) |
if (pledge("stdio", NULL) == -1) |
err(1, "pledge"); |
err(1, "pledge"); |
|
|
pdu = snmp_set(agent, snmpc_varbindparse(argc, argv)); |
if ((pdu = snmp_set(agent, snmpc_varbindparse(argc, argv))) == NULL) |
|
err(1, "set"); |
|
|
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, &errorstatus, |
(void) ber_scanf_elements(pdu, "t{Sdd{e", &class, &type, &errorstatus, |
&errorindex, &varbind); |
&errorindex, &varbind); |
if (errorstatus != 0) |
if (errorstatus != 0) { |
snmpc_printerror((enum snmp_error) errorstatus, |
if (errorindex >= 1 && errorindex <= argc / 3) |
argv[errorindex - 1]); |
hint = argv[(errorindex - 1) * 3]; |
|
snmpc_printerror((enum snmp_error) errorstatus, varbind, |
|
errorindex, hint); |
|
} |
|
|
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
if (class == BER_CLASS_CONTEXT && type == SNMP_C_REPORT) |
printf("Received report:\n"); |
printf("Received report:\n"); |
|
|
} |
} |
|
|
__dead void |
__dead void |
snmpc_printerror(enum snmp_error error, char *oid) |
snmpc_printerror(enum snmp_error error, struct ber_element *varbind, |
|
int index, const char *hint) |
{ |
{ |
|
struct ber_oid hoid, vboid; |
|
char oids[SNMP_MAX_OID_STRLEN]; |
|
const char *oid = NULL; |
|
int i; |
|
|
|
if (index >= 1) { |
|
/* Only print if the index is in the reply */ |
|
for (i = 1; varbind != NULL && i <= index; |
|
varbind = varbind->be_next) |
|
i++; |
|
if (varbind != NULL && |
|
ber_get_oid(varbind->be_sub, &vboid) == 0) { |
|
/* If user and reply conform print user input */ |
|
if (hint != NULL && |
|
smi_string2oid(hint, &hoid) == 0 && |
|
ber_oid_cmp(&hoid, &vboid) == 0) |
|
oid = hint; |
|
else |
|
oid = smi_oid2string(&vboid, oids, |
|
sizeof(oids), oid_lookup); |
|
} |
|
} |
|
if (oid == NULL) |
|
oid = "?"; |
|
|
switch (error) { |
switch (error) { |
case SNMP_ERROR_NONE: |
case SNMP_ERROR_NONE: |
errx(1, "No error, how did I get here?"); |
errx(1, "No error, how did I get here?"); |