Search code examples
c++buildersnmpindy10snmp-trap

Indy's SNMP Trap send nothing


I tried to send SNMP Trap using Indy's component TIdSnmp. (Code was copied from Implementing SNMP SendTrap using Indy components)

void __fastcall TMainForm::btSendTrapClick(TObject *Sender)
{
 String myEnterprise   = _D("1.5.5.5.5.5.5.5");
 String eventType      = myEnterprise + _D(".1");
 String eventDistance  = myEnterprise + _D(".2");

 TIdSNMP * idSnmp = 0;

 idSnmp = new TIdSNMP(NULL);

 idSnmp->Trap->Host       = edHost->Text;
 idSnmp->Trap->Community  = _D("public");
 idSnmp->Trap->Enterprise = myEnterprise;
 idSnmp->Trap->GenTrap    = 6;              // I've met such values
 idSnmp->Trap->SpecTrap   = 1;              // somewhere in inet
 idSnmp->Trap->MIBAdd(eventType,_D("ftCritical"));
 idSnmp->Trap->MIBAdd(eventDistance,_D("2.357"));

 idSnmp->SendTrap();

 delete idSnmp;
}

But wireshark doesn't registar any network activity. I tried variant with QuickSendTrap with the same result. In despair I decided to try Indy's UDP component for sending something.

void __fastcall TForm1::btFireClick(TObject *Sender)
{
 TIdUDPClient* udpClient = 0;
 TIdBytes sendData;

 myClass* packet = new myClass();
 packet->a = 10;
 packet->b = 77;
 packet->c = "Test";

 int size = sizeof(*packet);
 sendData = RawToBytes(packet, size);

 udpClient = new TIdUDPClient(NULL);
 udpClient->Host = "192.168.100.19";
 udpClient->Port = 162;
 udpClient->SendBuffer(sendData);

 delete udpClient;
}

Surely it's not a real SNMP Trap but wireshark see this:

192.168.100.21  192.168.100.19  UDP 54  Source port: 49873  Destination port: snmptrap

Wireshark filter is "udp portrange 161-162"

And in data section I can find my values. By the way SNMP component works properly for getting values by simple idSnmp->SendQuery() and this is registered by wireshark as well.

So, are there some additinal conditionals in order to SendTrap() works properly?

I have Windows7, administative rights. Firewall is turned off. Code compiled by Embarcadero RAD Studio 2010, desktop application.

Should SNMP Trap receiver wait my SendTrap() just in order to SendTrap() could work? (unfortunately, I haven't got another computer for experiments at the moment) Should be OID "1.5.5.5.5.5.5.5" be registered somewhere in my computer just in order to SendTrap() could work?

Maybe some other requirements?


Solution

  • But wireshark doesn't registar any network activity

    That is not what you said in the other discussion. You said it was working.

    So, are there some additinal conditionals in order to SendTrap() works properly?

    No. The code I gave you is all you need.

    Should SNMP Trap receiver wait my SendTrap() just in order to SendTrap() could work?

    No. UDP is connection-less. A receiver is not required in order to send. If there is no receiver, an ICMP error will be sent back to the sender.

    Should be OID "1.5.5.5.5.5.5.5" be registered somewhere in my computer just in order to SendTrap() could work?

    No.