qqs1402654893
2017-02-22 06:59
采纳率: 50%
浏览 2.0k
已采纳

libpcap抓包程序执行时出现Segmentation fault (core dumped)

下边是我的程序
#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);

}

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • shen_wei 2017-02-22 09:32
    已采纳
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题