Setting MIB leaf values

Frank Fock Frank.Fock____t-online.de
Wed Apr 18 22:25:08 CEST 2001


Hi Dan,

The OID "1.3.6.1.2.1.10.18.6.1.10.1001" is obviously not a leaf node,
since it does not end on ".0". Non-leaf values are not directly registered
with the Mib. Instead, the corresponding table object is registered.
In your case I assume, that "1.3.6.1.2.1.10.18.6.1" is that object, because
*Entry objects always end on ".1". So, what you have to do is something
like what is done in Mib::process_prepare_setrequest to find your leaf object:

 MibEntryPtr entry = 0;
 Oidx tmpoid(oid);
 mib->lock_mib();
 // entry not available
 if ((err = mib->find_managing_object(mib->get_context(""), tmpoid, entry, 0))
!=
       SNMP_ERROR_SUCCESS) {
  // object not found
}
MibLeaf* l = 0;
if (mib->is_complex_node(entry->type()) {
  if (mib->type() == AGENTPP_TABLE) {
    l = ((MibTable*)entry)->find(oid);
  }
  // If you use other Complex entries add your specific
  // code here.
}
else {
  l = (MibLeaf*)entry;
}
...
mib->unlock_mib();

Regards,
Frank

"Cox, Dan" wrote:

> Hi Frank,
>
> In the message below, I described a "segmentation fault" problem.
> Actually, the problem is that pContext->get(ind) is returning zero which I
> think indicates that the OID described by "ind" could not be found.
>
> I can see why NULL->type(); would cause a segmentation fault, but I don't
> understand what I am doing wrong getting the Oidx object.  See the code
> below.
>
> Let me just restate my problem one more time.  My agent has a function that
> is used as a callback by another piece of software in our system.  When that
> callback is invoked, I need to set the value of one of the entries in our
> MIB.  I don't have a 'this' pointer and I am not in the scope of any Agent++
> class when this function is executed.  I need to be able to set a MIB value
> based soley on its OID e.g. "1.3.6.1.2.1.10.18.6.1.10.1001".
>
> I am really stuck here. I hope that you can help me.
>
> Thanks
>
> Dan Cox
>
> -----Original Message-----
> From: Frank.Fock____t-online.de [mailto:Frank.Fock____t-online.de]
> Sent: Wednesday, April 11, 2001 2:56 PM
> To: Cox, Dan
> Subject: Re: Setting MIB leaf values
>
> The code seems to be OK. It must be something outside...
>
> Regards,
> Frank
>
> "Cox, Dan" wrote:
>
> > Hi Frank,
> >
> > Could you please take a look at this code and tell me what I
> > am doing wrong?  I called mib->get_context("") and got a non
> > zero value back for a MibContext*, but when I try to use it,
> > I get a segmentation fault.
> >
> > >Ok, you will have to determine whether the MibEntry instance
> > >is a MibLeaf or a MibTable. Most likely, it will be a MibLeaf
> > >instance (MibEntry should be treated as abstract base class).
> > >When calling the MibEntry::get_type() method a MibLeaf
> > >instances will return AGENTPP_LEAF. Then you can cast
> > >it to MibLeaf. The MibLeaf class has a set_value method.
> >
> > void LineStatusCallback(LIB_Handle      Handle,
> >                         hMsg_t* msg,
> >                         void* Text,
> >                         TAP_UINT32 Text_Byte_Count,
> >                         void* Data)
> > {
> >
> >     SM_NOTIFICATION_TEXT        *text_p;
> >     MibEntry* pMibEntry;
> >     MibContext* pContext;
> >
> >     if(msg->header.opcode != TAP_SM_NOTIFICATION)
> >     {
> >         printf("\nLineStatusCallback:got bogus opcode %x",
> > msg->header.opcode);
> >         return;
> >     }
> >
> >         text_p = (SM_NOTIFICATION_TEXT *)Text;
> >         printf("\nLineStatusCallback[%x]:",  *(int *)text_p);
> >
> >
> >
> >     pContext = mib->get_context("");
> >     if(pContext==0)
> >     {
> >         printf("\n Could not get context!\n");
> >         return;
> >     }
> >
> >         // This is the leaf that I want to write to
> >     #define LINESTATUS_OID "1.3.6.1.2.1.10.18.6.1.10.1001"
> >
> >     // create an OID object
> >     Oidx ind(LINESTATUS_OID);
> >
> >     pMibEntry = pContext->get(ind);
> >
> >     mib_type type = pMibEntry->type();  /**** SEGMENTATION FAULT  ****/
> >     if(type != AGENTPP_LEAF)
> >     {
> >         printf("Wrong type!  type = %d\n", type);
> >         return;
> >     }
> >
> >     switch(text_p->mask)
> >     {
> >                 case    SM_IDLE:
> >             printf("SM_IDLE\n");
> >             ((MibLeaf*)pMibEntry)->set_value(2);
> >
> >                 break;
> >
> >                 case    SM_OOF:
> >             printf("SM_OOF\n");
> >             ((MibLeaf*)pMibEntry)->set_value(3);
> >
> >                 break;
> >
> >                 case    SM_LOF:
> >             printf("SM_LOF\n");
> >             ((MibLeaf*)pMibEntry)->set_value(4);
> >
> >                 break;
> >
> >                 case    SM_AIS:
> >             printf("SM_AIS\n");
> >             ((MibLeaf*)pMibEntry)->set_value(5);
> >
> >                 break;
> >
> >                 default:
> >                 printf("Unknown message: mask = %x\n", text_p->mask);
> >             ((MibLeaf*)pMibEntry)->set_value(6);
> >
> >                 break;
> >         }
> >
> >
> > }
>




More information about the AGENTPP mailing list