...
Run Format

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  // +build !js,!plan9
     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  	ss := strings.Split(network, ":")
    21  	sw.Set(socktest.FilterConnect, func(so *socktest.Status) (socktest.AfterFilter, error) {
    22  		switch ss[0] {
    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