Justin Mason said: > -----BEGIN PGP SIGNED MESSAGE----- >> + for (my $i = 0; (!$sock && ($i<64511)); $i++) { >> + my $lport = 1024 + (($port_offset + $i) % 64511); >> + $sock = IO::Socket::INET->new ( >> + Proto => 'udp', >> + LocalPort => $lport, [...] > > as a matter of interest -- what will happen here if the port *is* > already in use?
What is supposed to happen, confirmed on the systems I tested on, is that IO::Socket->new returns undef and the for loop tries the next port number. That is the purpose of the for loop, to find the next unused port in the same way that IO::Socket->new(Proto=>'udp', LocalPort=>undef) does, except making sure that we start at a random number. If all sockets between the random number and 64K are in use, then $self->{sock} is set to undef. If the caller is not DnsResolver->bgsend, then that is fine -- When there is a call to DnsResolver->bgsend it will notice that and call connect_sock. If this happens in DnsResolver->bgsend's call to connect_sock, the return of undef will cause bgsend to return undef, logging a warning that a send has failed. That should be no worse than any other one-time failure of a DNS query. -- sidney