[SNMP4J] Detect the receiving SNMP Message

Andrew Chan wingnin at gmail.com
Tue Sep 27 00:13:49 CEST 2005


Hi Frank,
  I did, actually below are what I set for the repond pdu.
  public synchronized void processPdu(CommandResponderEvent e) {
PDU command = e.getPDU();
 sendRespond(e, command);
 }
  private void sendRespond(CommandResponderEvent e, PDU command)
{
CommunityTarget target = createCommunityTarget(e.getPeerAddress());

PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(My_OID), variable)); //please assume
MY_OID and the variable has been set somewhere
pdu.setType(PDU.RESPONSE); //Here I set the PDU type to RESPOND
pdu.setRequestID(command.getRequestID()); //Here I set the Request ID

//Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
Snmp snmp = new Snmp(e.getTransportMapping()); //I even set the
TransportMapping

snmp.send(pdu, target);
}

private CommunityTarget createCommunityTarget(Address addr)
{
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(addr);
target.setVersion(SnmpConstants.version1);

return target;
}
 Do you have any idea? Thanks.
 Regards,
Andrew


 On 9/27/05, Frank Fock <fock at agentpp.com> wrote:
>
> You need probably to set the request ID of the response PDU to the request
> ID you received.
>
> Best regards,
> Frank
>
> Andrew Chan wrote:
>
> > Thanks Frank,
> >
> > May I ask one more question? After I have recieved the SNMP Message,
> > I should construct an respond, right how do I do that? I try this by
> > sending a PDU.RESPOND type pdu to the
> > CommandResponderEvent.getPeerAddress(), but the manager always got a
> > time out error, do you have any idea? Many thanks.
> >
> > Regards,
> > AC
> >
> >
> > On 9/27/05, *Frank Fock* <fock at agentpp.com <mailto:fock at agentpp.com>>
> > wrote:
> >
> > Hi Andrew,
> >
> > Just call CommandResponderEvent.getMessageProcessingModel() and
> > you will
> > get the SNMP version.
> >
> > Best regards,
> > Frank
> >
> > Andrew Chan wrote:
> >
> > >Dear all,
> > > I am trying to writing code to receive SNMP request, I know how
> > to write
> > >it by referencing the example in Package org.snmp4j. However, how
> > do we know
> > >the SNMP version (v1, v2c or v3) of incoming message?
> > > What I am expecting is to get the "target" from the
> > CommandResponderEvent,
> > >but seems this is not the case.
> > > Am I doing something wrong?
> > > Thanks.
> > >AC
> > >_______________________________________________
> > >SNMP4J mailing list
> > >SNMP4J at agentpp.org <mailto:SNMP4J at agentpp.org>
> > > http://lists.agentpp.org/mailman/listinfo/snmp4j
> > >
> > >
> > >
> > >
> >
> >
> > --
> > AGENT++
> > http://www.agentpp.com
> > http://www.mibexplorer.com <http://www.mibexplorer.com>
> > http://www.mibdesigner.com
> >
> >
> >
>
>
> --
> AGENT++
> http://www.agentpp.com
> http://www.mibexplorer.com
> http://www.mibdesigner.com
>
>
>



More information about the SNMP4J mailing list