#include<iostream>
#define check_bit(var,pos) {return (var & (1 << pos))!=0;}
using namespace std;
int main()
{
uint8_t temp[150]={0x00,0x02,0x17,0xe2,0x1c,0xa8,0x00,0x30,0x96,0xe1,0x8c, 0x38,
0x88, 0x47, 0x00 ,0x01 ,
0x30, 0xfe, 0x00, 0x01 ,0x31, 0xfe, 0x45, 0x00, 0x00 ,0x64, 0x3b, 0x89 ,0x00, 0
x00 ,0xfe, 0x01 ,
0x33, 0x5a, 0xc0 ,0xa8 ,0x79 ,0x02 ,0x0a, 0x0a, 0x0a, 0x01, 0x08, 0x00, 0xe3, 0
x86, 0x00, 0xea,
0x01, 0xd2, 0x00, 0x00, 0x00, 0x05, 0x02, 0x6a, 0x95 ,0x98, 0xab ,0xcd ,0xab, 0x
cd ,0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd ,0xab, 0xcd ,0xab ,0
xcd ,0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd ,0xab ,0xcd ,0xab ,0
xcd, 0xab ,0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd , 0xab, 0xcd ,0xab, 0xcd, 0xab, 0
xcd, 0xab ,0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd , 0xab, 0xcd
};
uint16_t *ptr1=(uint16_t*)&temp[0];
while(!(*(ptr1+0)==0x88 && *(ptr1+1)==0x47))
{
ptr1++;
}
cout<<"MPLS packet";
uint32_t *ptr2=(uint32_t*)&temp[0];
cout<<"4 bytes accessed at a time";
ptr2++;
while(check_bit(*(ptr+3),7)!=1)
{
cout<<"bottom of the stack:label 0";
ptr2++;
}
cout<<"mpls label:1";
return 0;
}
方案的目的,以识别由在一个时间访问两个字节,并检查88级47的数据包的存在,并且如果MPLS分组的分组是MPLS或不那么它应该一次访问四个数据包,并检查第三个字节(在这种情况下是30)是否启用。如果未启用,则访问接下来的四个字节并检查字节是否启用。我编写了程序,但它不工作。请人帮我,我是不能够访问的array.if我给cout<<temp[0]
它给垃圾值单个元素如何检查位被允许或不以十六进制数字的阵列
请帮
'ptr1'是一个指向'uint16_t'的指针,所以'+ 1'将地址增加**两个**字节。只需取消剧组,并将'ptr1'设为'uint8_t *'。另外,谁是'ptr'? –
只需搜索0x8847来识别MPLS数据包就相当有风险。这个序列很可能以某种方式随机出现在数据包中,导致错误的检测。你应该实际上'解码'堆栈直到IP头部。 – KillianDS
要将'temp [0]'等字节输出到'cout',您需要首先将其转换为int。否则,它会尝试将其显示为可打印的字符。 – interjay