net-snmp 5.7
scalar_int.c
00001 
00022 /*
00023  * start be including the appropriate header files 
00024  */
00025 #include <net-snmp/net-snmp-config.h>
00026 #include <net-snmp/net-snmp-features.h>
00027 #include <net-snmp/net-snmp-includes.h>
00028 #include <net-snmp/agent/net-snmp-agent-includes.h>
00029 
00030 /*
00031  * if --enable-minimalist has been turned on, we need to register
00032  * the support we need so the needed functions aren't removed at compile time
00033  */
00034 netsnmp_feature_require(long_instance)
00035 
00036 /*
00037  * Then, we declare the variables we want to be accessed 
00038  */
00039 static long     example1 = 42;  /* default value */
00040 
00041 /*
00042  * our initialization routine, automatically called by the agent 
00043  * (to get called, the function name must match init_FILENAME())
00044  */
00045 void
00046 init_scalar_int(void)
00047 {
00048     /*
00049      * the OID we want to register our integer at.  This should be a
00050      * fully qualified instance.  In our case, it's a scalar at:
00051      * NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 (note the
00052      * trailing 0 which is required for any instantiation of any
00053      * scalar object) 
00054      */
00055     oid             my_registration_oid[] =
00056         { 1, 3, 6, 1, 4, 1, 8072, 2, 1, 1, 0 };
00057 
00058     /*
00059      * a debugging statement.  Run the agent with -Dexample_scalar_int to see
00060      * the output of this debugging statement. 
00061      */
00062     DEBUGMSGTL(("example_scalar_int",
00063                 "Initalizing example scalar int.  Default value = %ld\n",
00064                 example1));
00065 
00066     /*
00067      * the line below registers our "example1" variable above as
00068      * accessible and makes it writable.  A read only version of the
00069      * same registration would merely call
00070      * register_read_only_long_instance() instead.
00071      * 
00072      * If we wanted a callback when the value was retrieved or set
00073      * (even though the details of doing this are handled for you),
00074      * you could change the NULL pointer below to a valid handler
00075      * function. 
00076      */
00077     netsnmp_register_long_instance("my example int variable",
00078                                   my_registration_oid,
00079                                   OID_LENGTH(my_registration_oid),
00080                                   &example1, NULL);
00081 
00082     DEBUGMSGTL(("example_scalar_int",
00083                 "Done initalizing example scalar int\n"));
00084 }