| 324 | } |
| 325 | |
| 326 | Result SetMulticastIf(Socket socket, Address address) |
| 327 | { |
| 328 | int result = -1; |
| 329 | if (IsSocketIPv4(socket)) |
| 330 | { |
| 331 | struct in_addr inaddr; |
| 332 | memset(&inaddr, 0, sizeof(inaddr)); |
| 333 | inaddr.s_addr = *IPv4(&address); |
| 334 | result = setsockopt(socket, IPPROTO_IP, IP_MULTICAST_IF, (char*)&inaddr, sizeof(inaddr)); |
| 335 | } |
| 336 | #if !defined(DM_IPV6_UNSUPPORTED) |
| 337 | else if (IsSocketIPv6(socket)) |
| 338 | { |
| 339 | struct in6_addr inaddr; |
| 340 | memcpy(&inaddr, IPv6(&address), sizeof(struct in6_addr)); |
| 341 | result = setsockopt(socket, IPPROTO_IP, IP_MULTICAST_IF, (char*)&inaddr, sizeof(inaddr)); |
| 342 | } |
| 343 | #endif // no ipv6 |
| 344 | else |
| 345 | { |
| 346 | dmLogError("Failed to enable multicast interface, unsupported address family!"); |
| 347 | return RESULT_AFNOSUPPORT; |
| 348 | } |
| 349 | |
| 350 | return result == 0 ? RESULT_OK : NATIVETORESULT(DM_SOCKET_ERRNO); |
| 351 | } |