SNMP Subagent Programmer's Guide
Dynamic Directory Program
2-50 119728—SNMP Subagent Programmer’s Guide
Programming Tutorials
Example 2-10. Dynamic Directory Main Program and Next and Locator 
Functions (page 1 of 4)
#include "tdmporth"
#include "machtypH"
#include "syspubH"
#include "errnoH"                            
<-- 1
#include "mgmtpubH"
#include "dirH"
/*
 *  The SMI compiler output must be included after all
 *  the attribute data structures have been defined since
 *  this output will make reference to these structures.
 */
#pragma nowarn (93)
#include "dynamlsH"
#pragma warn (93)
/*****************************************************************************
 *   safe_malloc      Allocate a chunk of memory. Cause the program
 ****************************************************************************/
Void *
safe_malloc(register int size)
...
{
   register Void *data;
   data = (Void *) malloc(size);
   if (data == NULL)
   {
       (void) fprintf(stderr, "malloc failure\n");
       exit(1);
   }
   return(data);
}
/*****************************************************************************
 *  main      Main routine for the dynamic directory
 ****************************************************************************/
int
main(int argc,
    char **argv)
...
{
   struct directory   *dir;
   Void         *mgmt_env;
   Void         *group_handle;
   Void         *row_handle;
   short dummy = 0;
   /*
    *    make sure we were invoked nicely
    */
   if (argc != 2)
   {
     (void) fprintf(stderr, "Usage: run %s: $<agent> \n", argv[0]);
       return(1);
   }
   /*
    *   initialize context structure
    */
   dir = (struct directory *)safe_malloc(sizeof(*dir));
   dir->dir_name.val = (ubyte *)safe_malloc(MAX_dirName + 1);
   (void) strcpy((char *) dir->dir_name.val, "zsnmpsdk");          
<-- 2
   dir->dir_name.len = strlen((char *)dir->dir_name.val);
   dir->files = NULL;
   /*
    *   Initialize the session with the SMUX agent.
    */
   mgmt_env = mgmt_init_env(argv[1], (ObjId_t *) &GI_dir,          
<-- 3
             "Dynamic File Lister", NULL, NULL);










