SNMP Subagent Programmer's Guide

Programming Tutorials
SNMP Subagent Programmer’s Guide—119728 2-69
Indexed Trap Generator
/*************************************************************************
* next_entry - determine what the next entry in the table would be
************************************************************************/
int
next_entry(Void *t, <--
24
Void **i)
...
{
struct master *m;
INTEGER card;
INTEGER port;
/* findthe data structure containing the table of interest */
m = (struct master *) t;
/* figure out what we want the sucessor of.
* Special logic deals with the case of missing indices. */
if ((i[0] == NULL) || <--
25
(*((INTEGER *) i[0]) <= 0))
{
/* If index is missing, assume first table entry */
i[0] = &m->i[0][0].card;
}
card = *((INTEGER *) i[0]);
if (card > m->card_count)
{
return(1);
}
/* Now figure out what port (second index) is of interest. */
if (i[1] == NULL) <--
26
{
/* If index is missing, assume first table entry */
i[1] = &m->i[card-1][0].port;
port = *((INTEGER *) i[1]); }
else
{
/* extract the port number. figure out its successor.
* if it's too large, move on to the next card. */
port = *((INTEGER *) i[1]);
port++; }
if (port > m->port_count) <--
27
{ port = 1;
card++; }
/* Make sure that our final choice of card is ok */
if ((card > m->card_count) || <--
28
(card <= 0) ||
(port > m->port_count) ||
(port <= 0))
{
return(1);
}
/* adjust to 0-based indexing */
card--;
port--;
/*fill in the index value pointers to be used for this operation */
i[0] = &m->i[card][port].card; <--
29
i[1] = &m->i[card][port].port;
return(0);
}
Example 2-13. Indexed Trap Generator Main Program and Next and Locator
Functions (page 5 of 5)