NETSNMP_MIB_API(3)
β¨ NAME β¨
okay bestie, gather round, because this is the netsnmp_mib_api functions page β the whole girlboss crew of MIB-handling calls:
add_mibdir, netsnmp_init_mib, shutdown_mib, netsnmp_read_module, read_mib, read_all_mibs, add_module_replacement, snmp_set_mib_errors, snmp_set_mib_warnings, snmp_set_save_descriptions, read_objid, snmp_parse_oid, get_module_node, print_mib, print_objid, fprint_objid, snprint_objid, print_description, fprint_description, snprint_description β yes all of them, they're a package deal π
π SYNOPSIS π
#include <net-snmp/mib_api.h>
π Initialisation and Shutdown π
int add_mibdir(const char *dirname);
void netsnmp_init_mib(void);
void shutdown_mib(void);
π Reading and Parsing MIBs π
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);
π Searching the MIB Tree π
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);
π¨οΈ Output π¨οΈ
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);
π DESCRIPTION π
so the way this works is the MIB-module functions split into four little friend groups: initialisation & shutdown, reading in & parsing MIB files, searching the MIB tree, and output routines. four groups. iconic behaviour, honestly.
πΈ Initialisation and Shutdown πΈ
add_mibdir adds the directory you give it to the path of locations that get searched for files containing MIB modules. and listen β this does not actually load the MIB modules sitting in that directory, it's just an init step so they're available to netsnmp_read_module later. it returns a count of files found in the directory, or a -1 if something went wrong. call it before you invoke netsnmp_init_mib, ok? π«Ά
netsnmp_init_mib configures the MIB directory search path (using add_mibdir), sets up the internal MIB framework, and then loads the appropriate MIB modules (using netsnmp_read_module and read_mib). the ENVIRONMENTAL VARIABLES section has the deets if you're nosy (affectionate). it should be called before any other routine that manipulates or accesses the MIB tree β but after any additional add_mibdir calls. order matters bestie, it's giving choreography.
shutdown_mib clears the info that was gathered by netsnmp_read_module, add_mibdir and add_module_replacement.
π¨ strongly recommended: do NOT invoke shutdown_mib while there are SNMP sessions being actively managed. just... don't. that's a chaos move and we don't do those.
π Reading and Parsing MIBs π
netsnmp_read_module takes the name of a MIB module (which does not have to be the same as the name of the file containing the module, plot twist), locates it within the configured list of MIB directories, and loads the definitions from that module into the active MIB tree. it also loads any MIB modules listed in the IMPORTS clause of this module. it's bringing its friends, as it should π
read_mib is similar, but takes the name of the file containing the MIB module. note that this file does not need to be located within the MIB directory search list β although any modules listed in the IMPORTS clause do need to be.
read_all_mibs reads in all the MIB modules found on the MIB directory search list. all of them. the whole roster.
in general, the parser is silent about what strangenesses it sees in the MIB files (it's a "no thoughts head empty" parser, lowkey). to get warnings reported, call snmp_set_mib_warnings with a level of 1 β or 2 for even more warnings, if you're built different.
add_module_replacement lets new MIB modules obsolete older ones, without needing to amend the IMPORTS clauses of other modules. it takes the names of the old and new modules, plus an indication of which portions of the old module are affected:
tag=NULL,len=0β always (the old module is a strict subset of the new)tag=name,len=0β for the given tag onlytag=name,len= non-0 β for any identifier with this prefix
it can also be used to handle errors in the module identifiers used in MIB IMPORTS clauses β like referring to RFC1213 instead of RFC1213-MIB. we've all had a typo era, no judgement π₯°
π Searching the MIB Tree π
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 comes back 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 you're processing multiple object identifiers, reset this length before each call. this function returns 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, same way as read_objid above. if the module name is specified as "ANY", then this routine will assume the descriptor given is unique within the tree, and will return the matching entry.
π if that assumption is invalid, then the behaviour as to which variable is returned is implementation dependent. so like... unpredictable. not cute. just don't rely on it.
π¨οΈ Output π¨οΈ
print_mib prints out a representation of the currently active MIB tree to the specified FILE pointer.
print_objid takes an object identifier (as returned by read_objid, snmp_parse_oid or get_module_node), and prints the textual form of this OID to 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 that latter case, buf will typically contain a truncated version of the information β but that behaviour is not guaranteed, so don't get comfy with it.
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 laid out.
by default, the parser does not save descriptions, because they may be huge (they're doing the most, fr). in order to be able to print them, it is necessary to invoke snmp_set_save_descriptions(1) before calling init_mib (or similar). yes, before. timing is everything β¨
π ENVIRONMENT VARIABLES π
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. honestly? very demure, very mindful config.
π MIBDIRS
a colon-separated list of directories to search for MIB modules. default: /usr/share/snmp/mibs used by init_mib, netsnmp_read_module, read_all_mibs and (implicitly) by read_mib.
π MIBS
a colon-separated list of MIB modules to load. the default list of modules will depend on how the Net-SNMP software was originally compiled, but is typically:
IP-MIB:IF-MIB:TCP-MIB:UDP-MIB:SNMPv2-MIB:RFC1213-MIB:
UCD-SNMP-MIB:HOST-RESOURCES-MIB
if the value of the MIBS environmental variable starts with a '+' character, then these MIB modules will be added to the default list. otherwise these modules (plus any that they IMPORT from) will be loaded instead of the default list.
if the MIBS environmental variable has the value ALL then read_all_mibs will be called to load the full collection of all available MIB modules. the whole squad. no cap.
used by init_mib only.
π MIBFILES
a colon-separated list of files to load. default: (none) used by init_mib only.
π SEE ALSO π
netsnmp_session_api(3), netsnmp_pdu_api(3), netsnmp_varbind_api(3)
okay that's the whole thing bestie, you ate that ππ and for the record? this was Net-SNMP V5.9.5.2, dated 13 Aug 2010. ancient. historic. iconic. mwah ππ¦β¨
π¦ where this page comes from
- alpine 3.23: net-snmp-doc 5.9.5.2-r0 Β· Net-SNMP
- alpine 3.24: net-snmp-doc 5.9.5.2-r0 Β· Net-SNMP
- arch rolling: net-snmp 5.9.5.2-2 Β· BSD
- fedora 44: net-snmp-devel 1:5.9.5.2-4.fc44 Β· MIT-CMU AND BSD-3-Clause AND MIT
- fedora 44: net-snmp-devel 1:5.9.5.2-4.fc44 Β· MIT-CMU AND BSD-3-Clause AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms