测试网络报文,wireshark导出来的格式不大符合要求,写一个自己用。
#include <stdio.h>
#include <string.h>
typedef unsigned short INT16U;
typedef unsigned char INT8U;
#define FRAME_LEN 178
INT8U array[FRAME_LEN];
INT8U frame[FRAME_LEN];
void hex_to_array(void);
int main()
{
hex_to_array();
return 0;
}
void hex_to_array(void)
{
INT8U *p;
INT16U i = 0;
INT8U ch;
do
{
scanf("%02x",&frame[i++]);
}while(i < FRAME_LEN);
i = 0;
printf("frame[FRAME_LEN] = \n");
printf("{\n");
for(p = frame;p < (frame + sizeof(frame)/sizeof(INT8U));p++)
{
if(i % 16 == 0)
{
printf("\n");
}
i++;
printf("0x%02x",*p);
if(i != sizeof(frame)/sizeof(INT8U))
{
printf(",");
}
}
printf("\n}");
}
wireshark中报文,复制成hex stream
效果如图: