...

Source file src/net/main_posix_test.go

Documentation: net

		 1  // Copyright 2015 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.
		 4  
		 5  //go:build !js && !plan9
		 6  // +build !js,!plan9
		 7  
		 8  package net
		 9  
		10  import (
		11  	"net/internal/socktest"
		12  	"strings"
		13  	"syscall"
		14  )
		15  
		16  func enableSocketConnect() {
		17  	sw.Set(socktest.FilterConnect, nil)
		18  }
		19  
		20  func disableSocketConnect(network string) {
		21  	ss := strings.Split(network, ":")
		22  	sw.Set(socktest.FilterConnect, func(so *socktest.Status) (socktest.AfterFilter, error) {
		23  		switch ss[0] {
		24  		case "tcp4":
		25  			if so.Cookie.Family() == syscall.AF_INET && so.Cookie.Type() == syscall.SOCK_STREAM {
		26  				return nil, syscall.EHOSTUNREACH
		27  			}
		28  		case "udp4":
		29  			if so.Cookie.Family() == syscall.AF_INET && so.Cookie.Type() == syscall.SOCK_DGRAM {
		30  				return nil, syscall.EHOSTUNREACH
		31  			}
		32  		case "ip4":
		33  			if so.Cookie.Family() == syscall.AF_INET && so.Cookie.Type() == syscall.SOCK_RAW {
		34  				return nil, syscall.EHOSTUNREACH
		35  			}
		36  		case "tcp6":
		37  			if so.Cookie.Family() == syscall.AF_INET6 && so.Cookie.Type() == syscall.SOCK_STREAM {
		38  				return nil, syscall.EHOSTUNREACH
		39  			}
		40  		case "udp6":
		41  			if so.Cookie.Family() == syscall.AF_INET6 && so.Cookie.Type() == syscall.SOCK_DGRAM {
		42  				return nil, syscall.EHOSTUNREACH
		43  			}
		44  		case "ip6":
		45  			if so.Cookie.Family() == syscall.AF_INET6 && so.Cookie.Type() == syscall.SOCK_RAW {
		46  				return nil, syscall.EHOSTUNREACH
		47  			}
		48  		}
		49  		return nil, nil
		50  	})
		51  }
		52  

View as plain text