SNMP Subagent Programmer's Guide
Nowaited Hello World Program
2-24 119728—SNMP Subagent Programmer’s Guide
Programming Tutorials
/*
* 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],
(ObjId_t *) &GI_hello,
"nowaited Hello World Example",
(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,
&SMI_GROUP_hello,
(void *)NULL)) == NULL)
{
(void) fputs(argv[0], stderr);
(void) fputs(": mgmt_new_instance failure\n", wstderr);
mgmt_term_env(mgmt_env);
mgmt_env = NULL;
return(2);
}
/* allocate an IO buffer: */
<-- 4
if (mgmt_env->sess->agent_msg_buffer == NULL)
{
mgmt_env->sess->agent_msg_buffer = (char *) malloc(SNMP_MSG_MAX);
}
/* main loop */
while (!time_to_die)
{
agent_fileno = mgmt_read_nowait((struct mgmt_env *)mgmt_env,NULL);
<-- 5
if (agent_fileno == -1)
{
(void) fprintf(stderr, "%s: error from mgmt_read_nowait\n",
argv[0]);
break;
}
wait:
<-- 6
event_fileno = -1;
status = AWAITIOX(&event_fileno,,&count_xferd,,100*helloPrintFreq);
<-- 7
if (status != CCE) {
FILE_GETINFO_(event_fileno, &error);
<-- 8
if (error == 40) {
(void) fputs((char *) helloText.val, stderr);
(void) fputs("\n", stderr);
helloPrintCnt++;
goto wait;
} else {
(void) fprintf(stderr, "%s: AWAITIO error %i on file %i\n",
argv[0], error, event_fileno);
/* handle other errors here, may want to goto wait after */
} /* end if error == 40 */
} /* end if status != CCE */
if (event_fileno == agent_fileno) {
<-- 9
if (mgmt_poll((struct mgmt_env *) mgmt_env,(struct timeval *) NULL,
<-- 10
&count_xferd) < 0)
{
(void) fprintf(stderr,"%s: agent unavailable for poll\n", argv[0]);
break
;
Example 2-3. Nowaited Hello World Source Code (page 2 of 3)