kewal
kewal

Reputation: 39

Unable to set value using net-snmp c API

I am trying to set a value for an OID using net-snmp C api, snippet of the code that I am using is:

char *ltmp = "description";

char *buff = malloc(sizeof(char)*50);
strcpy(buff,ltmp);

if (!snmp_parse_oid(".1.3.6.1.4.1.2162.1.2.2.1.0", anOID, &anOID_len)) {
    snmp_perror(".1.3.6.1.4.1.2162.1.2.2.1.0");
    SOCK_CLEANUP;
    exit(1);
} else if (snmp_pdu_add_variable(pdu, anOID, anOID_len,'s',buff, (int)strlen(buff))) {
    snmp_perror(".1.3.6.1.4.1.2162.1.2.2.1.0");
}  

when I run this code, it throws the following error

Internal error in type switching

Error in packet

Reason: (badValue) The value given has the wrong type or length.

what am I doing wrong here?

Upvotes: 3

Views: 1096

Answers (1)

miken32
miken32

Reputation: 42725

You should be using one of the predefined constants for the variable type; in this case ASN_OCTET_STR instead of s.

From asn1.h:

#define ASN_BOOLEAN         ((u_char)0x01)
#define ASN_INTEGER         ((u_char)0x02)
#define ASN_BIT_STR         ((u_char)0x03)
#define ASN_OCTET_STR       ((u_char)0x04)
#define ASN_NULL            ((u_char)0x05)
#define ASN_OBJECT_ID       ((u_char)0x06)
#define ASN_SEQUENCE        ((u_char)0x10)
#define ASN_SET             ((u_char)0x11)

Upvotes: 2

Related Questions