Source File
ipsock.go
Belonging Package
net
package net
import (
)
type ipStackCapabilities struct {
sync.Once // guards following
ipv4Enabled bool
ipv6Enabled bool
ipv4MappedIPv6Enabled bool
}
var ipStackCaps ipStackCapabilities
func () bool {
ipStackCaps.Once.Do(ipStackCaps.probe)
return ipStackCaps.ipv4Enabled
}
func () bool {
ipStackCaps.Once.Do(ipStackCaps.probe)
return ipStackCaps.ipv6Enabled
}
func () bool {
ipStackCaps.Once.Do(ipStackCaps.probe)
return ipStackCaps.ipv4MappedIPv6Enabled
}
= count(, ':') > 0
:= last(, ':')
if < 0 {
return (, )
}
:= bytealg.IndexByteString(, ']')
if < 0 {
return (, "missing ']' in address")
}
switch + 1 {
return (, )
if [+1] == ':' {
return (, )
}
return (, )
}
= [1:]
, = 1, +1 // there can't be a '[' resp. ']' before these positions
} else {
= [:]
if bytealg.IndexByteString(, ':') >= 0 {
return (, )
}
}
if bytealg.IndexByteString([:], '[') >= 0 {
return (, "unexpected '[' in address")
}
if bytealg.IndexByteString([:], ']') >= 0 {
return (, "unexpected ']' in address")
}
= [+1:]
return , , nil
}
if := last(, '%'); > 0 {
, = [:], [+1:]
} else {
=
}
return
}
if bytealg.IndexByteString(, ':') >= 0 {
return "[" + + "]:" +
}
return + ":" +
}
func ( *Resolver) ( context.Context, , string) (addrList, error) {
var (
error
, string
int
)
switch {
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
if != "" {
if , , = SplitHostPort(); != nil {
return nil,
}
if , = .LookupPort(, , ); != nil {
return nil,
}
}
case "ip", "ip4", "ip6":
if != "" {
=
}
default:
return nil, UnknownNetworkError()
}
:= func( IPAddr) Addr {
switch {
case "tcp", "tcp4", "tcp6":
return &TCPAddr{IP: .IP, Port: , Zone: .Zone}
case "udp", "udp4", "udp6":
return &UDPAddr{IP: .IP, Port: , Zone: .Zone}
case "ip", "ip4", "ip6":
return &IPAddr{IP: .IP, Zone: .Zone}
default:
panic("unexpected network: " + )
}
}
if == "" {
return addrList{(IPAddr{})}, nil
}
, := .lookupIPAddr(, , )
if != nil {
return nil,
if len() == 1 && [0].IP.Equal(IPv6unspecified) {
= append(, IPAddr{IP: IPv4zero})
}
var func(IPAddr) bool
if != "" && [len()-1] == '4' {
= ipv4only
}
if != "" && [len()-1] == '6' {
= ipv6only
}
return filterAddrList(, , , )
}
func ( string) IP {
if != "" && [len()-1] == '6' {
return IPv6loopback
}
return IP{127, 0, 0, 1}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |