Browse Source

mptsd can support unicast source

wing_pn 3 years ago
parent
commit
a96815871b
1 changed files with 16 additions and 10 deletions
  1. 16 10
      network.c

+ 16 - 10
network.c View File

@@ -202,10 +202,13 @@ int connect_source(INPUT *r, int retries, int readbuflen, int *http_code) {
202 202
 		}
203 203
 		// connected ok, continue
204 204
 	} else {
205
-		if (!IN_MULTICAST(ntohl(r->src_sockname.sin_addr.s_addr))) {
206
-			LOGf("ERR  : %s is not multicast address\n", r->channel->source);
207
-			FATAL_ERROR;
208
-		}
205
+
206
+		char multicast = IN_MULTICAST(ntohl(r->src_sockname.sin_addr.s_addr));
207
+		
208
+		//if (!IN_MULTICAST(ntohl(r->src_sockname.sin_addr.s_addr))) {
209
+		//	LOGf("ERR  : %s is not multicast address\n", r->channel->source);
210
+		//	FATAL_ERROR;
211
+		//}
209 212
 		struct ip_mreq mreq;
210 213
 		struct sockaddr_in receiving_from;
211 214
 
@@ -217,12 +220,15 @@ int connect_source(INPUT *r, int retries, int readbuflen, int *http_code) {
217 220
 		// LOGf("CONN : Listening on multicast socket %s srv_fd: %i retries left: %i\n", r->channel->source, r->sock, retries);
218 221
 		int on = 1;
219 222
 		setsockopt(r->sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
220
-		// subscribe to multicast group
221
-		memcpy(&mreq.imr_multiaddr, &(r->src_sockname.sin_addr), sizeof(struct in_addr));
222
-		mreq.imr_interface.s_addr = htonl(INADDR_ANY);
223
-		if (setsockopt(r->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
224
-			LOGf("ERR  : Failed to add IP membership on %s srv_fd: %i\n", r->channel->source, r->sock);
225
-			FATAL_ERROR;
223
+		
224
+		if (multicast)  {
225
+    		// subscribe to multicast group
226
+    		memcpy(&mreq.imr_multiaddr, &(r->src_sockname.sin_addr), sizeof(struct in_addr));
227
+    		mreq.imr_interface.s_addr = htonl(INADDR_ANY);
228
+    		if (setsockopt(r->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
229
+    			LOGf("ERR  : Failed to add IP membership on %s srv_fd: %i\n", r->channel->source, r->sock);
230
+    			FATAL_ERROR;
231
+    		}
226 232
 		}
227 233
 		// bind to the socket so data can be read
228 234
 		memset(&receiving_from, 0, sizeof(receiving_from));