[Ns-bugs] [Bug 810] In TCP, Socket::GetSockName() does not return the local socket address

code@nsnam.ece.gatech.edu code at nsnam.ece.gatech.edu
Fri Feb 12 14:35:45 PST 2010


http://www.nsnam.org/bugzilla/show_bug.cgi?id=810


Tom Henderson <tomh at tomh.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tomh at tomh.org




--- Comment #1 from Tom Henderson <tomh at tomh.org>  2010-02-12 17:35:45 EDT ---
(In reply to comment #0)
> Suppose I create a TCP socket, bind it to a wildcard address, and set
> HandleAccept() as the accept callback:
> 
>   Ptr<Socket> s = Socket::CreateSocket (node, TcpSocketFactory::GetTypeId ());
>   s.Bind (InetSocketAddress (Ipv4Address::GetAny (), port);
>   s.SetAcceptCallback (
>      MakeNullCallback<bool, Ptr<Socket>, const Address&> (),
>      MakeCallback (HandleAccept));
> 
> Then when HandleAccept() calls GetSockName() on the connection socket,
> GetSockName() returns the wildcard address -- 0.0.0.0. If I bind the server
> socket to a specific address, GetSockName() does return that address.
> 
> In short, in 3.7, GetSockName() returns the address to which the server socket
> was bound, even if it's a wildcard, rather than the specific address on which
> the request arrived.
> 
> In 3.4, GetSockName() always returned the specific IP address. I don't know
> about 3.5 & 3.6.

I couldn't reproduce this error-- could you provide a test case?

The examples/tcp/tcp-large-transfer.cc uses a packet sink and binds it to the
wildcard.  I edited packet-sink.cc to call GetSockName() after it is provided
with the connected socket:

--- a/src/applications/packet-sink/packet-sink.cc       Fri Feb 12 12:12:33
2010 -0800
+++ b/src/applications/packet-sink/packet-sink.cc       Fri Feb 12 14:33:28
2010 -0800
@@ -175,6 +175,10 @@
   NS_LOG_FUNCTION (this << s << from);
   s->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this));
   m_socketList.push_back (s);
+  Address a;
+  s->GetSockName (a);
+  InetSocketAddress ia = InetSocketAddress::ConvertFrom (a);
+  NS_LOG_UNCOND ("GetSockName " << ia.GetIpv4 () << " " << ia.GetPort ());


and it outputs:

GetSockName 10.1.2.2 50000

not the wildcard.

-- 
Configure bugmail: http://www.nsnam.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Ns-bugs mailing list