my %sip; # create sip hash to store all sip packets in to $run = 1; #search a directory for pcap files and list all matchign to dump list array. for each of those pcaps (unless it one with current time in name), open it for each packet initiate 'process_packet' sub routine while ($run == "1") { system('cls'); my $shortTime = currentTime_short(); my @dumpList = glob("C:/*.pcap"); if (@dumpList) { foreach $dump(@dumpList) { if ($dump =~ m/$shortTime/) { system('cls'); print "DO NOT TOUCH THIS FILE IT IS CURRENTLY BEING USED\n\n"; sleep(10); } else { $pcap = pcap_open_offline($dump, \$err) or die "Can't read '$dump': $err\n"; pcap_loop($pcap, -1, \&process_packet,''); pcap_close($pcap); # call mix_packets sub routine here here mix_packets(); print "done!\n"; sleep(10); }; }; } else { print "No pcaps found. trying again in 10 seconds.\n"; sleep(2); }; }; #if the packet has rtp in it.. initiate rtp sub.. if sip then sip route etc. sub process_packet { my ($user_data, $header, $packet) = @_; if( $packet !~ m/sip/ && $packet !~ m/sdp/ ) { process_rtp(@_); } elsif ( $packet =~ m/sip/) { if ( $packet =~ m/sdp/) { process_sdp(@_); } else { process_sip(@_); }; }; } sub process_sip { my ($user_data, $header, $packet) = @_; # assign every sip PACKET to the sip hash.. increase is a sub routine which creates a new number every time its called to act as the key. $sip{increase()} = $packet; }; sub mix_packets { my $callid; my %main_hash; # having previous assigned all sip packets from the current pcap into several values in the global %sip hash. we will now go through each, and create a 'main_hash' with keys acting as hashes of hashes, named as 'callids' with all packets with the same 'callid' going into that key. foreach $value (values %sip) { my $asccidata = substr($value,42); my $sip_pkt = Net::SIP::Packet->new_from_string($asccidata); my $callid=$sip_pkt->get_header('call-id'); if (exists $main_hash{$callid}) { print "there is a key in the main hash with this packets callid in it\n"; $main_hash{$callid} = { increase() => $value, }; } else { print "there is no key in the main hash with this packets callid in it\n"; $main_hash{$callid} = { increase() => $value, } }; } };