aboutsummaryrefslogtreecommitdiffstats
path: root/lib/UdpSocket.cpp
diff options
context:
space:
mode:
authorSergiy G <piratfm@gmail.com>2018-01-31 10:41:34 +0200
committerSergiy G <piratfm@gmail.com>2018-01-31 10:41:34 +0200
commitfdff20e96d7198124542e6d03c27e1d496c4b328 (patch)
tree2601755f48c737ecfee23cfc6b9e98d6f391de24 /lib/UdpSocket.cpp
parent16b0a22c889b27093cb703dfbfacb4af721999cd (diff)
downloaddabmod-fdff20e96d7198124542e6d03c27e1d496c4b328.tar.gz
dabmod-fdff20e96d7198124542e6d03c27e1d496c4b328.tar.bz2
dabmod-fdff20e96d7198124542e6d03c27e1d496c4b328.zip
Enabled multicast support. Fix missing header in PAPRStats
Diffstat (limited to 'lib/UdpSocket.cpp')
-rw-r--r--lib/UdpSocket.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/UdpSocket.cpp b/lib/UdpSocket.cpp
index e711577..7c99724 100644
--- a/lib/UdpSocket.cpp
+++ b/lib/UdpSocket.cpp
@@ -170,7 +170,7 @@ int UdpSocket::send(const std::vector<uint8_t>& data, InetAddress destination)
* @param groupname The multicast address to join.
* @return 0 if ok, -1 if error
*/
-int UdpSocket::joinGroup(char* groupname)
+int UdpSocket::joinGroup(const char* groupname, const char* if_addr)
{
ip_mreqn group;
if ((group.imr_multiaddr.s_addr = inet_addr(groupname)) == INADDR_NONE) {
@@ -181,7 +181,7 @@ int UdpSocket::joinGroup(char* groupname)
setInetError("Not a multicast address");
return -1;
}
- group.imr_address.s_addr = htons(INADDR_ANY);;
+ group.imr_address.s_addr = inet_addr(if_addr);
group.imr_ifindex = 0;
if (setsockopt(listenSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &group, sizeof(group))
== SOCKET_ERROR) {
@@ -261,8 +261,10 @@ UdpReceiver::~UdpReceiver() {
}
}
-void UdpReceiver::start(int port, size_t max_packets_queued) {
+void UdpReceiver::start(int port, std::string& bindto, std::string& mcastaddr, size_t max_packets_queued) {
m_port = port;
+ m_bindto = bindto;
+ m_mcastaddr = mcastaddr;
m_max_packets_queued = max_packets_queued;
m_thread = std::thread(&UdpReceiver::m_run, this);
}
@@ -288,7 +290,13 @@ void UdpReceiver::m_run()
private: atomic<bool>& m_stop;
} autoSetStop(m_stop);
- m_sock.reinit(m_port, "0.0.0.0");
+ if(IN_MULTICAST(ntohl(inet_addr(m_mcastaddr.c_str())))){
+ m_sock.reinit(m_port, m_mcastaddr);
+ m_sock.setMulticastSource(m_bindto.c_str());
+ m_sock.joinGroup(m_mcastaddr.c_str(), m_bindto.c_str());
+ } else {
+ m_sock.reinit(m_port, m_bindto);
+ }
const size_t packsize = 8192;
UdpPacket packet(packsize);