Browse Source

- 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 20 years ago
parent
commit
e6b442bda9
2 changed files with 41 additions and 30 deletions
  1. 1 1
      Makefile.defs
  2. 40 29
      udp_server.c

+ 1 - 1
Makefile.defs

@@ -53,7 +53,7 @@ MAIN_NAME=ser
 VERSION = 0
 PATCHLEVEL = 10
 SUBLEVEL =   99
-EXTRAVERSION = -dev4
+EXTRAVERSION = -dev5
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 40 - 29
udp_server.c

@@ -34,6 +34,7 @@
  *              added set multicast ttl support (andrei)
  *  2004-07-05  udp_rcv_loop: drop packets with 0 src port + error msg.
  *              cleanups (andrei)
+ *  2005-03-10  multicast options are now set for all the udp sockets (andrei)
  */
 
 
@@ -235,20 +236,6 @@ static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
 			return -1;
 		}
 		
-		if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, 
-			       &mcast_loopback, sizeof(mcast_loopback))==-1){
-			LOG(L_ERR, "ERROR: setup_mcast_rcvr: setsockopt: %s\n",
-			    strerror(errno));
-			return -1;
-		}
-		if (mcast_ttl>=0){
-			if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &mcast_ttl,
-						sizeof(mcast_ttl))==-1){
-				LOG(L_ERR, "ERROR: setup_mcast_rcvr: setosckopt (ttl):"
-						" %s\n", strerror(errno));
-				return -1;
-			}
-		}
 #ifdef USE_IPV6
 	} else if (addr->s.sa_family==AF_INET6){
 		memcpy(&mreq6.ipv6mr_multiaddr, &addr->sin6.sin6_addr, 
@@ -265,23 +252,9 @@ static int setup_mcast_rcvr(int sock, union sockaddr_union* addr)
 			return -1;
 		}
 		
-		if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
-			       &mcast_loopback, sizeof(mcast_loopback))==-1){
-			LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", 
-			    strerror(errno));
-			return -1;
-		}
-		if (mcast_ttl>=0){
-			if (setsockopt(sock, IPPROTO_IP, IPV6_MULTICAST_HOPS, &mcast_ttl,
-						sizeof(mcast_ttl))==-1){
-				LOG(L_ERR, "ERROR: setup_mcast_rcvr: setosckopt (ttlv6):"
-						" %s\n", strerror(errno));
-				return -1;
-			}
-		}
 #endif /* USE_IPV6 */
 	} else {
-		LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family\n");
+		LOG(L_ERR, "ERROR: setup_mcast_rcvr: Unsupported protocol family\n");
 		return -1;
 	}
 	return 0;
@@ -342,6 +315,44 @@ int udp_init(struct socket_info* sock_info)
 	    && (setup_mcast_rcvr(sock_info->socket, addr)<0)){
 			goto error;
 	}
+	/* set the multicast options */
+	if (addr->s.sa_family==AF_INET){
+		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_LOOP, 
+						&mcast_loopback, sizeof(mcast_loopback))==-1){
+			LOG(L_ERR, "ERROR: udp_init: setsockopt(IP_MULTICAST_LOOP): %s\n",
+						strerror(errno));
+			goto error;
+		}
+		if (mcast_ttl>=0){
+			if (setsockopt(sock_info->socket, IPPROTO_IP, IP_MULTICAST_TTL,
+						&mcast_ttl, sizeof(mcast_ttl))==-1){
+				LOG(L_ERR, "ERROR: udp_init: setsockopt (IP_MULTICAST_TTL):"
+						" %s\n", strerror(errno));
+				goto error;
+			}
+		}
+#ifdef USE_IPV6
+	} else if (addr->s.sa_family==AF_INET6){
+		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
+						&mcast_loopback, sizeof(mcast_loopback))==-1){
+			LOG(L_ERR, "ERROR: udp_init: setsockopt (IPV6_MULTICAST_LOOP):"
+					" %s\n", strerror(errno));
+			goto error;
+		}
+		if (mcast_ttl>=0){
+			if (setsockopt(sock_info->socket, IPPROTO_IP, IPV6_MULTICAST_HOPS,
+							&mcast_ttl, sizeof(mcast_ttl))==-1){
+				LOG(L_ERR, "ERROR: udp_init: setssckopt (IPV6_MULTICAST_HOPS):"
+						" %s\n", strerror(errno));
+				goto error;
+			}
+		}
+#endif /* USE_IPV6*/
+	} else {
+		LOG(L_ERR, "ERROR: udp_init: Unsupported protocol family %d\n",
+					addr->s.sa_family);
+		goto error;
+	}
 #endif /* USE_MCAST */
 
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;