Commit 68e5815b authored by Mikio Hara's avatar Mikio Hara

go.net/ipv4: fix ancillary data socket option tests on old darwin

Looks like their UDP stacks don't support ancillary data socket options.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/153330043
parent 6a20d029
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
package ipv4_test
import (
"os"
"syscall"
)
func protocolNotSupported(err error) bool {
switch err := err.(type) {
case syscall.Errno:
if err == syscall.EPROTONOSUPPORT {
return true
}
case *os.SyscallError:
switch err := err.Err.(type) {
case syscall.Errno:
if err == syscall.EPROTONOSUPPORT {
return true
}
}
}
return false
}
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build nacl plan9
package ipv4_test
func protocolNotSupported(err error) bool {
return false
}
...@@ -62,7 +62,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) { ...@@ -62,7 +62,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface
for i, toggle := range []bool{true, false, true} { for i, toggle := range []bool{true, false, true} {
if err := p.SetControlMessage(cf, toggle); err != nil { if err := p.SetControlMessage(cf, toggle); err != nil && !protocolNotSupported(err) {
t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err)
} }
if err := p.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil { if err := p.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil {
...@@ -135,7 +135,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { ...@@ -135,7 +135,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("icmp.Message.Marshal failed: %v", err) t.Fatalf("icmp.Message.Marshal failed: %v", err)
} }
if err := p.SetControlMessage(cf, toggle); err != nil { if err := p.SetControlMessage(cf, toggle); err != nil && !protocolNotSupported(err) {
t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err)
} }
if err := p.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil { if err := p.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil {
...@@ -228,7 +228,7 @@ func TestRawConnReadWriteMulticastICMP(t *testing.T) { ...@@ -228,7 +228,7 @@ func TestRawConnReadWriteMulticastICMP(t *testing.T) {
Protocol: 1, Protocol: 1,
Dst: dst.IP, Dst: dst.IP,
} }
if err := r.SetControlMessage(cf, toggle); err != nil { if err := r.SetControlMessage(cf, toggle); err != nil && !protocolNotSupported(err) {
t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", err)
} }
if err := r.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil { if err := r.SetDeadline(time.Now().Add(200 * time.Millisecond)); err != nil {
......
...@@ -113,7 +113,7 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) { ...@@ -113,7 +113,7 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface cf := ipv4.FlagTTL | ipv4.FlagDst | ipv4.FlagInterface
for i, toggle := range []bool{true, false, true} { for i, toggle := range []bool{true, false, true} {
if err := p.SetControlMessage(cf, toggle); err != nil { if err := p.SetControlMessage(cf, toggle); err != nil && !protocolNotSupported(err) {
t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err)
} }
p.SetTTL(i + 1) p.SetTTL(i + 1)
...@@ -173,7 +173,7 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { ...@@ -173,7 +173,7 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("icmp.Message.Marshal failed: %v", err) t.Fatalf("icmp.Message.Marshal failed: %v", err)
} }
if err := p.SetControlMessage(cf, toggle); err != nil { if err := p.SetControlMessage(cf, toggle); err != nil && !protocolNotSupported(err) {
t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err)
} }
p.SetTTL(i + 1) p.SetTTL(i + 1)
...@@ -257,7 +257,7 @@ func TestRawConnReadWriteUnicastICMP(t *testing.T) { ...@@ -257,7 +257,7 @@ func TestRawConnReadWriteUnicastICMP(t *testing.T) {
Protocol: 1, Protocol: 1,
Dst: dst.IP, Dst: dst.IP,
} }
if err := r.SetControlMessage(cf, toggle); err != nil { if err := r.SetControlMessage(cf, toggle); err != nil && !protocolNotSupported(err) {
t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", err)
} }
if err := r.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)); err != nil { if err := r.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)); err != nil {
......
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