extern void init_example (void); extern FindVarMethod var_example;If the module includes any tables, or other collections of variables that are implemented in separate routines, then this second definition will be repeated for each of these.
extern writeMethod write_varName;These prototypes are in fact typedef'ed in
< agent/snmp_vars.h >.
config_require( util_funcs )(which is produced automatically by
mib2c). This same syntax can be used to trigger the inclusion of other related modules. An example of this can be seen in
mibII/route_write.hwhich relies on the
config_require( mibII/ip )
One use of this directive is to define a module group, by supplying a header
file consisting exclusively of such config_require directives. It can then
be included or excluded from the agent very simply.
Examples of this can be seen in
mibgroup/host.h, which list the consituent sub-modules
of the MIB-II and Host Resources MIBs respectively.
config_add_mib( HOST-RESOURCES-MIB )This is used to add the MIB file being implemented to the default list of MIBs loaded by such commands. This means that querying the agent will return informative names and values, rather than the raw numeric forms that SNMP actually works with. Of course, it is always possible for the utilities to specify that this MIB should be loaded anyway. But specifying this file within the module header file is a useful hint that a particular MIB should be loaded, without needing to ask for it explicitly.
mib2c, but most handcrafted modules have tended to define these as part of the header file, probably for clarity.
The only necessity is that the names and values are distinct (or more
precisely, the values are distinct within a single variable handling routine).
In practise, they tend to be defined using integers incrementing from 1,
or as the same as the final sub-identifier of the corresponding MIB object
(or indeed both, as these are frequently themselves successive integers).
This is not mandatory, and a counter-example can be seen in the example module, where two of the object form a sub-tree, and the corresponding magic numbers are based on the final two sub-identifiers (to ensure that the values are unique). But this construction is definitely unusual, and the majority of modules simply use successive integers.
#ifndef/#define/#endifstatements surrounding the whole file. This is used to ensure that the header file is only included once by any source code file (or more accurately, that there is no effect if it is inadvertantly included a second time).
Having finished all the preparatory work (or let
with it), the
next part starts to look at the code file that actually implements