1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Fixed BaseSniffer::next_packet() to return when error occurred. Updated its documentation.

Signed-off-by: Matias Fontanini <matias.fontanini@gmail.com>
This commit is contained in:
Bruno Nery
2012-11-19 10:29:51 -08:00
committed by Matias Fontanini
parent d0048e3aef
commit 28e5df3abc
2 changed files with 12 additions and 18 deletions

View File

@@ -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();

View File

@@ -65,10 +65,8 @@ 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)
@@ -78,11 +76,6 @@ PDU *BaseSniffer::next_packet() {
else if(iface_type == DLT_LOOP)
ret = new Tins::Loopback((const uint8_t*)content, header.caplen);
}
catch(...) {
ret = 0;
}
}
}
return ret;
}