Liu's GetSockName patch
This commit is contained in:
@@ -64,6 +64,8 @@ NscTcpSocketImpl::GetTypeId ()
|
||||
: m_endPoint (0),
|
||||
m_node (0),
|
||||
m_tcp (0),
|
||||
m_localAddress (Ipv4Address::GetZero ()),
|
||||
m_localPort (0),
|
||||
m_peerAddress ("0.0.0.0", 0),
|
||||
m_errno (ERROR_NOTERROR),
|
||||
m_shutdownSend (false),
|
||||
@@ -466,6 +468,14 @@ NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
return packet;
|
||||
}
|
||||
|
||||
int
|
||||
NscTcpSocketImpl::GetSockName (Address &address) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
address = InetSocketAddress(m_localAddress, m_localPort);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
NscTcpSocketImpl::GetRxAvailable (void) const
|
||||
{
|
||||
|
||||
@@ -81,6 +81,7 @@ public:
|
||||
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
||||
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
virtual int GetSockName (Address &address) const;
|
||||
|
||||
private:
|
||||
void NSCWakeup(void);
|
||||
|
||||
@@ -62,6 +62,8 @@ TcpSocketImpl::GetTypeId ()
|
||||
m_endPoint (0),
|
||||
m_node (0),
|
||||
m_tcp (0),
|
||||
m_localAddress (Ipv4Address::GetZero ()),
|
||||
m_localPort (0),
|
||||
m_errno (ERROR_NOTERROR),
|
||||
m_shutdownSend (false),
|
||||
m_shutdownRecv (false),
|
||||
@@ -553,6 +555,14 @@ TcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
return packet;
|
||||
}
|
||||
|
||||
int
|
||||
TcpSocketImpl::GetSockName (Address &address) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
address = InetSocketAddress(m_localAddress, m_localPort);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
|
||||
{
|
||||
|
||||
@@ -94,6 +94,7 @@ public:
|
||||
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
||||
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
virtual int GetSockName (Address &address) const;
|
||||
|
||||
private:
|
||||
friend class Tcp;
|
||||
|
||||
@@ -437,6 +437,21 @@ UdpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
return packet;
|
||||
}
|
||||
|
||||
int
|
||||
UdpSocketImpl::GetSockName (Address &address) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
if (m_endPoint != 0)
|
||||
{
|
||||
address = InetSocketAddress (m_endPoint->GetLocalAddress (), m_endPoint->GetLocalPort());
|
||||
}
|
||||
else
|
||||
{
|
||||
address = InetSocketAddress(Ipv4Address::GetZero(), 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
UdpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
|
||||
{
|
||||
|
||||
@@ -73,6 +73,7 @@ public:
|
||||
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
||||
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
virtual int GetSockName (Address &address) const;
|
||||
|
||||
private:
|
||||
// Attributes set through UdpSocket base class
|
||||
|
||||
@@ -57,6 +57,8 @@ PacketSocket::PacketSocket () : m_rxAvailable (0)
|
||||
m_shutdownSend = false;
|
||||
m_shutdownRecv = false;
|
||||
m_errno = ERROR_NOTERROR;
|
||||
m_isSingleDevice = false;
|
||||
m_device = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -429,4 +431,27 @@ PacketSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)
|
||||
return packet;
|
||||
}
|
||||
|
||||
int
|
||||
PacketSocket::GetSockName (Address &address) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
PacketSocketAddress ad = PacketSocketAddress::ConvertFrom(address);
|
||||
|
||||
ad.SetProtocol (m_protocol);
|
||||
if (m_isSingleDevice)
|
||||
{
|
||||
Ptr<NetDevice> device = m_node->GetDevice (ad.GetSingleDevice ());
|
||||
ad.SetPhysicalAddress(device->GetAddress());
|
||||
ad.SetSingleDevice (m_device);
|
||||
}
|
||||
else
|
||||
{
|
||||
ad.SetPhysicalAddress(Address());
|
||||
ad.SetAllDevices ();
|
||||
}
|
||||
address = ad;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -101,6 +101,7 @@ public:
|
||||
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
||||
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
virtual int GetSockName (Address &address) const;
|
||||
|
||||
private:
|
||||
void ForwardUp (Ptr<NetDevice> device, Ptr<const Packet> packet,
|
||||
|
||||
@@ -487,6 +487,10 @@ public:
|
||||
*/
|
||||
int RecvFrom (uint8_t* buf, uint32_t size, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
/**
|
||||
* \returns the address name this socket is associated with.
|
||||
*/
|
||||
virtual int GetSockName (Address &address) const = 0;
|
||||
|
||||
protected:
|
||||
void NotifyConnectionSucceeded (void);
|
||||
|
||||
Reference in New Issue
Block a user