报错Unhandled exception in Sniffer.exe 0xC0000005 :Access Violation,求指导
已定义结构体typedef struct iec_header {
unsigned char dest_mac[6];
unsigned char source_mac[6];
unsigned char TPID[2];
unsigned char TCI[2];
unsigned char Ethertype[1];
unsigned char APPID[2];
unsigned char Length[2];
unsigned char Reserved1[2];
unsigned char Reserved2[2];
}iec_header;
然后调试程序的时候运行到
str_smac.Format("%02x:%02x:%02x:%02x:%02x:%02x",ih->source_mac[0],
ih->source_mac[1],ih->source_mac[2],ih->source_mac[3],ih->source_mac[4],ih->source_mac[5]);
str_dmac.Format("%02x:%02x:%02x:%02x:%02x:%02x",ih->dest_mac[0],
ih->dest_mac[1],ih->dest_mac[2],ih->dest_mac[3],ih->dest_mac[4],ih->dest_mac[5]);
str_tpidtci.Format("%02x:%02x:%02x:%02x",ih->TPID[0],ih->TPID[1],ih->TCI[0],ih->TCI[1]);
str_etype.Format("%02x:%02x",ih->Ethertype[0],ih->Ethertype[1]);
str_pdu.Format("%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",ih->APPID[0],
ih->APPID[1],ih->Length[0],ih->Length[1],ih->Reserved1[0],ih->Reserved1[1],ih->Reserved2[0],ih->Reserved2[1]);
就会进入汇编模式(小弟新手,自学的,有些词还不会用,貌似看过别人这么用)7C92E480 mov ebx,dword ptr [esp]
7C92E483 push ecx
7C92E484 push ebx
7C92E485 call 7C94A970
7C92E48A or al,al
7C92E48C je 7C92E49A
7C92E48E pop ebx
7C92E48F pop ecx
7C92E490 push 0
7C92E492 push ecx
7C92E493 call 7C92D05E
7C92E498 jmp 7C92E4A5
7C92E49A pop ebx
7C92E49B pop ecx
7C92E49C push 0
7C92E49E push ecx
7C92E49F push ebx
7C92E4A0 call 7C92D9AE
就在7C92E4A0 call 7C92D9AE
这个地方报错Unhandled exception in Sniffer.exe 0xC0000005 :Access Violation,求大神指导怎么改,小弟在此谢谢啦
[解决办法]
可能是定义的结构不是4字节的整数倍长度有关,你把结构改为如下试一下:
typedef struct iec_header { unsigned char dest_mac[6]; unsigned char source_mac[6]; unsigned char TPID[2]; unsigned char TCI[2]; unsigned char Ethertype[1]; unsigned char APPID[2]; unsigned char Length[2]; unsigned char Reserved1[2]; unsigned char Reserved2[2]; unsigned char Nothing[3];}iec_header;