Hello,
I was trying to accomplish making a code that every time you perform a SET
operation, type the value in a text file and then read the same value from
the same file using a GET operation.
For starters, I have generated a template code that is broadly that is
equivalent to the
'example / scalar_int.c' module with mib2c command. After modifying this
template, I managed to perform the get operation by reading the value from
a file.
The problem arose when I tried to make a code for type the value in the
file with SET operation. To test, I wrote a small code to perform writing
the value of a variable in a text file , and it worked perfectly. The code
was as follows:
static long example1 = 123456;
char line[10];
int main()
{
FILE *filep;
filep = fopen("/tmp/test2.txt","w+");
if (filep==NULL)
{
perror ("Error al abrir test2.txt");
return -1;
}
sprintf(line, "%ld", example1);
fputs(line,filep);
fputs("\n",filep);
fclose(filep);
return 0;
}
But when I transcribed this code to the template, did not work. The code
was compiled without errors, and operations get / set are working, but SET
operation not write the value to the file, as the file it is empty.
Note that in the template I tried to perform the set operation writing to a
file, tweak the MODE_GET block to Directly Report this value, * not * read
from the / tmp file just yet, in order to have it running two separate
blocks, and then them together.
The blocks GET / SET the template were as follows:
FILE *filep;
filep = fopen("/tmp/test.txt","w+");
if (filep==NULL)
{
perror ("Error al abrir test2.txt");
return -1;
}
char line[10];
switch(reqinfo->mode) {
case MODE_GET:
snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
&example1,
sizeof(&example1));
break;
case MODE_SET_ACTION:
example1 = *(requests->requestvb->val.integer);
sprintf(line, "%ld", example1);
fputs(line,filep);
fputs("\n",filep);
fclose(filep);
break;
Could you help me to realize where the error is, and because it writes the
value to the text file?
>From already, thank you very much.
Regards,
Juan I. Bussoli.
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders