我是编程界的新手,我要在这里尝试将传入的以太网消息的MAC地址(数据类型为“ 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);
}
先谢谢您
答案 0 :(得分:2)
qword
只是一个64位整数,可以与标准==
运算符进行比较。
您可以使用CAPL函数qword
EthGetMacAddressAsNumber
从qword
转换为字符串可以使用EthGetMacAddressAsString
在您的情况下,代码大致如下:
char compareMacStr = "AA::BB::CC::00::FF::EE";
qword compareMac = EthGetMacAddressAsNumber(compareMacStr);
if(this.destination == compareMac)
{
....
}