作者:书友79086887 | 来源:互联网 | 2023-12-12 20:55
本文介绍了一种解析GRE报文长度的方法,通过分析GRE报文头中的标志位来计算报文长度。具体实现步骤包括获取GRE报文头指针、提取标志位、计算报文长度等。该方法可以帮助用户准确地获取GRE报文的长度信息。
// *pTemp为GRE报文头指针
unsigned char getGreHdrLen(unsigned char *pTemp)
{
unsigned char greflags1 = *(pTemp);
unsigned char greflags2 = *(pTemp + 1);
unsigned char sequence_num = (greflags1 >> 4) & 0x01;
unsigned char key = (greflags1 >> 5) & 0x01;
unsigned char acknowledge_num = (greflags2 >> 7) & 0x01;
unsigned char grehderlen = 0;
unsigned char flags = sequence_num + key + acknowledge_num;
switch (flags) {
case 0:
grehderlen = 4;
break;
case 1:
grehderlen = 8;
break;
case 2:
grehderlen = 12;
break;
case 3:
grehderlen = 16;
break;
}
return grehderlen;
}
gre报文长度解析,布布扣,bubuko.com