Search code examples
c++buildersnmpindy

SNMP trap via Indy plus russian letters


I send snmp traps from borland c++ application using indy components, (thanks Remy Lebeau for working example Implementing SNMP SendTrap using Indy components) But I have problem with russian letters.

void __fastcall TMainForm::QuickSendTrap()
{
String myEnterprise   = _D("1.5.5.5.5.5.5.5");
String eventType      = myEnterprise + _D(".1");
String eventDistance  = myEnterprise + _D(".2");
String eventTitle1     = myEnterprise + _D(".3");
String eventTitle2     = myEnterprise + _D(".4");
String eventTitle3     = myEnterprise + _D(".5");

TStringList *names = new TStringList;
names->Add(eventType);
names->Add(eventDistance);
names->Add(eventTitle1);
names->Add(eventTitle2);
names->Add(eventTitle3);

TStringList *values = new TStringList;
values->AddObject(_D("ftCritical"), (TObject*)ASN1_OCTSTR);
values->AddObject(_D("2.357"), (TObject*)ASN1_OCTSTR);
values->AddObject(_D("АБВГД"), (TObject*)ASN1_OCTSTR);
values->AddObject(_D("абвгд"), (TObject*)ASN1_OCTSTR);
values->AddObject(_D("ОПРСТ"), (TObject*)ASN1_OCTSTR);

TIdSNMP *idSnmp = new TIdSNMP(NULL);
idSnmp->QuickSendTrap(edHost->Text, myEnterprise, _D("public"), 162, 6, 1, names, values);
delete idSnmp;

delete names;
delete values;
}

Instead of russian symbols Wireshark see "?"

0000 30 81 8b 02 01 00 04 06 70 75 62 6c 69 63 a4 7e 0.......public.~ 0010 06 07 2d 05 05 05 05 05 05 40 04 c0 a8 64 56 02 [email protected]. 0020 01 06 02 01 01 43 01 00 30 64 30 16 06 08 2d 05 .....C..0d0...-. 0030 05 05 05 05 05 01 04 0a 66 74 43 72 69 74 69 63 ........ftCritic 0040 61 6c 30 11 06 08 2d 05 05 05 05 05 05 02 04 05 al0...-......... 0050 32 2e 33 35 37 30 11 06 08 2d 05 05 05 05 05 05 2.3570...-...... 0060 03 04 05 3f 3f 3f 3f 3f 30 11 06 08 2d 05 05 05 ...?????0...-... 0070 05 05 05 04 04 05 3f 3f 3f 3f 3f 30 11 06 08 2d ......?????0...- 0080 05 05 05 05 05 05 05 04 05 3f 3f 3f 3f 3f .........?????

The question is how to encode russian string for snmp properly?


Solution

  • Unfortunately, TIdSNMP does not support non-ASCII data at this time. This is because:

    1. Indy's ASN.1 encode/decode functions have not been made encoding-aware yet so that strings can be converted to/from byte arrays using charsets.

    2. TSNMPInfo encodes PDU data to a String first and then encodes that String to bytes using Indy's 8bit encoding when sending. Thus, any Unicode codepoints greater than #255 will get converted to ?. The Russian characters you are trying to send all have Unicode codepoint values greater than #255. There is no option to specify a different encoding, even though ASN.1 octet strings can technically carry character data encoded in any 8bit charset as long as both parties agree to the charset used.