Brad Fitzpatrick | 5194744 | 2016-03-01 22:57:46 +0000 | [diff] [blame] | 1 | // Copyright 2011 The Go Authors. All rights reserved. |
Mikio Hara | cbdbdc4 | 2012-01-11 09:53:32 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Mikio Hara | cbdbdc4 | 2012-01-11 09:53:32 +0900 | [diff] [blame] | 5 | package net |
| 6 | |
| 7 | import ( |
Ian Lance Taylor | 3792db5 | 2017-02-10 14:59:38 -0800 | [diff] [blame] | 8 | "runtime" |
Mikio Hara | cbdbdc4 | 2012-01-11 09:53:32 +0900 | [diff] [blame] | 9 | "syscall" |
| 10 | ) |
| 11 | |
Mikio Hara | cbdbdc4 | 2012-01-11 09:53:32 +0900 | [diff] [blame] | 12 | func 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 Taylor | 3792db5 | 2017-02-10 14:59:38 -0800 | [diff] [blame] | 18 | err := fd.pfd.SetsockoptIPMreqn(syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, mreq) |
| 19 | runtime.KeepAlive(fd) |
| 20 | return wrapSyscallError("setsockopt", err) |
Mikio Hara | cbdbdc4 | 2012-01-11 09:53:32 +0900 | [diff] [blame] | 21 | } |
| 22 | |
Mikio Hara | cbdbdc4 | 2012-01-11 09:53:32 +0900 | [diff] [blame] | 23 | func setIPv4MulticastLoopback(fd *netFD, v bool) error { |
Ian Lance Taylor | 3792db5 | 2017-02-10 14:59:38 -0800 | [diff] [blame] | 24 | err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, boolint(v)) |
| 25 | runtime.KeepAlive(fd) |
| 26 | return wrapSyscallError("setsockopt", err) |
Mikio Hara | cbdbdc4 | 2012-01-11 09:53:32 +0900 | [diff] [blame] | 27 | } |