下边是我的程序
#include
#include
#include
void packet_handler(u_char *user,const struct pcap_pkthdr *pkt_header,const u_char *pkt_data)
{
pcap_dump(user,pkt_header,pkt_data);
printf("....%d",pkt_header->len);
}
int main(int argc,char *argv[])
{
pcap_t *handle;
- char errbuf[PCAP_ERRBUF_SIZE];
-
- bpf_u_int32 mask;
- bpf_u_int32 net;
-
- //guo lv gui ze
- struct bpf_program filter;
- char filter_app[]="port 3306";
-
- char *dev;
- dev=pcap_lookupdev(errbuf);
- pcap_lookupnet(dev,&net,&mask,errbuf);
-
- handle=pcap_open_live(dev,BUFSIZ,1,0,errbuf);
-
- pcap_compile(handle,&filter,filter_app,0,net);
- pcap_setfilter(handle,&filter);
-
- pcap_dumper_t* out_pcap;
- out_pcap=pcap_dump_open(handle,"/home/qqs/pcak.pcap");
-
- pcap_loop(handle,30,packet_handler,(u_char *)out_pcap);
-
- pcap_dump_flush(out_pcap);
-
- pcap_close(handle);
- pcap_dump_close(out_pcap);
-
- return (0);
}