[EMAIL PROTECTED] writes:

> What's the probability that I run into an already used port with the
> new probably_unused_spamd_port() code?  Less than 1 per mill?  Ask
> Murphy...

The only chance of a collision is if the port is listed in
/etc/services.  My system only has 3 TCP ports above 32768 listed.  So
if my math is right, that's a 0.0000003% chance of a collision between
two processes.  The purely random code had a 0.1% chance of a collision
between two processes (running at the same time which could happen),
mostly because it only used 1000 ports.  A 32768-port random version
would have a 0.003% chance of a collision.
 
> The routine now tries to ask netstat if that port is already in use.
> I tested the pattern on Linux, FreeBSD and Windows.  If netstat can't
> be run, no harm is done, the routine will just work as before.  The
> grep is pretty broad, it might also catch a remote port; then it just
> tries the next random one.  (Hey Murphy, it really can't hit a used
> port ten times, can it?)

I'm not a big fan of shell calls, but it looks (untested) like it'll
work on Windows XP too.

Daniel

-- 
Daniel Quinlan
http://www.pathname.com/~quinlan/

Reply via email to