+ # The packet is OK! Do we already have a recent enough survey
+ # for this port, or should we use this packet?
+ my $survey = 1;
+ if (exists($last_survey{$dport})) {
+ my $age = Time::HiRes::tv_interval($last_survey{$dport}, $now);
+ if ($age < $Config::survey_freq) {
+ $survey = 0;
+ }
+ }
+
+ # New survey; find an unused port
+ my $survey_sport;
+ for my $port ($Config::survey_port_low..$Config::survey_port_high) {
+ if (!exists($active_surveys{$port})) {
+ $survey_sport = $port;
+
+ $active_surveys{$port} = {
+ start => $now,
+ active => 1,
+ dport => $dport,
+ num => 0
+ };
+ $last_survey{$dport} = $now;
+
+ last;
+ }
+ }
+
+ if (!defined($survey_sport)) {
+ print "WARNING: no free survey source ports, not surveying.\n";
+ $survey = 0;
+ }