SNMP Subagent Programmer's Guide
Fault-Tolerant Hello World Program
2-30 119728—SNMP Subagent Programmer’s Guide
Programming Tutorials
Example 2-4. Fault-Tolerant Hello World Program (page 1 of 3)
#include "tdmportH" nolist
#include "machtyph" nolist
#include "syspubh"  nolist
#include "smitypeh" nolist
#include "mgmtpubh" nolist
#include "mgmtenvH" nolist
#define DEF_TEXT     "Hello World"
#define DEF_FREQUENCY     15
static char      text[256] = {DEF_TEXT};
static DisplayString helloText = {sizeof(DEF_TEXT)-1, (ubyte *) text};
static INTEGER     helloPrintFreq = DEF_FREQUENCY;
static Counter   helloPrintCnt = 0;
#pragma nowarn (93)
#include "helloh" nolist      /* SMI compiler output */
#pragma warn (93)
#include <talh> nolist
#include <cextdecs (FILE_GETINFO_,AWAITIOX)> nolist
 /*  agent information includes mgmt_env pointer,
 *    handle to the management environment and our group, and
 *    file number (-1 means not connected) */
#define MAXAGTS 5
typedef struct {                            
<-- 1
 struct mgmt_env *mgmt_env;
 void     *mgmt_handle;
 short     agent_filenumber;
} agent_info_t;
agent_info_t agent_info[MAXAGTS+1]; /* element 0 is not used */          
<-- 2
/************************************************************************* *
 *  main - fault-tolerant hello-wowrld demo main program.
 ************************************************************************/
int main(int argc, char *argv[])
{
 /**  detect configuration changes */
 INTEGER last_freq = helloPrintFreq;
 /*  mgmt_read_nowait stuff  */
 short  count_xferd = 0;   /* used for AWAITIO to mgmt_poll() */
 short  i,         /* loop index */
    event_fileno,    /* returned from AWAITIO */
    status,       /* CC status from AWAITIO */
   error,    /* agent-subagent interprocess comm. errors */
    living_agent_count;  /* know when to quit */            
<-- 3
 /* initialize agent communication stuff */
 for (i=0;i++;i<MAXAGTS) {
 agent_info[i].mgmt_env = NULL;
  agent_info[i].mgmt_handle = NULL;
 agent_info[i].agent_filenumber = -1;
 }
 /*  Make sure we were properly invoked */
 if ((argc > MAXAGTS + 1) || (argc <= 1)) {
  i = MAXAGTS;
 (void) fprintf(stderr, "Usage: run %s $<agent> ... (up to %i agents)\n",
       argv[0], i);
 return(2);
 }










