Re: connecting an unbound socket to itself

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Serge Belyshev <belyshev@xxxxxxxxxxxxxxxxx>
Date: Sat, 19 Apr 2008 02:44:48 +0400

> 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?

If you bind to a local port, then connect to the same local port
it's still going to work.

You're only going to avoid the situation if you bind to a local
port and specifically connect to a different port.
--
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

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux