subtle problem with bind() semantics breaks bindresvport()

Joe Buehler
Wed Sep 24 20:08:00 GMT 2003

FYI, there appears to be a subtle difference in the semantics of winsock
bind() that makes Cygwin behave differently than UNIX.

I am seeing the problem in bindresvport() in librpc.a but it looks
like this may have been seen before in ftpd if I read the mailing list
archives correctly.

On a UNIX machine, bind() will return EADDRINUSE if an attempt is made
to bind to a port that is already bound.  Winsock is subtly different.
If you use INADDR_ANY for the socket address in the bind(), you can
succeed with bind() but later on fail with connect() -- Windows is
delaying the test until it can determine whether the (proto, port,
address) triple is unique.

This breaks the usual UNIX implementation of bindresvport() that just
scans through successive ports trying bind() until one succeeds.  So
I am seeing failing rpc calls because bindresvport() is picking a
port number that Windows later refuses to use in connect().
Joe Buehler

More information about the Cygwin-developers mailing list