blob: bd7d8344258e2418fb8ac8c36463deb19fcec96e [file] [log] [blame]
Brad Fitzpatrick51947442016-03-01 22:57:46 +00001// Copyright 2011 The Go Authors. All rights reserved.
Mikio Haracbdbdc42012-01-11 09:53:32 +09002// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Mikio Haracbdbdc42012-01-11 09:53:32 +09005package net
6
7import (
Ian Lance Taylor3792db52017-02-10 14:59:38 -08008 "runtime"
Mikio Haracbdbdc42012-01-11 09:53:32 +09009 "syscall"
10)
11
Mikio Haracbdbdc42012-01-11 09:53:32 +090012func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
13 var v int32
14 if ifi != nil {
15 v = int32(ifi.Index)
16 }
17 mreq := &syscall.IPMreqn{Ifindex: v}
Ian Lance Taylor3792db52017-02-10 14:59:38 -080018 err := fd.pfd.SetsockoptIPMreqn(syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, mreq)
19 runtime.KeepAlive(fd)
20 return wrapSyscallError("setsockopt", err)
Mikio Haracbdbdc42012-01-11 09:53:32 +090021}
22
Mikio Haracbdbdc42012-01-11 09:53:32 +090023func setIPv4MulticastLoopback(fd *netFD, v bool) error {
Ian Lance Taylor3792db52017-02-10 14:59:38 -080024 err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, boolint(v))
25 runtime.KeepAlive(fd)
26 return wrapSyscallError("setsockopt", err)
Mikio Haracbdbdc42012-01-11 09:53:32 +090027}