None of the functions with this name in scope match the target typeclass CPacketscapturedDlg :public CDialog{public:CPacketscapturedDlg(CWnd* pParent = NULL); void ethernet_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr* packet_he

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/07 23:22:23
None of the functions with this name in scope match the target typeclass CPacketscapturedDlg :public CDialog{public:CPacketscapturedDlg(CWnd* pParent = NULL); void ethernet_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr* packet_he

None of the functions with this name in scope match the target typeclass CPacketscapturedDlg :public CDialog{public:CPacketscapturedDlg(CWnd* pParent = NULL); void ethernet_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr* packet_he
None of the functions with this name in scope match the target type
class CPacketscapturedDlg :public CDialog
{
public:
CPacketscapturedDlg(CWnd* pParent = NULL);
void ethernet_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr*
packet_header,const u_char *packet_content);
void ip_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr
*packet_header,const u_char* packet_content);
void arp_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr *packet_header,const
u_char * packet_content);
void icmp_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr *
packet_header,const u_char * packet_content);
void udp_protocol_packet_callback(u_char * argument,const struct pcap_pkthdr *
packet_header,const u_char * packet_content);
void tcp_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr *packet_header,const
u_char *packet_content);
void go_capture();
}
void CPacketscapturedDlg::ethernet_protocol_packet_callback(u_char *argument,const struct
pcap_pkthdr* acket_header,const u_char *packet_content){}
void CPacketscapturedDlg::ip_protocol_packet_callback(u_char *argument,const struct
pcap_pkthdr *packet_header,const u_char* packet_content){}
void CPacketscapturedDlg::arp_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr
*packet_header,const u_char * packet_content){}
void CPacketscapturedDlg::icmp_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr * packet_header,const u_char * packet_content){}
void CPacketscapturedDlg::udp_protocol_packet_callback(u_char * argument,const struct pcap_pkthdr * packet_header,const u_char * packet_content){}
void CPacketscapturedDlg::tcp_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr *packet_header,const u_char *packet_content){}
void CPacketscapturedDlg::go_capture()
{
pcap_t *pcap_handle;
u_char *pkt_data;
char error_content[PCAP_ERRBUF_SIZE];
char *net_interface;//网络接口
struct bpf_program bpf_filter;//过滤规则
char bpf_filter_string[]="";
bpf_u_int32 net_mask;//网络掩码
bpf_u_int32 net_ip;//网络地址
net_interface=pcap_lookupdev(error_content);//获得网络接口
pcap_lookupnet(net_interface,&net_ip,&net_mask,error_content);//获得网络地址和网络掩码
pcap_handle=pcap_open_live(net_interface,BUFSIZ,1,0,error_content);//打开网络接口
pcap_compile(pcap_handle,&bpf_filter,bpf_filter_string,0,net_ip);
if(pcap_datalink(pcap_handle)!=DLT_EN10MB)
return;
pcap_loop(pcap_handle,-1,ethernet_protocol_packet_callback,NULL);//回调函数的方式捕获数据包
pcap_close(pcap_handle);
}
void CPacketscapturedDlg::OnCapture()
{
go_capture();
}
编译出现如下的错误:'pcap_loop' :cannot convert parameter 3 from 'void (unsigned char *,const struct pcap_pkthdr *,const unsigned char *)' to 'void (__cdecl *)(unsigned char *,const struct pcap_pkthdr *,const unsigned char *)'
None of the functions with this name in scope match the target type

None of the functions with this name in scope match the target typeclass CPacketscapturedDlg :public CDialog{public:CPacketscapturedDlg(CWnd* pParent = NULL); void ethernet_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr* packet_he
普通类成员变量是无法作为 回调函数的,原因就是C++会给类增加一个隐含的参数变量this指针.
这也就是你的类成员函数 ethernet_protocol_packet_callback 出问题的原因.
解决办法:
1.不要用类成员函数来做回调函数.这个估计和你的封装到类中的初衷不符.
2.把ethernet_protocol_packet_callback 加static变成静态函数.不过静态成员函数只能访问静态成员变量,这一点你也要注意一下.如果访问了非静态成员变量,则还会编译失败.
如果一定要访问对象的其他非静态成员变量,可以给类增加一个静态的指针,类型为类本身的类型,并且在类对象的构造函数中初始化它指向类对象,这样就可以访问类对象的所有成员了.