set source IP address in udp-socket packets
This commit is contained in:
1 parent
5b2c17667c
commit
9e698df2c0
6 files changed
+16
-20
No files matched your search
@@ -184,8 +184,10 @@ Ipv4Impl::GetAddress (uint32_t i) const
|
||||
Ipv4Address
|
||||
Ipv4Impl::GetSourceAddress (Ipv4Address destination) const
|
||||
{
|
||||
uint32_t ifIndex;
|
||||
uint32_t ifIndex = 0xffffffff;
|
||||
|
||||
bool result = m_ipv4->GetIfIndexForDestination (destination, ifIndex);
|
||||
|
||||
if (result)
|
||||
{
|
||||
return m_ipv4->GetAddress (ifIndex);
|
||||
|
||||
@@ -703,10 +703,13 @@ Ipv4L3Protocol::GetIfIndexForDestination (
|
||||
i++)
|
||||
{
|
||||
NS_DEBUG("Ipv4L3Protocol::Lookup (): Requesting Source Address");
|
||||
uint32_t ifIndex;
|
||||
uint32_t ifIndexTmp;
|
||||
|
||||
if ((*i).second->RequestIfIndex (destination, ifIndex))
|
||||
if ((*i).second->RequestIfIndex (destination, ifIndexTmp))
|
||||
{
|
||||
NS_DEBUG("Ipv4L3Protocol::GetIfIndexForDestination (): "
|
||||
"Found ifIndex " << ifIndexTmp);
|
||||
ifIndex = ifIndexTmp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,6 +406,8 @@ Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex)
|
||||
}
|
||||
|
||||
ifIndex = mRoute->GetOutputInterface(0);
|
||||
NS_DEBUG ("Ipv4StaticRouting::RequestIfIndex (): "
|
||||
"Found ifIndex " << ifIndex);
|
||||
return true;
|
||||
}
|
||||
return false; // Let other routing protocols try to handle this
|
||||
|
||||
@@ -174,7 +174,7 @@ UdpSocket::Close(void)
|
||||
int
|
||||
UdpSocket::Connect(const Address & address)
|
||||
{
|
||||
NS_DEBUG("UdpSocket::Connect (" << address << ")");
|
||||
NS_DEBUG ("UdpSocket::Connect (" << address << ")");
|
||||
|
||||
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
|
||||
m_defaultAddress = transport.GetIpv4 ();
|
||||
@@ -185,6 +185,8 @@ UdpSocket::Connect(const Address & address)
|
||||
Ptr<Ipv4> ipv4;
|
||||
ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
|
||||
m_endPoint->SetLocalAddress (ipv4->GetSourceAddress(m_defaultAddress));
|
||||
NS_DEBUG ("UdpSocket::Connect (): Local address is" <<
|
||||
m_endPoint->GetLocalAddress());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -270,4 +272,4 @@ UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port)
|
||||
NotifyDataReceived (p, address);
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
} //namespace ns3
|
||||
Reference in new issue
Block a user