Source file
src/net/main_posix_test.go
1
2
3
4
5
6
7 package net
8
9 import (
10 "net/internal/socktest"
11 "strings"
12 "syscall"
13 )
14
15 func enableSocketConnect() {
16 sw.Set(socktest.FilterConnect, nil)
17 }
18
19 func disableSocketConnect(network string) {
20 net, _, _ := strings.Cut(network, ":")
21 sw.Set(socktest.FilterConnect, func(so *socktest.Status) (socktest.AfterFilter, error) {
22 switch net {
23 case "tcp4":
24 if so.Cookie.Family() == syscall.AF_INET && so.Cookie.Type() == syscall.SOCK_STREAM {
25 return nil, syscall.EHOSTUNREACH
26 }
27 case "udp4":
28 if so.Cookie.Family() == syscall.AF_INET && so.Cookie.Type() == syscall.SOCK_DGRAM {
29 return nil, syscall.EHOSTUNREACH
30 }
31 case "ip4":
32 if so.Cookie.Family() == syscall.AF_INET && so.Cookie.Type() == syscall.SOCK_RAW {
33 return nil, syscall.EHOSTUNREACH
34 }
35 case "tcp6":
36 if so.Cookie.Family() == syscall.AF_INET6 && so.Cookie.Type() == syscall.SOCK_STREAM {
37 return nil, syscall.EHOSTUNREACH
38 }
39 case "udp6":
40 if so.Cookie.Family() == syscall.AF_INET6 && so.Cookie.Type() == syscall.SOCK_DGRAM {
41 return nil, syscall.EHOSTUNREACH
42 }
43 case "ip6":
44 if so.Cookie.Family() == syscall.AF_INET6 && so.Cookie.Type() == syscall.SOCK_RAW {
45 return nil, syscall.EHOSTUNREACH
46 }
47 }
48 return nil, nil
49 })
50 }
51
View as plain text