--- a/src/internet-stack/udp-socket-impl.cc Tue Jun 15 18:32:04 2010 +0100
+++ b/src/internet-stack/udp-socket-impl.cc Fri Jun 18 17:18:59 2010 +0100
@@ -66,6 +66,7 @@
m_rxAvailable (0)
{
NS_LOG_FUNCTION_NOARGS ();
+ m_allowBroadcast = false;
}
UdpSocketImpl::~UdpSocketImpl ()
@@ -370,6 +371,11 @@
//
if (dest.IsBroadcast ())
{
+ if (!m_allowBroadcast)
+ {
+ m_errno = ERROR_OPNOTSUPP;
+ return -1;
+ }
NS_LOG_LOGIC ("Limited broadcast start.");
for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
{
@@ -431,6 +437,21 @@
if (route != 0)
{
NS_LOG_LOGIC ("Route exists");
+ if (!m_allowBroadcast)
+ {
+ uint32_t outputIfIndex = ipv4->GetInterfaceForDevice (route->GetOutputDevice ());
+ uint32_t ifNAddr = ipv4->GetNAddresses (outputIfIndex);
+ for (uint32_t addrI = 0; addrI < ifNAddr; ++addrI)
+ {
+ Ipv4InterfaceAddress ifAddr = ipv4->GetAddress (outputIfIndex, addrI);
+ if (dest == ifAddr.GetBroadcast ())
+ {
+ m_errno = ERROR_OPNOTSUPP;
+ return -1;
+ }
+ }
+ }
+
header.SetSource (route->GetSource ());
m_udp->Send (p->Copy (), header.GetSource (), header.GetDestination (),
m_endPoint->GetLocalPort (), port, route);
@@ -706,10 +727,7 @@
void
UdpSocketImpl::SetAllowBroadcast (bool allowBroadcast)
{
- if (!allowBroadcast)
- {
- NS_FATAL_ERROR ("not implemented");
- }
+ m_allowBroadcast = allowBroadcast;
}
bool
--- a/src/internet-stack/udp-socket-impl.h Tue Jun 15 18:32:04 2010 +0100
+++ b/src/internet-stack/udp-socket-impl.h Fri Jun 18 17:18:59 2010 +0100
@@ -120,7 +120,8 @@
bool m_shutdownSend;
bool m_shutdownRecv;
bool m_connected;
-
+ bool m_allowBroadcast;
+
std::queue<Ptr<Packet> > m_deliveryQueue;
uint32_t m_rxAvailable;