Reputation: 41
Here is the relevant code:
pdu = snmp_pdu_create(SNMP_MSG_SET);
if (snmp_add_var(pdu, oid, oid_len, ASN_INTEGER, "1" ) != 0 )
snmp_perror("failed");
I get an error "Bad value type: weird Unicode character "
When I run this snmpset command in terminal:
snmpset -v 3 -u <user> <ip> <oid> integer 1
it works fine, so why isn't it working in my C program?
Upvotes: 0
Views: 818
Reputation: 385295
You're using snmp_add_var
wrong. It's the equivalent of snmpset
in a sense, so you should be passing the character 'i'
instead of the constant ASN_INTEGER
, which is designed for something else.
ASN_INTEGER
is defined to be ((u_char)0x02)
, so it's the parsing of that argument that's causing decoding difficulties.
The "something else" is the function you probably want to be using instead, which is snmp_pdu_add_variable
:
pdu = snmp_pdu_create(SNMP_MSG_SET);
uint32_t val = 1;
if (snmp_pdu_add_variable(pdu, oid, oid_len, ASN_INTEGER, &val, sizeof(val)) == nullptr)
snmp_perror("failed");
Note how it is "typed", rather than taking a string to lexically convert.
Upvotes: 0