I use a stl card to store stream information extracted from pcap files. When a package arrives, I use map.find to determine if there is a stream to which the package belongs. I have to use map.find twice since the packet from A to B and the packet from B to A belong to the same stream.
struct FiveTuple { unsigned short source_port; unsigned short dest_port; unsigned int source_ip_addr; unsigned int dest_ip_addr; unsigned char transport_proto_type; };
FiveTuple defines the flow. I use FiveTuple as a key element on the map.
map - map <FiveTuple, Flow, FlowCmp> where FlowCmp is a structure using memcmp to see if FiveTuple a is smaller than FiveTuple b, like the <operator. To find out if a package stream exists, I wrote the code as follows, where m is the name of the map, and five_tuple is FiveTuple with information extracted from the package:
auto it = m.find(five_tuple); if( it == m.end()) { //swap source and dest ip/port in five_tuple, it = m.find(five_tuple); if(it == m.end()) { //do something } }
In the debug version of vs2010, the result is reasonable. When I changed it to the release version, I found that instead of returning the correct iterator, the second m.find just gave me m.end most of the time. And I found that there are no problems with initialization. How to fix version release issue?
source share