SNMP Subagent Programmer's Guide
Callback Functions
4-36 119728—SNMP Subagent Programmer’s Guide
Writing Subagent Logic
Example
The following example is taken from the Dynamic Directory sample program. This
program provides a next function named next_file, which is identified in the INDEX
clause of the MIB definition for the associated table entry:
dirFiles OBJECT-TYPE
SYNTAX SEQUENCE OF FileEntry
...
fileEntry OBJECT-TYPE
SYNTAX FileEntry
ACCESS not-accessible
STATUS mandatory
INDEX { fileName }
C_NEXT_FUNC next_file
::= { dirFiles 1 }
The run-time library calls next_file() when it receives a GetNext request from a
manager. The next function calls build_files() to re-build the table. Then it determines
whether the first element of the index list is NULL, indicating that it should return
pointers to the index value of the first entry. The function comp_files() is used to detect
matching file names. When the matching file is found, next_file() terminates, returning
the index for the next entry. The value ENOENT, defined in errnoH, is returned when
no match is found. The run-time library then calls the locate function, locate_file(), to
complete processing the GetNext request. Refer to the example under “Locator
Functions,” earlier in this section, for information on locate_file().
int
next_file(Void *ctxt,
Void **indices)
...
{
struct directory *dir = (struct directory *) ctxt;
struct file_entry *file;
/* Build the cache of names. */
build_files(dir);
/* If the first pointer is NULL, the library code
* wants the first row of the table. */