custom snmpset coding not working-giving-error

2014-12-07 Thread Akhilesh kumar
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 
#include 
#include 
#include 
#include 

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];
chartypes[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);

}
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Re: custom snmpset coding not working-giving-error

2014-12-07 Thread Laszlo Papp
Please stop sending these messages to this mailing list. This is _not_
an SNMP mailing list. If you need programming help, go to trainings or
other sites, like Stack Overflow.

On Mon, Dec 8, 2014 at 5:57 AM, Akhilesh kumar <95aku...@gmail.com> wrote:
> 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 
> #include 
> #include 
> #include 
> #include 
>
> 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];
> chartypes[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);
>
> }
>
>
> ___
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox