src/applications/packet-sink/packet-sink.cc
changeset 4472 e20a31541404
parent 4014 b6349d9c007e
child 4520 c2b1a2145ae5
--- a/src/applications/packet-sink/packet-sink.cc	Thu May 28 20:16:56 2009 +0200
+++ b/src/applications/packet-sink/packet-sink.cc	Thu May 28 21:37:25 2009 -0700
@@ -18,10 +18,12 @@
  * Author:  Tom Henderson (tomhend@u.washington.edu)
  */
 #include "ns3/address.h"
+#include "ns3/address-utils.h"
 #include "ns3/log.h"
 #include "ns3/inet-socket-address.h"
 #include "ns3/node.h"
 #include "ns3/socket.h"
+#include "ns3/udp-socket.h"
 #include "ns3/simulator.h"
 #include "ns3/socket-factory.h"
 #include "ns3/packet.h"
@@ -88,6 +90,19 @@
       m_socket = Socket::CreateSocket (GetNode(), m_tid);
       m_socket->Bind (m_local);
       m_socket->Listen ();
+      if (addressUtils::IsMulticast (m_local))
+        {
+          Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket);
+          if (udpSocket)
+            {
+              // equivalent to setsockopt (MCAST_JOIN_GROUP)
+              udpSocket->MulticastJoinGroup (0, m_local);
+            }
+          else
+            {
+              NS_FATAL_ERROR ("Error: joining multicast on a non-UDP socket");
+            }
+        }
     }
 
   m_socket->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this));