DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Developing SMUX peers for SNMP agents

Writing get functions

You have written your MIB module, made the #define statements, declared global variables and initialized the values of the MIB objects and the MIB database used by the peer. The next step is to write ``get'' functions for single and multiple instances. This requires additional changes to foomib.c.

When a GetRequest or GetNextRequest PDU is being processed, control is passed through the get function, and it is in the get function that objects are read.

For every single instance leaf object in your MIB module, add a ``case'' to this switch statement. Use the appropriate function (o_string(), o_integer(), and so on) according to the object's syntax.

    switch (ifvar) {
    case PRODUCTNAME:
		return o_string(oi, v, productName, strlen(productName));
		
    case BOARDSTATUS:
        return o_integer(oi, v, boardStatus);

case EXAMPLEIPADDR: { struct sockaddr_in tmp_IpAddr; tmp_IpAddr.sin_addr = exampleIpAddr;

return o_ipaddr(oi, v, (char *) & tmp_IpAddr); }

case EXAMPLEOBJECTID: return o_specific(oi, v, exampleObjectID);

case NUMBERLINES: return o_integer(oi, v, numberLines);

default: return error__status_noSuchName; }

To get multiple instances, get_serialLineTable() is executed to process GetRequest and GetNextRequest PDUs for a VarBind of an Object in the serialLineTable. For each table in your MIB make one of the following functions of name get_tableName():
    static int
    get_serialLineTable(oi, v, offset)
     OI              oi;
   	 register struct type_SNMP_VarBind *v;
   	 int             offset;
	{
When a GetRequest or GetNextRequest PDU is being processed, control is passed through this get function, and it is here that the multiple instance objects are read.

For every object in the table that this function services, add a ``case'' to this ``switch'' statement. Use the appropriate function (o_string(), o_integer(), and so on) according to the object's syntax.

    switch (ifvar) {
    case SERIALLINENUMBER:
        return o_integer(oi, v, ifnum);

case SERIALLINEBAUDRATE: return o_integer(oi, v, serialLineTable[ifnum].serialLineBaudRate);

case SERIALLINETERMLOCATION: return o_string(oi, v, serialLineTable[ifnum].serialLineTermLocation, strlen(serialLineTable[ifnum].serialLineTermLocation));

default: return error__status_noSuchName; }


Next topic: Writing set functions
Previous topic: Initialization of global data

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003