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:
committed by
Matias Fontanini
parent
d0048e3aef
commit
28e5df3abc
@@ -68,7 +68,8 @@ namespace Tins {
|
|||||||
* sniffer's filter, or the first sniffed packet if no filter has
|
* sniffer's filter, or the first sniffed packet if no filter has
|
||||||
* been set.
|
* been set.
|
||||||
* \return The captured packet, matching the given filter, 0 if an
|
* \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();
|
PDU *next_packet();
|
||||||
|
|
||||||
|
|||||||
@@ -65,23 +65,16 @@ bool BaseSniffer::compile_set_filter(const string &filter, bpf_program &prog) {
|
|||||||
PDU *BaseSniffer::next_packet() {
|
PDU *BaseSniffer::next_packet() {
|
||||||
pcap_pkthdr header;
|
pcap_pkthdr header;
|
||||||
PDU *ret = 0;
|
PDU *ret = 0;
|
||||||
while(!ret) {
|
const u_char *content = pcap_next(handle, &header);
|
||||||
const u_char *content = pcap_next(handle, &header);
|
if(content) {
|
||||||
if(content) {
|
if(iface_type == DLT_EN10MB)
|
||||||
try {
|
ret = new EthernetII((const uint8_t*)content, header.caplen);
|
||||||
if(iface_type == DLT_EN10MB)
|
else if(iface_type == DLT_IEEE802_11_RADIO)
|
||||||
ret = new EthernetII((const uint8_t*)content, header.caplen);
|
ret = new RadioTap((const uint8_t*)content, header.caplen);
|
||||||
else if(iface_type == DLT_IEEE802_11_RADIO)
|
else if(iface_type == DLT_IEEE802_11)
|
||||||
ret = new RadioTap((const uint8_t*)content, header.caplen);
|
ret = Dot11::from_bytes((const uint8_t*)content, header.caplen);
|
||||||
else if(iface_type == DLT_IEEE802_11)
|
else if(iface_type == DLT_LOOP)
|
||||||
ret = Dot11::from_bytes((const uint8_t*)content, header.caplen);
|
ret = new Tins::Loopback((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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user