Debian Codegraph @

agent/mibgroup/examples/scalar_int.c

raw
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-features.h>
27 #include <net-snmp/net-snmp-includes.h>
28 #include <net-snmp/agent/net-snmp-agent-includes.h>
29
30 /*
31 * if --enable-minimalist has been turned on, we need to register
32 * the support we need so the needed functions aren't removed at compile time
33 */
34 netsnmp_feature_require(long_instance);
35
36 /*
37 * Then, we declare the variables we want to be accessed
38 */
39 static long example1 = 42; /* default value */
40
41 /*
42 * our initialization routine, automatically called by the agent
43 * (to get called, the function name must match init_FILENAME())
44 */
45 void
46 init_scalar_int(void)
47 {
48 /*
49 * the OID we want to register our integer at. This should be a
50 * fully qualified instance. In our case, it's a scalar at:
51 * NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 (note the
52 * trailing 0 which is required for any instantiation of any
53 * scalar object)
54 */
55 oid my_registration_oid[] =
56 { 1, 3, 6, 1, 4, 1, 8072, 2, 1, 1, 0 };
57
58 /*
59 * a debugging statement. Run the agent with -Dexample_scalar_int to see
60 * the output of this debugging statement.
61 */
62 DEBUGMSGTL(("example_scalar_int",
63 "Initalizing example scalar int. Default value = %ld\n",
64 example1));
65
66 /*
67 * the line below registers our "example1" variable above as
68 * accessible and makes it writable. A read only version of the
69 * same registration would merely call
70 * register_read_only_long_instance() instead.
71 *
72 * If we wanted a callback when the value was retrieved or set
73 * (even though the details of doing this are handled for you),
74 * you could change the NULL pointer below to a valid handler
75 * function.
76 */
77 netsnmp_register_long_instance("my example int variable",
78 my_registration_oid,
79 OID_LENGTH(my_registration_oid),
80 &example1, NULL);
81
82 DEBUGMSGTL(("example_scalar_int",
83 "Done initalizing example scalar int\n"));
84 }