+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
+#ifdef SO_REUSEPORT
+ setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes));
+#endif
+
+ switch (type) {
+ case SOCK_UC_IPV4:
+ case SOCK_UC_IPV6:
+ break;
+ case SOCK_MC_IPV4:
+ setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
+ setsockopt(fd, IPPROTO_IP, IP_TTL, &ittl, sizeof(ittl));
+ setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &no, sizeof(no));
+ local.sin_port = htons(MCAST_PORT);
+ break;
+ case SOCK_MC_IPV6:
+ setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl));
+ setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl));
+ setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes));
+ setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &no, sizeof(no));
+ local6.sin6_port = htons(MCAST_PORT);
+ break;