Don't needlessly recalculate the direction

This commit is contained in:
Arnout Engelen
2013-05-12 17:50:55 +00:00
parent bb2a4e0480
commit 9d8555e17c

View File

@@ -169,12 +169,22 @@ Packet::Packet (in6_addr m_sip, unsigned short m_sport, in6_addr m_dip, unsigned
hashstring = NULL; hashstring = NULL;
} }
Packet * Packet::newInverted () { direction invert(direction dir) {
/* TODO if this is a bottleneck, we can calculate the direction */ if (dir == dir_incoming)
if (sa_family == AF_INET) return dir_outgoing;
return new Packet (dip, dport, sip, sport, len, time, dir_unknown); else if (dir == dir_outgoing)
return dir_incoming;
else else
return new Packet (dip6, dport, sip6, sport, len, time, dir_unknown); return dir_unknown;
}
Packet * Packet::newInverted () {
direction new_direction = invert(dir);
if (sa_family == AF_INET)
return new Packet (dip, dport, sip, sport, len, time, new_direction);
else
return new Packet (dip6, dport, sip6, sport, len, time, new_direction);
} }
/* constructs returns a new Packet() structure with the same contents as this one */ /* constructs returns a new Packet() structure with the same contents as this one */