[CAPL]: сравнить QWord со строкой, или Как сохранить MAC-адрес как QWord для сравнения с другим QWord? - PullRequest
0 голосов
/ 04 февраля 2019

Я новичок в мире программирования. Я пытаюсь сохранить в строке MAC-адрес входящего сообщения Ethernet типа данных «QWord», а затем, наконец, сравнить строку.

Ниже приведен мой код, здесь snprintf соответствует функции C sprintf

Я ищу помощь в следующих пунктах:

on ethernetPacket *
{
  byte Data[1506];
  int i;
  int Payloadlength;

  char DestinationmacStr[18];
  char SourcemacStr[18];
  char ComparemacStr[18];
  char macStr[18];

  // Store a MAC address to compare with the MAC Address of the incoming ETH message
  int array[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  snprintf(ComparemacStr, elCount(ComparemacStr), "%02x:%02x:%02x:%02x:%02x:%02x",
         array[0], array[1], array[2], array[3], array[4], array[5]);

  Payloadlength=this.Length;

  for(i=0; i<Payloadlength; i++)
  {
    Data[i]=this.byte(i);
  }

  // How to store the Source MAC Address of Source (QWord to string)?
  // Error message when compiling at "this.Source[0]" => no array possible here
  snprintf(SourcemacStr, elCount(SourcemacStr), "%02x:%02x:%02x:%02x:%02x:%02x",
         this.Source[0], this.Source[1], this.Source[2], this.Source[3], this.Source[4], this.Source[5]);

  // How to store the Destination MAC Address of Source (QWord to string)?
  // Error message when compiling at "this.destination[0]" => no array possible here
  snprintf(DestinationmacStr, elCount(DestinationmacStr), "%02x:%02x:%02x:%02x:%02x:%02x",
         this.destination[0], this.destination[1], this.destination[2], this.destination[3], this.destination[4], this.destination[5]);

  write("Source MAC Address: %s",SourcemacStr);
  write("Destination MAC Address: %s",DestinationmacStr);

  if(DestinationmacStr==ComparemacStr)
  {
   // do something
  }
  outputMostEthPkt(1, this.destination, this.length, Data);
}

enter image description here

enter image description here

Спасибо заранее

1 Ответ

0 голосов
/ 05 февраля 2019

A qword - это просто 64-разрядное целое число, которое можно сравнить со стандартным оператором ==.

Вы можете преобразовать строку, содержащую MAC-адрес, в qword, используя CAPLfunction EthGetMacAddressAsNumber

Преобразование из qword в строку можно выполнить с помощью EthGetMacAddressAsString

В вашем случае код будет выглядеть примерно так:

char compareMacStr = "AA::BB::CC::00::FF::EE";
qword compareMac = EthGetMacAddressAsNumber(compareMacStr);

if(this.destination == compareMac)
{
    ....
}
...