smi_config(3)
π NAME π
smiInit, smiExit, smiSetErrorLevel, smiGetFlags, smiSetFlags, smiLoadModule, smiGetPath, smiSetPath, smiReadConfig β the SMI library configuration routines, aka the little gremlins that set up your whole MIB world β¨
okay so this is smi_config(3) from the SMI Management Information Library bestie, and it's literally the "get your life together before you do anything else" page of libsmi. let's go π«Ά
β¨ SYNOPSIS β¨
#include <smi.h>
int smiInit(const char *tag);
int smiExit();
void smiSetErrorLevel(int level);
int smiGetFlags();
void smiSetFlags(int userflags);
char *smiLoadModule(char *module);
int smiIsLoaded(char *module);
char *smiGetPath();
int smiSetPath(char *path);
int smiSetSeverity(char *pattern, int severity);
int smiReadConfig(char *filename, const char *tag);
void smiSetErrorHandler(SmiErrorHandler *smiErrorHandler);
typedef void (SmiErrorHandler) (char *path, int line,
int severity, char *msg, char *tag);
πΈ DESCRIPTION πΈ
these functions do the initialization + tweaking thing for the SMI library. setup era, fr fr.
π smiInit()
this one is the first SMI function you should call in your app, no cap. it sets up all its internal structures. if tag is not NULL, the global configuration file and (on UNIX systems) a user configuration file get read implicitly, if they exist. every global statement and every statement carrying a tag (a tag: prefix) that matches the tag argument gets executed. (peep the CONFIGURATION FILES section below π
). smiInit() returns zero on success, otherwise a negative value. slay or fail, no in between.
it can also flex for multiple sets of MIB data. in that case the tag argument may be prepended by a colon and a name to differentiate the data sets. any library function call after an smiInit("tag:dataset") call is using the specified data set. main character dataset energy π
π¦ smiExit()
call this when your app doesn't need any SMI info anymore, so all the allocated SMI resources get released. it's giving "thanks for coming, close the door on your way out" π
π€ smiSetErrorLevel()
sets the pedantic level (0-9) of the SMI parsers of the SMI library β currently SMIv1/v2 and SMIng. the higher the level, the louder it complains. values up to 3 should be regarded as errors, higher levels could be interpreted as warnings. but note that this classification is some kind of personal taste (ngl same). the default level is 0, since usually only MIB checkers want to tune a higher level.
π© smiGetFlags() / smiSetFlags()
these let you fetch, modify, and set some userflags that control the SMI library's behaviour. the tea:
- if
SMI_FLAG_ERRORSis not set, no error messages are printed at all, keeping the SMI library totally quiet, which might be mandatory for some applications π€« - if
SMI_FLAG_STATSis set, the library prints some module statistics - if
SMI_FLAG_RECURSIVEis set, the library also complains about errors in modules that are read due to import statements - if
SMI_FLAG_NODESCRis set, no description and references strings are stored in memory. this may save a huge amount of memory in case of applications that do not need this information πΎβ¨
π©Ή smiSetSeverity()
lets you set the severity of all errors that have a name prefixed by pattern to the value severity. picky but make it fashion.
π¦ smiLoadModule()
specifies an additional MIB module that the application claims to know, or an additional file path to read. only after a module is made known through this function, iterating retrieval functions and retrieval functions without fully qualified identifiers will return results from this module. smiLoadModule() returns the name of the loaded module, or NULL if it could not be loaded π
π smiIsLoaded()
returns a positive value if the module named module is already loaded, or zero otherwise. simple. iconic.
π£οΈ smiGetPath() / smiSetPath()
these let you fetch, modify, and set the path used to search MIB modules. smiGetPath() returns a copy of the current search path in the form "DIR1:DIR2:...", or NULL if no path is set. the application should free this string if it is no longer needed (leak queen behavior is NOT it). smiSetPath() sets the search path to path.
π smiReadConfig()
reads the configuration file filename. all global statements in the configuration file, plus those statements with a tag (a tag: prefix) that matches the tag argument β if present β are executed.
π¨ smiSetErrorHandler()
lets you set a callback function that gets called by the MIB parsers instead of the builtin default error handler, which prints error messages to stderr. the error handler has to comply with the SmiErrorHandler function type. the path, line, severity, msg, and tag arguements carry the module's pathname, the line number within the module, the error severity level, a textual error message, and a short error name of the error being reported. custom error handler glow-up π«Ά
ποΈ MODULE LOCATIONS ποΈ
the SMI library may retrieve MIB modules from different kinds of resources. currently, SMIv1/v2 and SMIng module files are supported.
if in an smiLoadModule() function call a module is specified by a path name (identified by containing at least one dot or slash character), that is assumed to be the exact file to read. otherwise, if a module is identified by its plain module name, the correspondant file (either SMIv1/2 or SMIng) is searched along a path. this path is initialized with
/usr/share/mibs/ietf:/usr/share/mibs/iana:/usr/share/mibs/irtf:/usr/share/mibs/site:/usr/share/mibs/tubs:/usr/share/pibs/ietf:/usr/share/pibs/site:/usr/share/pibs/tubs
afterwards the optional global and user configuration files are parsed for path commands, and finally the optional SMIPATH environment variable is evaluated π
the path command argument and the environment variable either:
- start with a path separator character (
:on UNIX-like systems,;on MS-Windows systems) to append to the path, or - end with a path separator character to prepend to the path, or
- otherwise completely replace the path.
the path can also be controlled by the smiGetPath() and smiSetPath() functions (see above π).
when files are searched by a given module name, they might have no extension or one of the extensions .my, .smiv2, .sming, .mib, or .txt. however β and this part matters bestie β the MIB module language is identified by the file's content, not by its file name extension. the vibe check is on the inside π
π CONFIGURATION FILES π
SMI library configuration files, read at initialization and on demand by smiReadConfig(), have a simple line oriented syntax. empty lines and those starting with # are ignored. other lines start with an optional tag (prepended by a colon), followed by a command and options dependent on the command. tags are used to limit the scope of a command to those applications that are using this tag.
the commands, bestie:
loadβ used to preload a given MIB module. if multiple modules shall be preloaded, multipleloadcommands must be used. no shortcuts π«pathβ allows to prepend or append components to the MIB module search path or to modify it completely (see also MODULE LOCATIONS above)cacheβ allows to add an additional directory for MIB module lookup as a last resort. the first argument specifies the directory, and the rest of the line starting from the second argument specifies the caching method, which is invoked with the MIB module name appended if the module is found neither in one of the regular directories nor in the cache directory beforehandlevelβ sets the error levelhideβ allows to tune the list of errors that are reported. it raises all errors with names prefixed by the given pattern to severity level9. [Currently, there is no way to list the error names. RTFS: error.c.] π
example configuration (copy it, it's cute):
#
# $HOME/.smirc
#
# add a private directory
path :/usr/home/strauss/lib/mibs
# don't show any errors by default
level 0
# preload some basic modules
load SNMPv2-SMI
load SNMPv2-TC
load SNMPv2-CONF
# want to make smilint shout
smilint: level 8
# but please don't claim about
# any names longer than 32 chars
smilint: hide namelength-32
tcpdump: load DISMAN-SCRIPT-MIB
smiquery: load IF-MIB
smiquery: load DISMAN-SCRIPT-MIB
π FILES π
/etc/smi.confβ global configuration file$HOME/.smircβ user configuration file${prefix}/include/smi.hβ SMI library header file/usr/share/mibs/β SMI module repository directory
π SEE ALSO π
libsmi(3), smi.h
π AUTHOR π
(C) 1999-2001 Frank Strauss, TU Braunschweig, Germany <strauss@ibr.cs.tu-bs.de>
and that's the whole page bestie, you're officially config-pilled π go forth and smiInit() responsibly.
that was IBR, August 22, 2001, and this little page is smi_config(3) π stan libsmi, mwah π
β¨
π¦ where this page comes from
- debian bookworm: libsmi2-dev 0.4.8+dfsg2-16
- debian trixie: libsmi2-dev 0.4.8+dfsg2-17+b1
- ubuntu jammy: libsmi2-dev 0.4.8+dfsg2-16
- ubuntu noble: libsmi2-dev 0.4.8+dfsg2-16.1build1
- ubuntu questing: libsmi2-dev 0.4.8+dfsg2-17
- ubuntu resolute: libsmi2-dev 0.4.8+dfsg2-18
- ubuntu stonking: libsmi2-dev 0.4.8+dfsg2-18
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms