Char error_content [PCAP_ERRBUF_SIZE];
Char * net_interface;
Struct bpf_program bpf_filter;
Udp//char bpf_filter_string []="SRC host 192.168.2.181";
///entrance parameters monitor success
DST//char bpf_filter_string []="udp port 3232 and SRC host 192.168.2.181";
Char bpf_filter_string []="udp";
Bpf_u_int32 net_mask;
Bpf_u_int32 net_ip;
Net_interface=pcap_lookupdev (error_content);
Printf (" net_interface=% s \ n ", net_interface);
Pcap_lookupnet (net_interface, & amp; Net_ip, & amp; Net_mask error_content);
Pcap_handle=pcap_open_live (net_interface, 20480, 0, error_content);
Pcap_compile (pcap_handle, & amp; Bpf_filter bpf_filter_string, 0, net_mask);
Pcap_setfilter (pcap_handle, & amp; Bpf_filter);
If (pcap_datalink (pcap_handle)!=DLT_EN10MB)
return -1;
Pcap_loop (ethernet_protocol_packet_callback pcap_handle, 1, NULL);
Pcap_close (pcap_handle);
//pcap_stats (pcap_t *, struct pcap_stat *);
CodePudding user response:
Nic open chaos model?CodePudding user response:
Pcap_open_live (net_interface, 20480, 0, error_content); The third argument is that opens the mixed mode?