Bugzilla – Bug 1164
IPV4 TCP Bind an already used port failed but without setting errno
Last modified: 2011-08-18 01:43:49 EDT
Binding twice the same port failed but errno is 0 for example: Ptr<Socket> server = sockFactory0->CreateSocket(); Ptr<Socket> server2 = sockFactory0->CreateSocket(); uint16_t port = 50000; InetSocketAddress serverlocaladdr (Ipv4Address::GetAny(), port); int ret = server->Bind(serverlocaladdr); ret = server2->Bind(serverlocaladdr); // ret == -1 but errno == 0... ------- I propose to add an error code in socket.h : ERROR_ADDRINUSE and patch tcp-socket-base.cc TcpSocketBase::Bind (const Address &address) like this : --- a/src/network/model/socket.h Mon Feb 21 09:11:37 2011 -0800 +++ b/src/network/model/socket.h Wed May 18 12:03:16 2011 +0200 @@ -82,6 +82,7 @@ ERROR_NOROUTETOHOST, ERROR_NODEV, ERROR_ADDRNOTAVAIL, + ERROR_ADDRINUSE, SOCKET_ERRNO_LAST }; AND --- a/src/internet/model/tcp-socket-base.cc Wed Apr 13 08:26:47 2011 +0200 +++ b/src/internet/model/tcp-socket-base.cc Wed May 18 12:05:52 2011 +0200 @@ -242,6 +242,11 @@ else if (ipv4 == Ipv4Address::GetAny () && port != 0) { m_endPoint = m_tcp->Allocate (port); + if (0 == m_endPoint) + { + m_errno = ERROR_ADDRINUSE; + return -1; + } } else if (ipv4 != Ipv4Address::GetAny () && port == 0) { @@ -250,6 +255,11 @@ else if (ipv4 != Ipv4Address::GetAny () && port != 0) { m_endPoint = m_tcp->Allocate (ipv4, port); + if (0 == m_endPoint) + { + m_errno = ERROR_ADDRINUSE; + return -1; + } } NS_LOG_LOGIC ("TcpSocketBase " << this << " got an endpoint: " << m_endPoint);
+1
changeset: 979d65377d5f