Content-type: text/html
void init_mib(void);
int add_mibdir(const char *dirname);
void init_mib_internals(void);
struct tree *netsnmp_read_module(const char *name);
struct tree *read_mib(const char *filename);
struct tree *read_all_mibs(void);
int add_module_replacement(const char *old_module,
const char *new_module,
const char *tag, int len);
void snmp_set_mib_warnings(int level);
void snmp_set_mib_errors( int level);
void snmp_set_save_descriptions(int save);
int read_objid(const char *input,
oid *objid, size_t *objidlen);
oid *snmp_parse_oid(const char *input,
oid *objid, size_t *objidlen);
int get_module_node(const char *name, const char *module,
oid *objid, size_t *objidlen);
void print_mib(FILE *fp);
void print_objid(const oid *objid, size_t objidlen);
void fprint_objid(FILE *fp,
const oid *objid, size_t objidlen);
int snprint_objid(char *buf, size_t len,
const oid *objid, size_t objidlen);
void print_description(const oid *objid, size_t objidlen, int width);
void fprint_description(FILE *fp,
const oid *objid, size_t objidlen, int width);
int snprint_description(char *buf, size_t len,
const oid *objid, size_t objidlen, int width);
add_mibdir is used to add the specified directory to the path of locations which are searched for files containing MIB modules. Note that this does not actually load the MIB modules located in that directory, but is simply an initialisation step to make them available to netsnmp_read_module. This function returns a count of files found in the directory, or a -1 if there is an error.
init_mib_internals sets up the internal structures, preparatory to reading in MIB modules. It should be called after all calls to add_mibdir, and before any calls to netsnmp_read_module.
init_mib
is a convenience function that configures the MIB directory search path (using
add_mibdir
), set up the internal MIB framework (using
init_mib_internals
), and then loads the appropriate MIB modules (using
netsnmp_read_module and read_mib).
See the ENVIRONMENTAL VARIABLES section for details.
It should be called before any other
routine that manipulates or accesses the MIB tree.
shutdown_mib will clear the information that was gathered by netsnmp_read_module, add_mibdir and add_module_replacement. It is strongly recommended that one does not invoke shutdown_mib while there are SNMP sessions being actively managed.
netsnmp_read_module takes the name of a MIB module (which need not be the same as the name of the file that contains the module), locates this within the configured list of MIB directories, and loads the definitions from the module into the active MIB tree. It also loads any MIB modules listed in the IMPORTS clause of this module.
read_mib is similar, but takes the name of the file containing the MIB module. Note that this file need not be located within the MIB directory search list (although any modules listed in the IMPORTS clause do).
read_all_mibs will read in all the MIB modules found on the MIB directory search list.
In general the parser is silent about what strangenesses it sees in the MIB files. To get warnings reported, call snmp_set_mib_warnings with a level of 1 (or 2 for even more warnings).
add_module_replacement can be used to allow new MIB modules to obsolete older ones, without needing to amend the IMPORTS clauses of other modules. It takes the names of the old and new modules, together with an indication of which portions of the old module are affected.
tag | len | load the new module when: |
NULL | 0 | always (the old module is a strict subset of the new) |
name | 0 | for the given tag only |
name | non-0 | for any identifier with this prefix |
read_objid takes a string containing a textual version of an object identifier (in either numeric or descriptor form), and transforms this into the corresponding list of sub-identifiers. This is returned in the output parameter, with the number of sub-identifiers returned via out_len. When called, out_len must hold the maximum length of the output array. If multiple object identifiers are being processed, then this length should be reset before each call. This function returns a value of 1 if it succeeds in parsing the string and 0 otherwise.
snmp_parse_oid is similar, but returns a pointer to the parsed OID buffer (or NULL).
get_module_node
takes a descriptor and the name of a module, and returns the corresponding
oid list, in the same way as
read_objid
above.
If the module name is specified as "ANY", then this routine will
assume that the descriptor given is unique within the tree, and will
return the matching entry. If this assumption is invalid, then the
behaviour as to which variable is returned is implementation
dependent.
print_objid will take an object identifier (as returned by read_objid, snmp_parse_oid or get_module_node), and prints the textual form of this OID to the standard output.
fprint_objid does the same, but prints to the FILE pointer specified by the initial parameter.
snprint_objid prints the same information into the buffer pointed to by buf which is of length len. It returns the number of characters printed, or -1 if the buffer was not large enough. In the latter case, buf will typically contain a truncated version of the information (but this behaviour is not guaranteed).
print_description, fprint_description, and snprint_description take a similar object identifier and print out a version of the MIB definition for that object, together with the full OID. The width argument controls how the OID is layed out.
By default the parser does not save descriptions since they may be huge. In order to be able to print them, it is necessary to invoke snmp_set_save_descriptions(1)before calling init_mib (or similar).
The main use of environmental variables with respect to these API calls is to configure which MIB modules should be loaded, and where they are located.