1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 "golang.org/x/net/internal/nettest"
14 "golang.org/x/net/ipv4"
17 var icmpStringTests = []struct {
21 {ipv4.ICMPTypeDestinationUnreachable, "destination unreachable"},
26 func TestICMPString(t *testing.T) {
27 for _, tt := range icmpStringTests {
30 t.Errorf("got %s; want %s", s, tt.out)
35 func TestICMPFilter(t *testing.T) {
39 t.Skipf("not supported on %s", runtime.GOOS)
43 for _, toggle := range []bool{false, true} {
45 for _, typ := range []ipv4.ICMPType{
46 ipv4.ICMPTypeDestinationUnreachable,
47 ipv4.ICMPTypeEchoReply,
48 ipv4.ICMPTypeTimeExceeded,
49 ipv4.ICMPTypeParameterProblem,
53 t.Errorf("ipv4.ICMPFilter.Set(%v, false) failed", typ)
56 if !f.WillBlock(typ) {
57 t.Errorf("ipv4.ICMPFilter.Set(%v, true) failed", typ)
63 func TestSetICMPFilter(t *testing.T) {
67 t.Skipf("not supported on %s", runtime.GOOS)
69 if m, ok := nettest.SupportsRawIPSocket(); !ok {
73 c, err := net.ListenPacket("ip4:icmp", "127.0.0.1")
79 p := ipv4.NewPacketConn(c)
83 f.Accept(ipv4.ICMPTypeEcho)
84 f.Accept(ipv4.ICMPTypeEchoReply)
85 if err := p.SetICMPFilter(&f); err != nil {
88 kf, err := p.ICMPFilter()
92 if !reflect.DeepEqual(kf, &f) {
93 t.Fatalf("got %#v; want %#v", kf, f)