added files
[bcm963xx.git] / userapps / opensource / net-snmp / agent / mibgroup / examples / scalar_int.c
1 /**  @example scalar_int.c
2  *  This example creates some scalar registrations that allows
3  *  some simple variables to be accessed via SNMP.  In a more
4  *  realistic example, it is likely that these variables would also be
5  *  manipulated in other ways outside of SNMP gets/sets.
6  *
7  *  If this module is compiled into an agent, you should be able to
8  *  issue snmp commands that look something like (authentication
9  *  information not shown in these commands):
10  *
11  *  - snmpget localhost netSnmpExampleInteger.0
12  *  - netSnmpExampleScalars = 42
13  *
14  *  - snmpset localhost netSnmpExampleInteger.0 = 1234
15  *  - netSnmpExampleScalars = 1234
16  *  
17  *  - snmpget localhost netSnmpExampleInteger.0
18  *  - netSnmpExampleScalars = 1234
19  *
20  */
21
22 /*
23  * start be including the appropriate header files 
24  */
25 #include <net-snmp/net-snmp-config.h>
26 #include <net-snmp/net-snmp-includes.h>
27 #include <net-snmp/agent/net-snmp-agent-includes.h>
28
29 /*
30  * Then, we declare the variables we want to be accessed 
31  */
32 static int      example1 = 42;  /* default value */
33
34 /*
35  * our initialization routine, automatically called by the agent 
36  * (to get called, the function name must match init_FILENAME())
37  */
38 void
39 init_scalar_int(void)
40 {
41     /*
42      * the OID we want to register our integer at.  This should be a
43      * fully qualified instance.  In our case, it's a scalar at:
44      * NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 (note the
45      * trailing 0 which is required for any instantiation of any
46      * scalar object) 
47      */
48     oid             my_registration_oid[] =
49         { 1, 3, 6, 1, 4, 1, 8072, 2, 1, 1, 0 };
50
51     /*
52      * a debugging statement.  Run the agent with -Dexample_scalar_int to see
53      * the output of this debugging statement. 
54      */
55     DEBUGMSGTL(("example_scalar_int",
56                 "Initalizing example scalar int.  Default value = %d\n",
57                 example1));
58
59     /*
60      * the line below registers our "example1" variable above as
61      * accessible and makes it writable.  A read only version of the
62      * same registration would merely call
63      * register_read_only_int_instance() instead.
64      * 
65      * If we wanted a callback when the value was retrieved or set
66      * (even though the details of doing this are handled for you),
67      * you could change the NULL pointer below to a valid handler
68      * function. 
69      */
70     netsnmp_register_int_instance("my example int variable",
71                                   my_registration_oid,
72                                   OID_LENGTH(my_registration_oid),
73                                   &example1, NULL);
74
75     DEBUGMSGTL(("example_scalar_int",
76                 "Done initalizing example scalar int\n"));
77 }