Skip to content

Commit 2040edb

Browse files
committed
Add non-multicast compatibility
1 parent 8a24ff5 commit 2040edb

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

socket.c

+20-10
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@ bool cIptvSocket::OpenSocket(const int portP, const bool isUdpP)
7373
sockAddrM.sin_port = htons((uint16_t)(portP & 0xFFFF));
7474
sockAddrM.sin_addr.s_addr = htonl(INADDR_ANY);
7575
if (isUdpP)
76-
ERROR_IF_FUNC(bind(socketDescM, (struct sockaddr *)&sockAddrM, sizeof(sockAddrM)) < 0,
76+
{
77+
int rcvbuf = 4 * 1024 * 1024;
78+
79+
ERROR_IF_FUNC(bind(socketDescM, (struct sockaddr *)&sockAddrM, sizeof(sockAddrM)) < 0,
7780
"bind()", CloseSocket(), return false);
81+
82+
ERROR_IF_RET(setsockopt(socketDescM, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(int)) < 0, "setsockopt(SO_RCVBUF)", return false);
83+
}
7884
// Update socket port
7985
socketPortM = portP;
8086
}
@@ -184,11 +190,13 @@ bool cIptvUdpSocket::JoinMulticast(void)
184190
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, MCAST_JOIN_SOURCE_GROUP, &gsr, sizeof(gsr)) < 0, "setsockopt(MCAST_JOIN_SOURCE_GROUP)", return false);
185191
}
186192
else {
187-
struct ip_mreq mreq;
188-
mreq.imr_multiaddr.s_addr = streamAddrM;
189-
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
190-
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0, "setsockopt(IP_ADD_MEMBERSHIP)", return false);
191-
}
193+
if (IN_MULTICAST(ntohl(streamAddrM))) {
194+
struct ip_mreq mreq;
195+
mreq.imr_multiaddr.s_addr = streamAddrM;
196+
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
197+
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0, "setsockopt(IP_ADD_MEMBERSHIP)", return false);
198+
}
199+
}
192200
// Update multicasting flag
193201
isActiveM = true;
194202
}
@@ -218,11 +226,13 @@ bool cIptvUdpSocket::DropMulticast(void)
218226
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, MCAST_LEAVE_SOURCE_GROUP, &gsr, sizeof(gsr)) < 0, "setsockopt(MCAST_LEAVE_SOURCE_GROUP)", return false);
219227
}
220228
else {
221-
struct ip_mreq mreq;
222-
mreq.imr_multiaddr.s_addr = streamAddrM;
223-
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
224-
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0, "setsockopt(IP_DROP_MEMBERSHIP)", return false);
229+
if (IN_MULTICAST(ntohl(streamAddrM))) {
230+
struct ip_mreq mreq;
231+
mreq.imr_multiaddr.s_addr = streamAddrM;
232+
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
233+
ERROR_IF_RET(setsockopt(socketDescM, SOL_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0, "setsockopt(IP_DROP_MEMBERSHIP)", return false);
225234
}
235+
}
226236
// Update multicasting flag
227237
isActiveM = false;
228238
}

0 commit comments

Comments
 (0)