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