SNMP Subagent Programmer's Guide
Programming Tutorials
SNMP Subagent Programmer’s Guide—119728 2-89
Security Checker
   /*
    *    Set up the management environment.  We'll talk to the local
    *    agent, registering ourselves as 1.3.6.1.4.1.442.2.1
    *    with no password.
    */
   if ((mgmt_env = mgmt_init_env(argv[1],               <--
5
               (ObjId_t *) &GI_hello,
               "Hello World Example with security",
               (Octets_t *) NULL,
               (void_function) NULL)) == NULL)
   {
       (void) fputs(argv[0], stderr);
       (void) fputs(": mgmt_init_env failure\n", stderr);
       return(2);
   }
   /*
    *    Let the agent know information what we're responsible for.
    */
   if ((mgmt_hello_handle = mgmt_new_instance(mgmt_env,          <--
6
                    &SMI_GROUP_hello,
                    (void *)NULL)) == NULL)
   {
       (void) fputs(argv[0], stderr);
       (void) fputs(": mgmt_new_instance failure\n", stderr);
       mgmt_term_env(mgmt_env);
       mgmt_env = NULL;
       return(2);
   }
/* allocate an IO buffer: */
   if (mgmt_env->sess->agent_msg_buffer == NULL)
   {
   mgmt_env->sess->agent_msg_buffer = (char *) malloc(SNMP_MSG_MAX);
   }
#pragma page
 /* main loop */
   while (!time_to_die)
   {
    agent_fileno = mgmt_read_nowait((struct mgmt_env *)mgmt_env,NULL);   <--
7
    if (agent_fileno == -1)
     {
     (void) fprintf(stderr, "%s: error from mgmt_read_nowait\n",
           argv[0]);
     break;
     }
Example 2-18. Security Checker Main Program (page 3 of 5)










