Re: bind_socket uses SO_REUSEADDR
- Subject: Re: bind_socket uses SO_REUSEADDR
- From: Aris Adamantiadis <aris@xxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Fri, 23 Jun 2017 11:11:43 +0200
- To: libssh@xxxxxxxxxx
The reason we use SO_REUSEADDR is not to start two servers on the same
port. Actually that wouldn't work, the port would be marked as busy
until the application is closed. This flag is important because without
it, it can take a few minutes after the server exited or was killed
before we can bind again to the same port. It's a stupid legacy from BSD
sockets and I not aware of a single server that does not use it.
This links describes what happens without it:
Are you mistaking it with SO_REUSEPORT ?
*SO_REUSEPORT *(since Linux 3.9)
Permits multiple *AF_INET *or *AF_INET6 *sockets to be bound to an
identical socket address. This option must be set on each
socket (including the first socket) prior to calling bind(2) <http://man7.org/linux/man-pages/man2/bind.2.html>
on the socket. To prevent port hijacking, all of the
processes binding to the same address must have the same
effective UID. This option can be employed with both TCP and
If you have very specific needs about the port binding,
ssh_bind_set_fd() is the way to go
On 23/06/17 10:53, Игорь Коваленко wrote:
> I'm developing an ssh server and I came to the following problem.
> In bind_socket functional hard coded using SO_REUSEADDR socket
> option. Why is that so?
> Because of that it is possible to start two servers on the same port
> which I don't need.
> What alternatives do I have? I see the following:
> - to add new SSH_BIND_OPTIONS_REUSEADDR or something like that (but I
> need to change libssh for that)
> - to use ssh_bind_set_fd with a socket created by myself
> - something else?
Archive administrator: firstname.lastname@example.org