mirror of
https://github.com/golang/go
synced 2024-11-24 21:20:05 -07:00
net, syscall: add IPv4 multicast helpers for windows
Also re-enable simple IPv4 multicast testing on windows. R=alex.brainman, rsc CC=golang-dev https://golang.org/cl/5605048
This commit is contained in:
parent
63f68a2eda
commit
804f1882c5
@ -86,7 +86,7 @@ func TestListenMulticastUDP(t *testing.T) {
|
||||
|
||||
func TestSimpleListenMulticastUDP(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "plan9", "windows":
|
||||
case "plan9":
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
@ -16,8 +17,19 @@ func ipv4MulticastInterface(fd *netFD) (*Interface, error) {
|
||||
}
|
||||
|
||||
func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
|
||||
// TODO: Implement this
|
||||
return syscall.EWINDOWS
|
||||
ip, err := interfaceToIPv4Addr(ifi)
|
||||
if err != nil {
|
||||
return os.NewSyscallError("setsockopt", err)
|
||||
}
|
||||
var x [4]byte
|
||||
copy(x[:], ip.To4())
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
err = syscall.SetsockoptInet4Addr(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, x)
|
||||
if err != nil {
|
||||
return os.NewSyscallError("setsockopt", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ipv4MulticastTTL(fd *netFD) (int, error) {
|
||||
@ -26,8 +38,14 @@ func ipv4MulticastTTL(fd *netFD) (int, error) {
|
||||
}
|
||||
|
||||
func setIPv4MulticastTTL(fd *netFD, v int) error {
|
||||
// TODO: Implement this
|
||||
return syscall.EWINDOWS
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_TTL, v)
|
||||
if err != nil {
|
||||
return os.NewSyscallError("setsockopt", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func ipv4MulticastLoopback(fd *netFD) (bool, error) {
|
||||
@ -36,8 +54,14 @@ func ipv4MulticastLoopback(fd *netFD) (bool, error) {
|
||||
}
|
||||
|
||||
func setIPv4MulticastLoopback(fd *netFD, v bool) error {
|
||||
// TODO: Implement this
|
||||
return syscall.EWINDOWS
|
||||
fd.incref()
|
||||
defer fd.decref()
|
||||
err := syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, boolint(v))
|
||||
if err != nil {
|
||||
return os.NewSyscallError("setsockopt", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func ipv4ReceiveInterface(fd *netFD) (bool, error) {
|
||||
|
@ -657,6 +657,9 @@ type IPv6Mreq struct {
|
||||
|
||||
func GetsockoptInt(fd Handle, level, opt int) (int, error) { return -1, EWINDOWS }
|
||||
func SetsockoptLinger(fd Handle, level, opt int, l *Linger) (err error) { return EWINDOWS }
|
||||
func SetsockoptInet4Addr(fd Handle, level, opt int, value [4]byte) (err error) {
|
||||
return Setsockopt(fd, int32(level), int32(opt), (*byte)(unsafe.Pointer(&value[0])), 4)
|
||||
}
|
||||
func SetsockoptIPMreq(fd Handle, level, opt int, mreq *IPMreq) (err error) {
|
||||
return Setsockopt(fd, int32(level), int32(opt), (*byte)(unsafe.Pointer(mreq)), int32(unsafe.Sizeof(*mreq)))
|
||||
}
|
||||
|
@ -389,8 +389,13 @@ const (
|
||||
SO_SNDBUF = 0x1001
|
||||
SO_UPDATE_ACCEPT_CONTEXT = 0x700b
|
||||
|
||||
// cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460
|
||||
|
||||
IP_TOS = 0x3
|
||||
IP_TTL = 0x4
|
||||
IP_MULTICAST_IF = 0x9
|
||||
IP_MULTICAST_TTL = 0xa
|
||||
IP_MULTICAST_LOOP = 0xb
|
||||
IP_ADD_MEMBERSHIP = 0xc
|
||||
IP_DROP_MEMBERSHIP = 0xd
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user