Re: connecting an unbound socket to itself

From: Serge Belyshev
Date: Fri Apr 18 2008 - 18:44:54 EST


David Miller <davem@xxxxxxxxxxxxx> writes:

> From: Serge Belyshev <belyshev@xxxxxxxxxxxxxxxxx>
> Date: Sat, 19 Apr 2008 02:24:04 +0400
>
>> But my socket is unbound and I'm connecting to a loopback address, so
>> I expect the connection to fail if nobody listens on the port I am
>> connecting to. Yet the connections succeedes on the rare occasion when
>> the kernel chooses the source port number that matches the destination.
>
> At the point you do a connect() you are "listening" on that
> port and can be connected to.

Okay, so to reliably detect the case when nobody else but me is
"listening" on that port I should do bind() (with a different port)
instead of relying on the kernel, right?
--
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html