diff --git a/include/sniffer.h b/include/sniffer.h index 36f28cb..bd8ebb0 100644 --- a/include/sniffer.h +++ b/include/sniffer.h @@ -68,7 +68,8 @@ namespace Tins { * sniffer's filter, or the first sniffed packet if no filter has * been set. * \return The captured packet, matching the given filter, 0 if an - * error occured(probably compiling the filter). + * error occured(probably compiling the filter). Caller takes + * ownership of the packet. */ PDU *next_packet(); diff --git a/src/sniffer.cpp b/src/sniffer.cpp index 874d9d4..4a7a104 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -65,23 +65,16 @@ bool BaseSniffer::compile_set_filter(const string &filter, bpf_program &prog) { PDU *BaseSniffer::next_packet() { pcap_pkthdr header; PDU *ret = 0; - while(!ret) { - const u_char *content = pcap_next(handle, &header); - if(content) { - try { - if(iface_type == DLT_EN10MB) - ret = new EthernetII((const uint8_t*)content, header.caplen); - else if(iface_type == DLT_IEEE802_11_RADIO) - ret = new RadioTap((const uint8_t*)content, header.caplen); - else if(iface_type == DLT_IEEE802_11) - ret = Dot11::from_bytes((const uint8_t*)content, header.caplen); - else if(iface_type == DLT_LOOP) - ret = new Tins::Loopback((const uint8_t*)content, header.caplen); - } - catch(...) { - ret = 0; - } - } + const u_char *content = pcap_next(handle, &header); + if(content) { + if(iface_type == DLT_EN10MB) + ret = new EthernetII((const uint8_t*)content, header.caplen); + else if(iface_type == DLT_IEEE802_11_RADIO) + ret = new RadioTap((const uint8_t*)content, header.caplen); + else if(iface_type == DLT_IEEE802_11) + ret = Dot11::from_bytes((const uint8_t*)content, header.caplen); + else if(iface_type == DLT_LOOP) + ret = new Tins::Loopback((const uint8_t*)content, header.caplen); } return ret; }