Hi,

I try what you say and... It's Works! :)
Let's go now for the SET!

Thanks Dave and Claus for your time and help
Regards.
Guille


$ snmptranslate -IR -Of netSnmpExampleIntegerII.0
.iso.org.dod.internet.private.enterprises.netSnmp.netSnmpExamples.netSnmpExampleScalars.netSnmpExampleIntegerII.0


(authentication information not shown in these commands):
$ snmpwalk localhost netSnmpExampleIntegerII
NET-SNMP-EXAMPLES-MIB::netSnmpExampleIntegerII.0 = INTEGER: 22

------------------------------------  part of netSnmpExampleIntegerII.c

FILE *filep;
filep = fopen("/tmp/test","r");
char line[10];
char *p;

    switch(reqinfo->mode) {

        case MODE_GET:

fgets(line, sizeof(line), filep);
fclose(filep);
filep = NULL;
example1 = strtol(line,&p,0);

            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                     &example1,
                                     sizeof(&example1));
            break;

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in
handle_netSnmpExampleIntegerII\n", reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

--------------
$ cat /tmp/test
22



2013/1/22 Dave Shield <d.t.shi...@liverpool.ac.uk>

> On 21 January 2013 20:20, Guillermo Veneranda <guillev...@gmail.com>
> wrote:
> > Hi,
> >     I'm reading the files examples/netSnmpHostsTable* but I find these
> quite
> > difficult to understand, This is going to take a while. Maybe I should
> try
> > something easier that use subhandler function.
> >
> > Could you please show me a simple example of a subhandler function?
>
> If you started by looking at the code in 'example/scalar_int.c'
> then perhaps a sensible approach would be to look at a handler-based
> version of that.
>
> Try running the following command:
>
>       mib2c  -c   mib2c.scalar.conf
> NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger
>
> That will generate template code that is broadly equivalent to the
> 'example/scalar_int.c' module.
>    The main difference is that instead of GET/SETs being handled
> automatically by an internal helper, the requests are passed to the
> MIB handler routine (i.e. the generated code) for processing.
>
> What I would suggest is that you start with a read-only version of the
> above template - i.e. take the generated code, change
> "HANDLER_CAN_RWRITE" to be "HANDLER_CAN_RONLY", and
> delete the blocks     MODE_SET_RESERVE1 through to MODE_SET_UNDO
>
> Then add the declaration of 'example1' from example/scalar_int.c
> and use this value to fill in the MODE_GET block.
>    Compiling that into the agent (*instead* of example/scalar_int)
> should allow you to query the same OID as before.
>
>
> Then amend the code of the MODE_GET block so that instead of
> returning a fixed value for 'example1',  this value is read from a file.
> (i.e. open the file, scan in a line, convert this line to a number,
>  and return that number - not forgetting to close the file again!)
>
>
> That would give you the first part of what you were asking about.
> (Handling GET requests from a file).
>
> Try that - and come back when you've got it working, and we can
> look at the SET processing.
>
> Dave
>
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to