custom snmpset coding not working-giving-error

Akhilesh kumar 95akumar at gmail.com
Mon Dec 8 05:57:33 UTC 2014


Hi all

i am writing my own implementation code for snmpset command. I have written
the below code but it gives error. I cant figure out how to correct "Bad
variable type" error.



#include <stdio.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <string.h>
#include <net-snmp/varbind_api.h>

int main(int argc, char ** argv)
{

struct snmp_session session;
struct snmp_session *sess_handle;
struct snmp_pdu *pdu;
struct snmp_pdu *response;
struct variable_list *vars;
oid id_oid[MAX_OID_LEN];
size_t id_len = MAX_OID_LEN;
size_t name_length;
int status;
char set_var_cval[30],set_var[50];
int choose_option=0;
char *p=NULL, get_var[51];
int set_var_ival=0,failures=0,count;
char           *names[SNMP_MAX_CMDLINE_OIDS];
char            types[SNMP_MAX_CMDLINE_OIDS];
unsigned int    *values[SNMP_MAX_CMDLINE_OIDS];
oid             name[MAX_OID_LEN];
char type='i';
const char
*dirname="/usr/local/share/snmp/mibs/",*filename="DDS-ENGINE-MIB.mib";
unsigned int value_ptr;



        add_mibdir("/usr/local/share/snmp/mibs/");
        read_mib("DDS-ENGINE-MIB.mib");
        printf("Enter the OID to set value\n");
        scanf("%s",&set_var);
        printf("The OID to be set is %s\n",set_var);

        init_snmp("snmpdemoapp");
        snmp_sess_init( &session );
        session.version = SNMP_VERSION_1;
        session.community = "public";
        session.community_len = strlen(session.community);
        session.peername = argv[1];
        sess_handle = snmp_open(&session);
        pdu = snmp_pdu_create(SNMP_MSG_SET);


        count=0;
        names[0]=set_var;
        printf("Enter the value to be set with\n");
        scanf("%d",&value_ptr);
        values[0]=&value_ptr;
        types[0]="i";
        name_length=strlen(names[0]);

        if (snmp_add_var(pdu, name, name_length, types[count],
values[count]))
                { snmp_perror(names[count]); failures++; }



        status = snmp_synch_response(sess_handle, pdu, &response);






snmp_free_pdu(response);
snmp_close(sess_handle);
exit(1);

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20141208/0de20bc0/attachment-0001.html>


More information about the busybox mailing list