1NETSNMP_MIB_API(3)                 Net-SNMP                 NETSNMP_MIB_API(3)
2
3
4

NAME

6       add_mibdir,    netsnmp_init_mib,   shutdown_mib,   netsnmp_read_module,
7       read_mib, read_all_mibs,  add_module_replacement,  snmp_set_mib_errors,
8       snmp_set_mib_warnings,      snmp_set_save_descriptions,     read_objid,
9       snmp_parse_oid, get_module_node, print_mib, print_objid,  fprint_objid,
10       snprint_objid,  print_description, fprint_description, snprint_descrip‐
11       tion - netsnmp_mib_api functions
12

SYNOPSIS

14       #include <net-snmp/mib_api.h>
15
16   Initialisation and Shutdown
17       int add_mibdir(const char *dirname);
18
19       void netsnmp_init_mib(void);
20       void shutdown_mib(void);
21
22   Reading and Parsing MIBs
23       struct tree *netsnmp_read_module(const char *name);
24       struct tree *read_mib(const char *filename);
25       struct tree *read_all_mibs(void);
26
27       int add_module_replacement(const char *old_module,
28                                  const char *new_module,
29                                  const char *tag, int len);
30
31       void snmp_set_mib_warnings(int level);
32       void snmp_set_mib_errors(int level);
33       void snmp_set_save_descriptions(int save);
34
35   Searching the MIB Tree
36       int  read_objid(const char *input,
37                       oid *objid, size_t *objidlen);
38       oid *snmp_parse_oid(const char *input,
39                       oid *objid, size_t *objidlen);
40       int  get_module_node(const char *name, const char *module,
41                       oid *objid, size_t *objidlen);
42
43   Output
44       void  print_mib(FILE *fp);
45
46       void  print_objid(const oid *objid, size_t objidlen);
47       void fprint_objid(FILE *fp,
48                         const oid *objid, size_t objidlen);
49       int snprint_objid(char *buf, size_t len,
50                         const oid *objid, size_t objidlen);
51
52       void  print_description(const oid *objid, size_t objidlen, int width);
53       void fprint_description(FILE *fp,
54                               const oid *objid, size_t objidlen, int width);
55       int snprint_description(char *buf, size_t len,
56                               const oid *objid, size_t objidlen, int width);
57

DESCRIPTION

59       The functions dealing with MIB modules fall into four  groups  -  those
60       dealing  with  initialisation and shutdown, with reading in and parsing
61       MIB files, with searching the MIB tree, and output routines.
62
63   Initialisation and Shutdown
64       add_mibdir is used to add the specified directory to the path of  loca‐
65       tions  which  are searched for files containing MIB modules.  Note that
66       this does not actually load the MIB modules located in that  directory,
67       but  is  simply  an  initialisation step to make them available to net‐
68       snmp_read_module.  This function returns a count of files found in  the
69       directory,  or  a  -1 if there is an error.  It should be called before
70       invoking netsnmp_init_mib.
71
72       netsnmp_init_mib  configures  the  MIB  directory  search  path  (using
73       add_mibdir  ),  sets  up the internal MIB framework, and then loads the
74       appropriate MIB modules (using netsnmp_read_module and read_mib).   See
75       the ENVIRONMENTAL VARIABLES section for details.
76       It  should  be  called  before  any  other  routine that manipulates or
77       accesses the MIB tree (but after any additional add_mibdir calls).
78
79       shutdown_mib will clear the  information  that  was  gathered  by  net‐
80       snmp_read_module,   add_mibdir   and   add_module_replacement.   It  is
81       strongly recommended that one does not invoke shutdown_mib while  there
82       are SNMP sessions being actively managed.
83
84   Reading and Parsing MIBs
85       netsnmp_read_module  takes  the name of a MIB module (which need not be
86       the same as the name of the file that  contains  the  module),  locates
87       this within the configured list of MIB directories, and loads the defi‐
88       nitions from the module into the active MIB tree.  It  also  loads  any
89       MIB modules listed in the IMPORTS clause of this module.
90
91       read_mib  is similar, but takes the name of the file containing the MIB
92       module.  Note that this file need not be located within the MIB  direc‐
93       tory  search  list  (although  any modules listed in the IMPORTS clause
94       do).
95
96       read_all_mibs will read in all the MIB modules found on the MIB  direc‐
97       tory search list.
98
99       In general the parser is silent about what strangenesses it sees in the
100       MIB files. To get warnings reported, call snmp_set_mib_warnings with  a
101       level of 1 (or 2 for even more warnings).
102
103       add_module_replacement can be used to allow new MIB modules to obsolete
104       older ones, without needing to amend the IMPORTS clauses of other  mod‐
105       ules.   It takes the names of the old and new modules, together with an
106       indication of which portions of the old module are affected.
107
108              tag      len       load the new module when:
109              NULL     0         always (the old module is a strict subset of
110                                 the new)
111              name     0         for the given tag only
112              name     non-0     for any identifier with this prefix
113       It can also be used to handle errors in the module identifiers used  in
114       MIB   IMPORTS   clauses  (such  as  referring  to  RFC1213  instead  of
115       RFC1213-MIB).
116
117   Searching the MIB Tree
118       read_objid takes a string containing a textual  version  of  an  object
119       identifier  (in either numeric or descriptor form), and transforms this
120       into the corresponding list of sub-identifiers.  This  is  returned  in
121       the  output  parameter, with the number of sub-identifiers returned via
122       out_len.  When called, out_len must hold the maximum length of the out‐
123       put  array.   If  multiple object identifiers are being processed, then
124       this length should be reset before each call.  This function returns  a
125       value of 1 if it succeeds in parsing the string and 0 otherwise.
126
127       snmp_parse_oid is similar, but returns a pointer to the parsed OID buf‐
128       fer (or NULL).
129
130       get_module_node takes a descriptor  and  the  name  of  a  module,  and
131       returns  the  corresponding  oid  list,  in  the same way as read_objid
132       above.
133       If the module name is specified as "ANY", then this routine will assume
134       that  the  descriptor  given is unique within the tree, and will return
135       the matching entry.  If this assumption is invalid, then the  behaviour
136       as to which variable is returned is implementation dependent.
137
138   Output
139       print_mib  will  print out a representation of the currently active MIB
140       tree to the specified FILE pointer.
141
142       print_objid will take an object identifier (as returned by  read_objid,
143       snmp_parse_oid or get_module_node), and prints the textual form of this
144       OID to the standard output.
145
146       fprint_objid does the same, but prints to the FILE pointer specified by
147       the initial parameter.
148
149       snprint_objid prints the same information into the buffer pointed to by
150       buf which is of length  len.   It  returns  the  number  of  characters
151       printed, or -1 if the buffer was not large enough.  In the latter case,
152       buf will typically contain a truncated version of the information  (but
153       this behaviour is not guaranteed).
154
155       print_description,  fprint_description,  and snprint_description take a
156       similar object identifier and print out a version of the MIB definition
157       for  that  object,  together with the full OID. The width argument con‐
158       trols how the OID is layed out.
159
160       By default the parser does not save  descriptions  since  they  may  be
161       huge.   In  order  to  be able to print them, it is necessary to invoke
162       snmp_set_save_descriptions(1)before calling init_mib (or similar).
163

ENVIRONMENT VARIABLES

165       The main use of environmental variables with respect to these API calls
166       is  to configure which MIB modules should be loaded, and where they are
167       located.
168
169       MIBDIRS   A colon separated list of directories to search for MIB  mod‐
170                 ules.
171                 Default: /usr/share/snmp/mibs
172                 Used  by  init_mib,  netsnmp_read_module,  read_all_mibs  and
173                 (implicitly) by read_mib.
174
175       MIBS      A colon separated list of MIB modules to load.
176                 The default list of modules will depend on how  the  Net-SNMP
177                 software was originally compiled, but is typically:
178                 IP-MIB:IF-MIB:TCP-MIB:UDP-MIB:SNMPv2-MIB:RFC1213-MIB:
179                 UCD-SNMP-MIB:HOST-RESOURCES-MIB
180
181                 If the value of the MIBS environmental variable starts with a
182                 '+'  character,  then  these MIB modules will be added to the
183                 default list.  Otherwise these modules (plus  any  that  they
184                 IMPORT from) will be loaded instead of the default list.
185
186                 If  the  MIBS  environmental  variable has the value ALL then
187                 read_all_mibs will be called to load the full  collection  of
188                 all available MIB modules.
189
190                 Used by init_mib only.
191
192       MIBFILES  A colon separated list of files to load.
193                 Default: (none)
194                 Used by init_mib only.
195

SEE ALSO

197       netsnmp_session_api(3), netsnmp_pdu_api(3), netsnmp_varbind_api(3)
198
199
200
201V5.9                              13 Aug 2010               NETSNMP_MIB_API(3)
Impressum