Browse code

- multicast fixes backported: multicast options are set for all the sockets, multicast ttl & loop options are properly set (they work on *BSD too)

Andrei Pelinescu-Onciul authored on 26/07/2005 14:45:46
Showing 2 changed files
... ...
@@ -58,7 +58,7 @@ MAIN_NAME=ser
58 58
 VERSION = 0
59 59
 PATCHLEVEL = 9
60 60
 SUBLEVEL = 4
61
-EXTRAVERSION = -rc1
61
+EXTRAVERSION = -rc2
62 62
 
63 63
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
64 64
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -34,6 +34,8 @@
34 34
  *              added set multicast ttl support (andrei)
35 35
  *  2004-07-05  udp_rcv_loop: drop packets with 0 src port + error msg.
36 36
  *              cleanups (andrei)
37
+ *  2005-07-26  multicast fixes backported: multicast ttl & loop are set
38
+ *              for all the sockets; ipv4 ttl & loop expect a char* (andrei)
37 39
  */
38 40
 
39 41
 
... ...
@@ -234,21 +236,6 @@ static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
234 236
 			    strerror(errno));
235 237
 			return -1;
236 238
 		}
237
-		
238
-		if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, 
239
-			       &mcast_loopback, sizeof(mcast_loopback))==-1){
240
-			LOG(L_ERR, "ERROR: setup_mcast_rcvr: setsockopt: %s\n",
241
-			    strerror(errno));
242
-			return -1;
243
-		}
244
-		if (mcast_ttl>=0){
245
-			if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &mcast_ttl,
246
-						sizeof(mcast_ttl))==-1){
247
-				LOG(L_ERR, "ERROR: setup_mcast_rcvr: setosckopt (ttl):"
248
-						" %s\n", strerror(errno));
249
-				return -1;
250
-			}
251
-		}
252 239
 #ifdef USE_IPV6
253 240
 	} else if (addr->s.sa_family==AF_INET6){
254 241
 		memcpy(&mreq6.ipv6mr_multiaddr, &addr->sin6.sin6_addr, 
... ...
@@ -265,23 +252,9 @@ static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
265 252
 			return -1;
266 253
 		}
267 254
 		
268
-		if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
269
-			       &mcast_loopback, sizeof(mcast_loopback))==-1){
270
-			LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", 
271
-			    strerror(errno));
272
-			return -1;
273
-		}
274
-		if (mcast_ttl>=0){
275
-			if (setsockopt(sock, IPPROTO_IP, IPV6_MULTICAST_HOPS, &mcast_ttl,
276
-						sizeof(mcast_ttl))==-1){
277
-				LOG(L_ERR, "ERROR: setup_mcast_rcvr: setosckopt (ttlv6):"
278
-						" %s\n", strerror(errno));
279
-				return -1;
280
-			}
281
-		}
282 255
 #endif /* USE_IPV6 */
283 256
 	} else {
284
-		LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family\n");
257
+		LOG(L_ERR, "ERROR: setup_mcast_rcvr: Unsupported protocol family\n");
285 258
 		return -1;
286 259
 	}
287 260
 	return 0;
... ...
@@ -294,6 +267,9 @@ int udp_init(struct socket_info* sock_info)
294 267
 {
295 268
 	union sockaddr_union* addr;
296 269
 	int optval;
270
+#ifdef USE_MCAST
271
+	unsigned char m_ttl, m_loop;
272
+#endif
297 273
 	addr=&sock_info->su;
298 274
 /*
299 275
 	addr=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
... ...
@@ -342,6 +318,44 @@ int udp_init(struct socket_info* sock_info)
342 318
 	    && (setup_mcast_rcvr(sock_info->socket, addr)<0)){
343 319
 			goto error;
344 320
 	}
321
+	/* set the multicast options */
322
+	if (addr->s.sa_family==AF_INET){
323
+		m_loop=mcast_loopback;
324
+		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_LOOP, 
325
+						&m_loop, sizeof(m_loop))==-1){
326
+			LOG(L_WARN, "WARNING: udp_init: setsockopt(IP_MULTICAST_LOOP):"
327
+						" %s\n", strerror(errno));
328
+			/* it's only a warning because we might get this error if the
329
+			  network interface doesn't support multicasting -- andrei */
330
+		}
331
+		if (mcast_ttl>=0){
332
+			m_ttl=mcast_ttl;
333
+			if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_TTL,
334
+						&m_ttl, sizeof(m_ttl))==-1){
335
+				LOG(L_WARN, "WARNING: udp_init: setsockopt (IP_MULTICAST_TTL):"
336
+						" %s\n", strerror(errno));
337
+			}
338
+		}
339
+#ifdef USE_IPV6
340
+	} else if (addr->s.sa_family==AF_INET6){
341
+		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
342
+						&mcast_loopback, sizeof(mcast_loopback))==-1){
343
+			LOG(L_WARN, "WARNING: udp_init: setsockopt (IPV6_MULTICAST_LOOP):"
344
+					" %s\n", strerror(errno));
345
+		}
346
+		if (mcast_ttl>=0){
347
+			if (setsockopt(sock_info->socket, IPPROTO_IP, IPV6_MULTICAST_HOPS,
348
+							&mcast_ttl, sizeof(mcast_ttl))==-1){
349
+				LOG(L_WARN, "WARNING: udp_init: setssckopt "
350
+						"(IPV6_MULTICAST_HOPS): %s\n", strerror(errno));
351
+			}
352
+		}
353
+#endif /* USE_IPV6*/
354
+	} else {
355
+		LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family %d\n",
356
+					addr->s.sa_family);
357
+		goto error;
358
+	}
345 359
 #endif /* USE_MCAST */
346 360
 
347 361
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;