Hi,
I'm assuming that you did spend less than 10 seconds trying to figure out what's the issue.
There is also the corollary option:
a) you have not understood fully how TCP/IP works for real (not only in ns-3, in real systems too).
Now, since I'm in a good mood (imagine how I am when I'm in a bad mood!) I'll explain what's going on.
What's wrong asking a socket its IPv6 address? Simple: ONLY a TCP socket can have a local address, and it can have one just AFTER a successfully connect (3 way handshake) with another node.
This is not a ns-3 problem, this is real stuff. One node can have multiple IP address. It always have more than one, even in IPv4 (normal one and 127.0.0.1). So what's the address the socket is bound to ?
You'll know when the socket is actually connected and its connection-oriented nature is in place. However only TCP is connection-oriented, UDP and RawIP are not. So they don't have any "name".
Try the following: open a socket (in your computer), then open two connections to it, one from your own PC, one from another one. The socket will use 127.0.0.1 or the public IP address, depending on the source. But this just AFTER the connect. Before it will return zero, as it's not connected and doesn't have any name.
Note: if you're wondering... yes you can bound a socket to a specific IP address, but that's just a packet filter. The fact that the socket does not have a name still holds. Names are for named (connection oriented and connected) sockets.
And now, since I'm still in a good mood, I'll tell you also what was your original error.
You found the GetSockName function and you did read what it does. However there's no written any warning about the fact that it only works for TCP and connected. So you used it.
Mistake number 1: you don't know about real sockets.
You found it doesn't give you the IP address and you did not dig in the code.
TcpSocketBase::GetSockName (Address &address) const
{
NS_LOG_FUNCTION (this);
if (m_endPoint != 0)
{
address = InetSocketAddress (m_endPoint->GetLocalAddress (), m_endPoint->GetLocalPort ());
}
Ipv4EndPoint::GetLocalAddress (void)
{
return m_localAddr;
}
void
Ipv4EndPoint::SetLocalAddress (Ipv4Address address)
{
m_localAddr = address;
}
search for who's calling Ipv4EndPoint::SetLocalAddress:
/** Configure the endpoint to a local address. Called by Connect() if Bind() didn't specify one. */
int
TcpSocketBase::SetupEndpoint ()
Was it so hard ?
The answer in "how to do it right" in the next post.
T.