Skip to content

Commit bbac2ec

Browse files
authored
Replace remaining rfind_pdu calls to find_pdu in src directory (#527)
This commit replaces the remaining `rfind_pdu` calls to `find_pdu` in the `src` directory. Any existing `rfind_pdu` calls in the `examples` and `tests` directories are unmodified. The main motivation is that conditional statements are generally more performant than exception handling. Since `rfind_pdu` calls `find_pdu` internally anyway, this eliminates some overhead as well. Signed-off-by: James Raphael Tiovalen <[email protected]>
1 parent ba9a215 commit bbac2ec

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/crypto.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,11 @@ WPA2Decrypter::bssids_map::const_iterator WPA2Decrypter::find_ap(const Dot11Data
705705

706706
bool WPA2Decrypter::decrypt(PDU& pdu) {
707707
if (capturer_.process_packet(pdu)) {
708-
try_add_keys(pdu.rfind_pdu<Dot11Data>(), capturer_.handshakes().front());
709-
capturer_.clear_handshakes();
708+
Dot11Data* data = pdu.find_pdu<Dot11Data>();
709+
if (data) {
710+
try_add_keys(*data, capturer_.handshakes().front());
711+
capturer_.clear_handshakes();
712+
}
710713
}
711714
else if (const Dot11Beacon* beacon = pdu.find_pdu<Dot11Beacon>()) {
712715
if (aps_.count(beacon->addr3()) == 0) {

src/tcp_ip/stream.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ Stream::Stream(PDU& packet, const timestamp_type& ts)
5959
client_hw_addr_ = eth->src_addr();
6060
server_hw_addr_ = eth->dst_addr();
6161
}
62-
const TCP& tcp = packet.rfind_pdu<TCP>();
63-
// If this is not the first packet of a stream (SYN), then it's a partial stream
64-
is_partial_stream_ = !tcp.has_flags(TCP::SYN);
62+
const TCP* tcp = packet.find_pdu<TCP>();
63+
if (tcp) {
64+
// If this is not the first packet of a stream (SYN), then it's a partial stream
65+
is_partial_stream_ = !tcp->has_flags(TCP::SYN);
66+
}
6567
}
6668

6769
void Stream::process_packet(PDU& packet, const timestamp_type& ts) {

0 commit comments

Comments
 (0)