---
name: "snprint_description"
section: "3"
platform: "linux"
package: "net-snmp"
version: "5.9.5.2-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/netsnmp_mib_api"
---

# snprint\_description(3)

netsnmp\_mib\_api functions

Part of [netsnmp\_mib\_api(3)](/netsnmp_mib_api/3.md).

## NAME

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 - netsnmp\_mib\_api functions

## 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

The functions dealing with MIB modules fall into four groups - those dealing with initialisation and shutdown, with reading in and parsing MIB files, with searching the MIB tree, and output routines.

### Initialisation and Shutdown

**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.   It should be called *before* invoking **netsnmp\_init\_mib**.

**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**). See the ENVIRONMENTAL VARIABLES section for details.\
 It should be called before any other routine that manipulates or accesses the MIB tree (but after any additional **add\_mibdir** calls).

**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.

### Reading and Parsing MIBs

**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 |

It can also be used to handle errors in the module identifiers used in MIB IMPORTS clauses (such as referring to *RFC1213* instead of *RFC1213-MIB*).

### 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 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.\

### Output

**print\_mib** will print out a representation of the currently active MIB tree to the specified FILE pointer.

**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 laid 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).

## 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.

- 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.

-

  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_session_api/3.md), [netsnmp\_pdu\_api(3)](/netsnmp_pdu_api/3.md), [netsnmp\_varbind\_api(3)](/netsnmp_varbind_api/3.md)
