On Friday 26 November 2004 06:48 CET Daniel Quinlan wrote:
> [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.
If I understood that code right (which I hope), is the only safety which was
in there that the port is *not* in /etc/services.
> My system only has 3 TCP ports above 32768 listed. [...]
That means that in 32768 - 3 cases it was not checked for a collision. Now,
if it's 32768 or 32765, in my eyes it still pretty unrealistic that you hit
an already-used port twice. That's why I asked for Murphy...
Actually, I now know why it happened: I played around with a port knocking
daemon written in Java before. And that one was listening on ~1024 port
above 32768 and spamd tried to use a port out of that range.
> > 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.
I haven't actively tested it on Windows XP, but I had a look at the netstat
output there. That's why the first grep looks for spaces in front of the
"tcp" string (and it doesn't look for spaces afterwards because FreeBSD
reports the type as "tcp4"). Windows XP also has one column less than the
Unixes.
Even if it doesn't work on XP, it wouldn't matter. Then the @nstat array is
empty and the code just works as it did before.
Cheers,
Malte
--
[SGT] Simon G. Tatham: "How to Report Bugs Effectively"
<http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>
[ESR] Eric S. Raymond: "How To Ask Questions The Smart Way"
<http://www.catb.org/~esr/faqs/smart-questions.html>