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

NAME

6       mib2c -- generate template code for extending the agent
7

SYNOPSIS

9       mib2c  [-h]  -c  CONFIGFILE  [-I  PATH]  [-f  OUTNAME]  [-i][-s][-q][-S
10       VAR=VAL] MIBNODE
11

DESCRIPTION

13       The mib2c tool is designed to take  a  portion  of  the  MIB  tree  (as
14       defined  by  a  MIB file) and generate the template C code necessary to
15       implement the relevant management objects within it.
16
17       In order to implement a new MIB module, three files are necessary:
18
19       - MIB definition file
20       - C header file
21       - C implementation file.
22
23       The mib2c tool uses the MIB definition file to produce the two  C  code
24       files.  Thus, mib2c generates a template that you can edit to add logic
25       necessary to obtain information from the operating system  or  applica‐
26       tion to complete the module.
27
28       MIBNODE  is  the top level mib node you want to generate code for.  You
29       must give mib2c a mib node (e.g. ifTable) on the command  line,  not  a
30       mib file.  This is the single most common mistake.
31
32       The mib2c tool accepts both SMIv1 and SMIv2 MIBs.
33
34       mib2c needs to be able to find and load a MIB file in order to generate
35       C code for the MIB. To enable mib2c to find the MIB file, set the  MIBS
36       environment variable to include the MIB file you are using.  An example
37       of setting this environment variable is:
38
39          MIBS=+NET-SNMP-TUTORIAL-MIB
40
41          or
42
43          MIBS=ALL
44
45       The first example ensures that mib2c  finds  the  NET-SNMP-TUTORIAL-MIB
46       mib,  in  addition  to the default MIB modules. The default list of MIB
47       modules is set when the suite is first configured and built  and  basi‐
48       cally  corresponds to the list of modules that the agent supports.  The
49       second example ensures that mib2c finds all MIBs in the search location
50       for   MIB   files.  The  default  search  location  for  MIB  files  is
51       /usr/share/snmp/mibs. This search location can be modified by the  MIB‐
52       DIRS environment variable.
53
54       Both  the  MIB  files to be loaded and the MIB file search location can
55       also be configured in the snmp.conf file. Please see  snmp.conf(5)  for
56       more information.
57
58       The  generated *.c and *.h files will be created in the current working
59       directory.
60

OPTIONS

62       -h     Display a help message.
63
64       -c CONFIGFILE
65              Use CONFIGFILE  when  generating  code.   These  files  will  be
66              searched  for  first  in  the  current directory and then in the
67              /usr/share directory (which is where the default mib2c  configu‐
68              ration  files  can be found).  Running mib2c without the -c CON‐
69              FIGFILE option will display a description of  the  valid  values
70              for  CONFIGFILE,  that is, the available config files, including
71              new ones that you might author.
72
73              For example,
74
75              % mib2c ifTable
76
77              will display a description of the currently available values for
78              CONFIGFILE.
79
80              The following values are supported for CONFIGFILE:
81
82              mib2c.mfd.conf
83              mib2c.scalar.conf
84              mib2c.int_watch.conf
85              mib2c.iterate.conf
86              mib2c.create-dataset.conf
87              mib2c.array-user.conf
88              mib2c.column_defines.conf
89              mib2c.column_enums.conf
90
91              GENERATING CODE FOR SCALAR OBJECTS:
92
93              If you're writing code for some scalars, run:
94
95                   mib2c -c mib2c.scalar.conf MIBNODE
96
97              If  you  want  to  magically  "tie" integer variables to integer
98              scalars, use:
99
100                   mib2c -c mib2c.int_watch.conf MIBNODE
101
102              GENERATING CODE FOR TABLES:
103
104              The recommended configuration file for tables is  the  MIBs  for
105              Dummies,  or  MFD,  configuration  file. It hides as much of the
106              SNMP details as possible, generating small, easy  to  understand
107              functions.   It  is  also  the most flexible and well documented
108              configuration     file.      See     the      agent/mibgroup/if-
109              mib/ifTable/ifTable*.c files for an example:
110
111                      mib2c -c mib2c.mfd.conf MIBNODE
112
113              If your table data is kept somewhere else (e.g. it's in the ker‐
114              nel and not in the memory of the agent itself) and you  need  to
115              "iterate"  over it to find the right data for the SNMP row being
116              accessed.  See the agent/mibgroup/mibII/vacm_context.c file  for
117              an example:
118
119                   mib2c -c mib2c.iterate.conf MIBNODE
120
121              If  your  table data is kept in the agent (i.e. it's not located
122              in an external source) and is purely data driven  (i.e.  you  do
123              not  need  to  perform  any  work  when  a set occurs).  See the
124              agent/mibgroup/examples/data_set.c file for an example of such a
125              table:
126
127                   mib2c -c mib2c.create-dataset.conf MIBNODE
128
129              If  your  table data is kept in the agent (i.e. it's not located
130              in an external source), and you can keep your data sorted by the
131              table index but you do need to perform work when a set occurs:
132
133                   mib2c -c mib2c.array-user.conf MIBNODE
134
135              GENERATING HEADER FILE DEFINITIONS
136
137              To  generate  just a header with a define for each column number
138              in your table:
139
140                   mib2c -c mib2c.column_defines.conf MIBNODE
141
142              To generate just a header with a define for each  enum  for  any
143              column containing enums:
144
145                   mib2c -c mib2c.column_enums.conf MIBNODE
146
147                   GENERATING CODE FOR THE 4.X LINE OF CODE (THE OLDER API)
148
149                   mib2c -c mib2c.old-api.conf MIBNODE
150
151       -IPATH Search  for  configuration files in PATH.  Multiple paths can be
152              specified using multiple -I switches or  by  using  one  with  a
153              comma separated list of paths in it.
154
155       -f OUTNAME
156              Places  the  output code into OUTNAME.c and OUTNAME.h. Normally,
157              mib2c will place the output code into files which correspond  to
158              the  table  names  it  is generating code for, which is probably
159              what you want anyway.
160
161       -i     Do not run indent on the resulting code.
162
163       -s     Do not look for MIBNODE.sed and run sed on the  resulting  code.
164              This is useful to shorten long mib variable names in the code.
165
166       -q     Run  in  "quiet" mode, which minimizes the status messages mib2c
167              generates.
168
169       -SVAR=VAL
170              Preset a variable VAR, in the mib2c.*.conf file,  to  the  value
171              VAL.   None   of   the   existing   mib2c   configuration  files
172              (mib2c.*.conf) currently makes use of this feature, however,  so
173              this option should be considered available only for future use.
174

EXAMPLES

176       The  following generates C template code for the header and implementa‐
177       tion files to implement UCD-DEMO-MIB::ucdDemoPublic.
178
179              % mib2c -c mib2c.scalar.conf ucdDemoPublic
180              writing to ucdDemoPublic.h
181              writing to ucdDemoPublic.c
182              running indent on ucdDemoPublic.h
183              running indent on ucdDemoPublic.c
184
185       The resulting ucdDemoPublic.c and ucdDemoPublic.h files  are  generated
186       the current working directory.
187
188       The  following generates C template code for the header and implementa‐
189       tion files  for the module to implement TCP-MIB::tcpConnTable.
190
191              % mib2c -c mib2c.iterate.conf tcpConnTable
192              writing to tcpConnTable.h
193              writing to tcpConnTable.c
194              running indent on tcpConnTable.h
195              running indent on tcpConnTable.c
196
197       The resulting tcpConnTable.c and tcpConnTable.h files are generated  in
198       the current working directory.
199

SEE ALSO

201       snmpcmd(1), snmp.conf(5)
202
203
204
205V5.9                              05 Apr 2010                         MIB2C(1)
Impressum