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

NAME

6       init_mib,    add_mibdir,    init_mib_internals,    shutdown_mib,   net‐
7       snmp_read_module,  read_mib,   read_all_mibs,   add_module_replacement,
8       read_objid,   snmp_parse_oid,   get_module_node,   snmp_set_mib_errors,
9       snmp_set_mib_warnings,      snmp_set_save_descriptions,      print_mib,
10       print_objid,     fprint_objid,     snprint_objid,    print_description,
11       fprint_description, snprint_description - mib_api functions
12

SYNOPSIS

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

DESCRIPTION

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

ENVIRONMENT VARIABLES

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

SEE ALSO

201       snmp_api(3), output_api(3)
202
203
204
2054.2 Berkeley Distribution         06 Mar 2002                       MIB_API(3)
Impressum