SNMP Subagent Programmer's Guide
Programming Tutorials
SNMP Subagent Programmer’s Guide—119728 2-51
Dynamic Directory Program
   if (mgmt_env == NULL)
   {
       (void) fprintf(stderr, "%s: failed to connect to agent\n",
             argv[0]);
       return(2);
   }
   /*
   *  Instantiate the group that contains the table.
    */
   group_handle = mgmt_new_instance(mgmt_env, &SMI_GROUP_dir,     
<-- 4
                 (Void *) dir);
   if (group_handle == NULL)
   {
       (void) fprintf(stderr, "%s: group instantiation failure\n",
             argv[0]);
       return(2);
   }
   / * Register the dynamic table of file names. Since the MIB for this table 
   *  indicates that a NEXT function is defined for finding rows of the 
   *  table, the library knows that this is a dynamic table. Registering this
    *  single mount point will cause the NEXT and LOCATOR
   *  functions to be called by the library when appropriate.*/
   row_handle = mgmt_new_instance(mgmt_env,          
<-- 5
                &SMI_GROUP_fileEntry, (Void *) dir);
   if (row_handle == NULL)
   {
       (void) fprintf(stderr, "%s: table instantiation failure\n",
             argv[0]);
       return(2);
   }
    /*  Do nothing but process SNMP requests as they come in.
    *    The program will only be terminated by a signal. */
   while (1)
   {
       if (mgmt_poll(mgmt_env, (struct timeval *) NULL,&dummy)      
<-- 6
        < 0) {
          (void) fprintf(stderr, "%s: agent unavailable\n",
                argv[0]);
          return(2);
       }
       /*
       *    Processing of management requests may have
       *    caused a list of files to have been created.
       *    If this is the case, free this list at this time.
       *
       *   A more economical approach is to timestamp the cache,
       *    re-loading it only if it has aged past a certain point.
       *   This approach  is more economical in terms of
       *    cpu utilization, but it means that the data being
     *  returned to the manager is somewhat stale.
       *
       *    In this less efficient implementation, the list is
       *    built from scratch whenever a management message
       *   is received.
       */
       if (dir->files)
       {
          free_files(dir->files);                
<-- 7
          dir->files = NULL;
       }
   }
}
Example 2-10. Dynamic Directory Main Program and Next and Locator 
Functions (page 2 of 4)










