@@ -73,8 +73,14 @@ bool cIptvSocket::OpenSocket(const int portP, const bool isUdpP)
73
73
sockAddrM .sin_port = htons ((uint16_t )(portP & 0xFFFF ));
74
74
sockAddrM .sin_addr .s_addr = htonl (INADDR_ANY );
75
75
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 ,
77
80
"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
+ }
78
84
// Update socket port
79
85
socketPortM = portP ;
80
86
}
@@ -184,11 +190,13 @@ bool cIptvUdpSocket::JoinMulticast(void)
184
190
ERROR_IF_RET (setsockopt (socketDescM , SOL_IP , MCAST_JOIN_SOURCE_GROUP , & gsr , sizeof (gsr )) < 0 , "setsockopt(MCAST_JOIN_SOURCE_GROUP)" , return false );
185
191
}
186
192
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
+ }
192
200
// Update multicasting flag
193
201
isActiveM = true;
194
202
}
@@ -218,11 +226,13 @@ bool cIptvUdpSocket::DropMulticast(void)
218
226
ERROR_IF_RET (setsockopt (socketDescM , SOL_IP , MCAST_LEAVE_SOURCE_GROUP , & gsr , sizeof (gsr )) < 0 , "setsockopt(MCAST_LEAVE_SOURCE_GROUP)" , return false );
219
227
}
220
228
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 );
225
234
}
235
+ }
226
236
// Update multicasting flag
227
237
isActiveM = false;
228
238
}
0 commit comments