Browse code

- multicast parameters (ttl, local loopback) are now set on all the udp sockets (they might be used to send a msg. to a multicast destination); fixes reported bug.

Andrei Pelinescu-Onciul authored on 10/03/2005 12:55:46
Showing 2 changed files
... ...
@@ -53,7 +53,7 @@ MAIN_NAME=ser
53 53
 VERSION = 0
54 54
 PATCHLEVEL = 10
55 55
 SUBLEVEL =   99
56
-EXTRAVERSION = -dev4
56
+EXTRAVERSION = -dev5
57 57
 
58 58
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
59 59
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -34,6 +34,7 @@
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-03-10  multicast options are now set for all the udp sockets (andrei)
37 38
  */
38 39
 
39 40
 
... ...
@@ -235,20 +236,6 @@ static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
235 235
 			return -1;
236 236
 		}
237 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 238
 #ifdef USE_IPV6
253 239
 	} else if (addr->s.sa_family==AF_INET6){
254 240
 		memcpy(&mreq6.ipv6mr_multiaddr, &addr->sin6.sin6_addr, 
... ...
@@ -265,23 +252,9 @@ static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
265 265
 			return -1;
266 266
 		}
267 267
 		
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 268
 #endif /* USE_IPV6 */
283 269
 	} else {
284
-		LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family\n");
270
+		LOG(L_ERR, "ERROR: setup_mcast_rcvr: Unsupported protocol family\n");
285 271
 		return -1;
286 272
 	}
287 273
 	return 0;
... ...
@@ -342,6 +315,44 @@ int udp_init(struct socket_info* sock_info)
342 342
 	    && (setup_mcast_rcvr(sock_info->socket, addr)<0)){
343 343
 			goto error;
344 344
 	}
345
+	/* set the multicast options */
346
+	if (addr->s.sa_family==AF_INET){
347
+		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_LOOP, 
348
+						&mcast_loopback, sizeof(mcast_loopback))==-1){
349
+			LOG(L_ERR, "ERROR: udp_init: setsockopt(IP_MULTICAST_LOOP): %s\n",
350
+						strerror(errno));
351
+			goto error;
352
+		}
353
+		if (mcast_ttl>=0){
354
+			if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_TTL,
355
+						&mcast_ttl, sizeof(mcast_ttl))==-1){
356
+				LOG(L_ERR, "ERROR: udp_init: setsockopt (IP_MULTICAST_TTL):"
357
+						" %s\n", strerror(errno));
358
+				goto error;
359
+			}
360
+		}
361
+#ifdef USE_IPV6
362
+	} else if (addr->s.sa_family==AF_INET6){
363
+		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
364
+						&mcast_loopback, sizeof(mcast_loopback))==-1){
365
+			LOG(L_ERR, "ERROR: udp_init: setsockopt (IPV6_MULTICAST_LOOP):"
366
+					" %s\n", strerror(errno));
367
+			goto error;
368
+		}
369
+		if (mcast_ttl>=0){
370
+			if (setsockopt(sock_info->socket, IPPROTO_IP, IPV6_MULTICAST_HOPS,
371
+							&mcast_ttl, sizeof(mcast_ttl))==-1){
372
+				LOG(L_ERR, "ERROR: udp_init: setssckopt (IPV6_MULTICAST_HOPS):"
373
+						" %s\n", strerror(errno));
374
+				goto error;
375
+			}
376
+		}
377
+#endif /* USE_IPV6*/
378
+	} else {
379
+		LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family %d\n",
380
+					addr->s.sa_family);
381
+		goto error;
382
+	}
345 383
 #endif /* USE_MCAST */
346 384
 
347 385
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;