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 236
 			return -1;
236 237
 		}
237 238
 		
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;
... ...
@@ -342,6 +315,44 @@ int udp_init(struct socket_info* sock_info)
342 315
 	    && (setup_mcast_rcvr(sock_info->socket, addr)<0)){
343 316
 			goto error;
344 317
 	}
318
+	/* set the multicast options */
319
+	if (addr->s.sa_family==AF_INET){
320
+		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_LOOP, 
321
+						&mcast_loopback, sizeof(mcast_loopback))==-1){
322
+			LOG(L_ERR, "ERROR: udp_init: setsockopt(IP_MULTICAST_LOOP): %s\n",
323
+						strerror(errno));
324
+			goto error;
325
+		}
326
+		if (mcast_ttl>=0){
327
+			if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_TTL,
328
+						&mcast_ttl, sizeof(mcast_ttl))==-1){
329
+				LOG(L_ERR, "ERROR: udp_init: setsockopt (IP_MULTICAST_TTL):"
330
+						" %s\n", strerror(errno));
331
+				goto error;
332
+			}
333
+		}
334
+#ifdef USE_IPV6
335
+	} else if (addr->s.sa_family==AF_INET6){
336
+		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
337
+						&mcast_loopback, sizeof(mcast_loopback))==-1){
338
+			LOG(L_ERR, "ERROR: udp_init: setsockopt (IPV6_MULTICAST_LOOP):"
339
+					" %s\n", strerror(errno));
340
+			goto error;
341
+		}
342
+		if (mcast_ttl>=0){
343
+			if (setsockopt(sock_info->socket, IPPROTO_IP, IPV6_MULTICAST_HOPS,
344
+							&mcast_ttl, sizeof(mcast_ttl))==-1){
345
+				LOG(L_ERR, "ERROR: udp_init: setssckopt (IPV6_MULTICAST_HOPS):"
346
+						" %s\n", strerror(errno));
347
+				goto error;
348
+			}
349
+		}
350
+#endif /* USE_IPV6*/
351
+	} else {
352
+		LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family %d\n",
353
+					addr->s.sa_family);
354
+		goto error;
355
+	}
345 356
 #endif /* USE_MCAST */
346 357
 
347 358
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;