Solaris System Management Agent Developer's Guide

Generating Code Templates

You use the mib2c tool to generate C header files and implementation files from your MIB. You can use the generated C files as templates for your module. You can modify the templates appropriately for your purposes, and then use the templates to make your module. Before the file generation begins, mib2c tests your MIB node for syntax errors. Any errors are reported to standard output. You must fix any syntax errors before the code can be generated. This error-checking ability enables you to use mib2c as you create your MIB to ensure that the MIB syntax is correct.


Note –

Be sure to set your MIB environment variables as described in Setting MIB Environment Variables before you use mib2c.


The mib2c command must be run against nodes in the MIB, not on the entire MIB at once. You do not need to specify the MIB name, but the MIB file must be located in a directory on your MIB search path. On the mib2c command line, you must specify a configuration file and the name of one or more MIB nodes. The configuration file must matches the type of data in the MIB node. The command must use the following format:


mib2c -c configfile MIBnode [MIBnode2 MIBnode3 ...]

For example, if you have one node that is called scalarGroup in your MIB, you could use the following command to generate the code templates:


% mib2c -c mib2c.scalar.conf scalarGroup

The files scalarGroup.h and scalarGroup.c are generated.

If your MIB contains both scalar and table data, you should run mib2c separately on the MIB nodes for each type of data. You specify the appropriate configuration file for each type of data.

The following table lists the mib2c configuration files. The table describes the purpose of each configuration file, to help you decide which configuration file to use for your data.

Table 2–1 Configuration Files for Use With mib2c Tool

mib2c Configuration File

Purpose 

mib2c.scalar.conf

For scalar data, including integers and non-integers. This configuration file causes mib2c to generate handlers for the scalar objects in the specified MIB node. Internal structural definitions, table objects, and notifications in the MIB are ignored.

mib2c.int_watch.conf

For scalar integers only. When you use this configuration file, mib2c generates code to map integer type scalar MIB objects to C variables. GET or SET requests on MIB objects subsequently have the effect of getting and setting the corresponding C variables in the module automatically. This feature might be useful if you want to watch, or monitor, the values of certain objects.

mib2c.iterate.conf

For tables of data that are not kept in the agent's memory. The tables are located externally, and the tables need to be searched to find the correct row. When you use this configuration file, mib2c generates a pair of routines that can iterate through the table. The routines can be used to select the appropriate row for any given request. The row is then passed to the single table handler routine. This routine handles the rest of the processing for all of the column objects, for both GET and SET requests.

mib2c.create-dataset.conf

For tables of data that are kept in the agent's memory. The table does not need to be searched to find the correct row. This configuration file causes mib2c to generate a single handler routine for each table. Most of the processing is handled internally within the agent, so this handler routine is only needed if particular column objects require special processing.

mib2c.array-user.conf

For tables of data that are kept in the agent's memory. The data can be sorted by the table index. This configuration file causes mib2c to generate a series of separate routines to handle different aspects of processing the request. As with the mib2c.create-dataset.conf file, much of the processing is handled internally in the agent. Many of the generated routines can be deleted if the relevant objects do not need special processing.

mib2c.column_defines.conf

To create a header file that contains a #define for each column number in a MIB table.

mib2c.column_enums.conf

To create a header file that contains a #define for each enum of common values used by the columns in a MIB table.

The mib2c(1M) man page includes more details about using the mib2c tool. You should also see Chapter 3, Data Modeling for more examples of using mib2c.