A.5   Running mibcomp

mibcomp generates an output file based on a MIB description file whose name you must specify on the mibcomp command line. The output file contains the C code that declares the MIB tree to the target agent. If you do not specify a name for the output file, mibcomp uses the name OUTPUT. You can specify options on the command line to modify mibcomp's default behavior.

The general form of an mibcomp command is:

mibcomp            [ -ansi ]                        [ -array ] 
            [ -check ]                        [ -exclude module-name.object-name ] 
            [ -inst_oid_len length ]                        [ -inst_str_len length ] 
            [ -k_and_r ]                        [ -l MIB-search-path ]
[ -leaf ] [ -loadtree ] [ -lowmem ] [ -man ] [ -man.h ] [ -mib.c ] [ -nametree ] [ -nowarn ] [ -numbers ] [ -o outfile ] [ -partial ] [ -partialm module-name ] [ -quiet ] [ -readtree ] [ -skel ] [ -skel.h ] [ -start module-name.object-name ] [ -statistics ] [ -stub ] [ @automated-response-file] file1 [ file2... ]

Square brackets indicate optional arguments. The only argument that mibcomp absolutely requires is the name of an input file. You can specify multiple input files on the command line. If a MIB depends on objects or textual conventions defined in another MIB, be sure to list the other MIB first on the command line.

The options -array, -check, -leaf, -loadtree, -man, -man.h, -mib.c, -numbers, -partial, -partialm, -readtree, -skel, -skel.h, and -stub specify output modes, and are described in detail in B. mibcomp Output Formats. No more than one output format option can be selected for a particular run of mibcomp. If you do not select any of these options, mibcomp uses -mib.c as its default output mode.


*   

NOTE: The -ansi and -k_and_r options are mutually exclusive. For use with VxWorks, only the -ansi option should be used.

Most of mibcomp's command line options do not take effect until after mibcomp has finished processing the command line; however, the options -lowmem, -nowarn, and -quiet options are processed immediately when mibcomp encounters them on the command line, as are the names of input files. This means that the order of these options and of input-file names on the command line matters: if you want to suppress warnings that mibcomp generates when it reads a particular file, you must specify -nowarn before the filename. Similarly, -lowmem is only useful if you specify it before any filenames.

You can specify that mibcomp should read arguments from a file (an automated response file). Many MS-DOS programs support automated response files in order to circumvent MS-DOS' 128-character command-line limit. To instruct mibcomp to read commands from a file, use a "@" character immediately followed by the filename. For instance:

mibcomp @cmds.arf

You can use automated response files and other command-line arguments at the same time. mibcomp supports automated response files on all systems, not just MS-DOS.

Commands in an automated response file may be written one to a line, or may be separated by spaces on one or more lines. Lines may be up to 512 characters long. mibcomp treats the sequences ";", "--", and "#" as comment characters; you may use them to embed comments in your automated response files. For instance:

; This is an automated response file. 
rfc1213.mib 
-o mib_ii.c

You may customize options to mibcomp by setting the environment variable MIBCOMP. UNIX and MS-DOS systems both support environment variables. Set the MIBCOMP variable to a list of arguments you want to give to mibcomp. mibcomp executes these arguments before it processes its command line. The most common options generally used with the MIBCOMP environment variable are: -l, -lowmem, -quiet, and -statistics.

A.5.1   Argument Overview

-autoexclude
The -autoexclude option caused the output routines to skip unused nodes.
-ansi
The -ansi option causes any C code generated by this run of mibcomp to use ANSI C function prototyping. This is the default. This option and the -k_and_r option are mutually exclusive.
-array
This output mode is discussed in -array.
-check
The -check option causes mibcomp not to generate an output file. Instead, mibcomp exits immediately after it has finished reading the input files and performing its consistency checks on them.
-exclude module-name.object-name
The -exclude option causes mibcomp to remove objects from compiled MIBs. This option is equivalent to an EXCLUDE keyword with the same argument. Please see section The EXCLUDE Keyword for more information.
-forceinclude
The -forceinclude option has the same effect as a forceinclude operator in the MIB or MIB control files.
-inst_oid_len length
This argument is only meaningful in conjunction with the -man argument. It sets the number of object identifier components that mibcomp reserves for variables which have an instance identifier that is an OBJECT IDENTIFIER. mibcomp defaults to reserving space for 23 components if you don't specify this argument.
-inst_str_len length
This argument is only meaningful in conjunction with the -man argument. It sets the number of octets (bytes) that mibcomp reserves for variables which have an instance identifier that is an OCTET STRING with no size constraint. mibcomp defaults to reserving space for 65 bytes if you don't specify this argument.
-k_and_r
The -k_and_r1 option causes any C code generated by this run of mibcomp to use the "traditional" (non-ANSI) format for function declarations and definitions. This option and the -ansi option are mutually exclusive; -ansi is the default.
-l MIB-search-path
The WindNet SNMPv1/v2c target agent supports search paths for input files. The -l option adds one directory to the search path. You can specify more than one -l option; mibcomp remembers a list of directories to search.
You may want to have one copy of standard MIB files that are shared by all your engineers, rather than having separate copies for each project. You would then use -l to specify the directory where the standard MIBs reside. You may want to set the -l options in your MIBCOMP environment variable, rather than wiring pathnames into Makefiles that use mibcomp.
-leaf
-loadtree
-lowmem
The -lowmem option causes mibcomp to immediately forget an DESCRIPTION or REFERENCE strings it sees when processing the OBJECT-TYPE or NOTIFICATION-TYPE macros. This saves memory and can help when you are running out of memory while compiling a large MIB. Since some of mibcomp's output modes use the DESCRIPTION clause to generate C comments in the output file, using -lowmem results in a slightly less interesting (but also slightly smaller) output file.
-man
-man.h
-mib.c
-mib.c. This is mibcomp's default output mode.
-nametree
-nowarn
The -nowarn option suppresses all mibcomp warning messages. mibcomp still generates messages for fatal errors. You can set this option in your MIBCOMP environment variable, but this is not advisable, since most of mibcomp's warnings indicate potential problems in your MIB. See -quiet.
-numbers
-o outfile
The -o option specifies that you want mibcomp to write its output to outfile. If you do not specify this option, mibcomp writes its output to a file named OUTPUT.
If you want mibcomp to write its output file to the standard output stream, use "-" (a single hyphen character) as the output filename. This is most likely to be useful on a system like UNIX that supports I/O redirection.
-partial
-partialm module-name
-quiet
Normally mibcomp generates a series of progress messages while it compiles a MIB, telling the user the name of the current module and current object. The -quiet flag suppresses these progress messages. You may want to set the -quiet option in your MIBCOMP environment variable. See -nowarn.
-readtree
-rootname
The -rootname option lets you specify the name of the root of the tree. Use this option if you need multiple MIB trees within one address space.
-sigid
The -sigid option lets you specify the number of significant characters in an identifier. If, during output, the MIB compiler detects identifiers that are not unique within the specified limit, it prints out a warning. The default limit is 31.
-skel
-skel.h
-start module-name.object-name
The -start option instructs certain mibcomp output modes to begin their output starting at the named node in the MIB tree rather than at the root which is the default. This option is effective for all applicable back ends.
The -start option is particularly useful when constructing MIBs that are linked to the SNMP agent dynamically. For more information, see 6.4 Dynamic MIB Additions.
-statistics
The -statistics option instructs mibcomp to print some simple statistics about the MIB compilation: how many objects were specified, how many traps, and how long the compilation took. You may wish to set the -statistics option in your MIBCOMP environment variable. mibcomp writes the statistics to the standard-error output stream, so using -statistics does not get in the way if you have told mibcomp to write its output file to the standard-output stream.
-stub
file1 [ file2 . . .]
Filenames specify files for mibcomp to use as input. You must specify at least one input file. You can use "-" (a single hyphen character) to specify that mibcomp should read from standard input.

A.5.2   Compiling a MIB Description File

Assume that you want to build an agent that supports MIB-II, that you keep your MIBs in a standard directory, that you have included that directory in a default search path via the MIBCOMP environment variable, and that the control file for your project is in the current directory under the name control.mib. To generate the C code that a WindNet SNMPv1/v2c-based agent uses to represent the MIB tree, leaving the output in a file called mib.c, do:

mibcomp -mib.c -o mib.c rfc1213.mib control.mib

You can modify a makefile to do this automatically by adding the following lines to your makefile:

mib.c:        control.mib 
        mibcomp -mib.c -o mib.c rfc1213.mib control.mib

After adding these lines to your makefile, you can use the make utility to generate mib.c automatically:

make mib.c

If your makefile also has rules that use mib.c as a source, you should be able to just build your program normally, letting make build mib.c for you when necessary. For an example of makefile construction, see $WIND_BASE/target/src/snmpv1/agent/Makefile.

Whether you create mib.c manually or with the make utility, you should be able to compile it without error using the same compiler switches that you use to compile the target agent. If mib.c does not compile, there is probably something wrong with your control file (control.mib in this example).


1:  K&R" stands for "Kernighan and Ritchie C," named after the authors of the original C language reference.