Commit 804f1882 authored by Mikio Hara's avatar Mikio Hara

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
parent 63f68a2e
...@@ -86,7 +86,7 @@ func TestListenMulticastUDP(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestListenMulticastUDP(t *testing.T) {
func TestSimpleListenMulticastUDP(t *testing.T) { func TestSimpleListenMulticastUDP(t *testing.T) {
switch runtime.GOOS { switch runtime.GOOS {
case "plan9", "windows": case "plan9":
return return
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package net package net
import ( import (
"os"
"syscall" "syscall"
) )
...@@ -16,8 +17,19 @@ func ipv4MulticastInterface(fd *netFD) (*Interface, error) { ...@@ -16,8 +17,19 @@ func ipv4MulticastInterface(fd *netFD) (*Interface, error) {
} }
func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error { func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
// TODO: Implement this ip, err := interfaceToIPv4Addr(ifi)
return syscall.EWINDOWS 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) { func ipv4MulticastTTL(fd *netFD) (int, error) {
...@@ -26,8 +38,14 @@ func ipv4MulticastTTL(fd *netFD) (int, error) { ...@@ -26,8 +38,14 @@ func ipv4MulticastTTL(fd *netFD) (int, error) {
} }
func setIPv4MulticastTTL(fd *netFD, v int) error { func setIPv4MulticastTTL(fd *netFD, v int) error {
// TODO: Implement this fd.incref()
return syscall.EWINDOWS 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) { func ipv4MulticastLoopback(fd *netFD) (bool, error) {
...@@ -36,8 +54,14 @@ func ipv4MulticastLoopback(fd *netFD) (bool, error) { ...@@ -36,8 +54,14 @@ func ipv4MulticastLoopback(fd *netFD) (bool, error) {
} }
func setIPv4MulticastLoopback(fd *netFD, v bool) error { func setIPv4MulticastLoopback(fd *netFD, v bool) error {
// TODO: Implement this fd.incref()
return syscall.EWINDOWS 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) { func ipv4ReceiveInterface(fd *netFD) (bool, error) {
......
...@@ -657,6 +657,9 @@ type IPv6Mreq struct { ...@@ -657,6 +657,9 @@ type IPv6Mreq struct {
func GetsockoptInt(fd Handle, level, opt int) (int, error) { return -1, EWINDOWS } 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 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) { 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))) return Setsockopt(fd, int32(level), int32(opt), (*byte)(unsafe.Pointer(mreq)), int32(unsafe.Sizeof(*mreq)))
} }
......
...@@ -389,8 +389,13 @@ const ( ...@@ -389,8 +389,13 @@ const (
SO_SNDBUF = 0x1001 SO_SNDBUF = 0x1001
SO_UPDATE_ACCEPT_CONTEXT = 0x700b SO_UPDATE_ACCEPT_CONTEXT = 0x700b
// cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460
IP_TOS = 0x3 IP_TOS = 0x3
IP_TTL = 0x4 IP_TTL = 0x4
IP_MULTICAST_IF = 0x9
IP_MULTICAST_TTL = 0xa
IP_MULTICAST_LOOP = 0xb
IP_ADD_MEMBERSHIP = 0xc IP_ADD_MEMBERSHIP = 0xc
IP_DROP_MEMBERSHIP = 0xd IP_DROP_MEMBERSHIP = 0xd
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment