Code generated by cmd/cgo; DO NOT EDIT.
line /usr/local/Cellar/go/1.16.3/libexec/src/net/cgo_unix.go:1:1 Copyright 2011 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
+build cgo,!netgo +build aix darwin dragonfly freebsd linux netbsd openbsd solaris

package net
#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <unistd.h>#include <string.h>
If nothing else defined EAI_OVERFLOW, make sure it has a value.#ifndef EAI_OVERFLOW#define EAI_OVERFLOW -12#endif
import _ 

import (
	
	
	
)
An addrinfoErrno represents a getaddrinfo, getnameinfo-specific error number. It's a signed number and a zero value is a non-error by convention.
type addrinfoErrno int

func (eai addrinfoErrno) Error() string   { return ( /*line :36:52*/_Cfunc_GoString /*line :36:61*/)(( /*line :36:63*/_Cfunc_gai_strerror /*line :36:76*/)( /*line :36:78*/_Ctype_int /*line :36:83*/(eai))) }
func (eai addrinfoErrno) Temporary() bool { return eai == ( /*line :37:59*/_Ciconst_EAI_AGAIN /*line :37:69*/) }
func (eai addrinfoErrno) Timeout() bool   { return false }

type portLookupResult struct {
	port int
	err  error
}

type ipLookupResult struct {
	addrs []IPAddr
	cname string
	err   error
}

type reverseLookupResult struct {
	names []string
	err   error
}

func cgoLookupHost(ctx context.Context, name string) (hosts []string, err error, completed bool) {
	addrs, err, completed := cgoLookupIP(ctx, "ip", name)
	for _, addr := range addrs {
		hosts = append(hosts, addr.String())
	}
	return
}

func cgoLookupPort(ctx context.Context, network, service string) (port int, err error, completed bool) {
	var hints  /*line :65:12*/_Ctype_struct_addrinfo /*line :65:29*/
	switch network {
	case "": // no hints
	case "tcp", "tcp4", "tcp6":
		hints.ai_socktype = ( /*line :69:23*/_Ciconst_SOCK_STREAM /*line :69:35*/)
		hints.ai_protocol = ( /*line :70:23*/_Ciconst_IPPROTO_TCP /*line :70:35*/)
	case "udp", "udp4", "udp6":
		hints.ai_socktype = ( /*line :72:23*/_Ciconst_SOCK_DGRAM /*line :72:34*/)
		hints.ai_protocol = ( /*line :73:23*/_Ciconst_IPPROTO_UDP /*line :73:35*/)
	default:
		return 0, &DNSError{Err: "unknown network", Name: network + "/" + service}, true
	}
	switch ipVersion(network) {
	case '4':
		hints.ai_family = ( /*line :79:21*/_Ciconst_AF_INET /*line :79:29*/)
	case '6':
		hints.ai_family = ( /*line :81:21*/_Ciconst_AF_INET6 /*line :81:30*/)
	}
	if ctx.Done() == nil {
		port, err := cgoLookupServicePort(&hints, network, service)
		return port, err, true
	}
	result := make(chan portLookupResult, 1)
	go cgoPortLookup(result, &hints, network, service)
	select {
	case r := <-result:
		return r.port, r.err, true
Since there isn't a portable way to cancel the lookup, we just let it finish and write to the buffered channel.
		return 0, mapErr(ctx.Err()), false
	}
}

func cgoLookupServicePort(hints * /*line :99:34*/_Ctype_struct_addrinfo /*line :99:51*/, network, service string) (port int, err error) {
	cservice := make([]byte, len(service)+1)
Lowercase the C service name.
	for i, b := range cservice[:len(service)] {
		cservice[i] = lowerASCII(b)
	}
	var res * /*line :106:11*/_Ctype_struct_addrinfo /*line :106:28*/
	gerrno, err := func() (_Ctype_int, error){ var _cgo0 *_Ctype_char = /*line :107:31*/nil; var _cgo1 *_Ctype_char = /*line :107:36*/(*_Ctype_char)(unsafe.Pointer(&cservice[0])); _cgo2 := /*line :107:77*/hints; _cgoBase3 := /*line :107:84*/&res; _cgo3 := _cgoBase3; _cgoCheckPointer(_cgo2, nil); _cgoCheckPointer(_cgoBase3, 0 == 0); return _C2func_getaddrinfo(_cgo0, _cgo1, _cgo2, _cgo3); }()
	if gerrno != 0 {
		isTemporary := false
		switch gerrno {
		case ( /*line :111:8*/_Ciconst_EAI_SYSTEM /*line :111:19*/):
			if err == nil { // see golang.org/issue/6232
				err = syscall.EMFILE
			}
		default:
			err = addrinfoErrno(gerrno)
			isTemporary = addrinfoErrno(gerrno).Temporary()
		}
		return 0, &DNSError{Err: err.Error(), Name: network + "/" + service, IsTemporary: isTemporary}
	}
	defer func() func() { _cgo0 := /*line :121:23*/res; return func() { _cgoCheckPointer(_cgo0, nil); _Cfunc_freeaddrinfo(_cgo0); }}()()

	for r := res; r != nil; r = r.ai_next {
		switch r.ai_family {
		case ( /*line :125:8*/_Ciconst_AF_INET /*line :125:16*/):
			sa := (*syscall.RawSockaddrInet4)(unsafe.Pointer(r.ai_addr))
			p := (*[2]byte)(unsafe.Pointer(&sa.Port))
			return int(p[0])<<8 | int(p[1]), nil
		case ( /*line :129:8*/_Ciconst_AF_INET6 /*line :129:17*/):
			sa := (*syscall.RawSockaddrInet6)(unsafe.Pointer(r.ai_addr))
			p := (*[2]byte)(unsafe.Pointer(&sa.Port))
			return int(p[0])<<8 | int(p[1]), nil
		}
	}
	return 0, &DNSError{Err: "unknown port", Name: network + "/" + service}
}

func cgoPortLookup(result chan<- portLookupResult, hints * /*line :138:59*/_Ctype_struct_addrinfo /*line :138:76*/, network, service string) {
	port, err := cgoLookupServicePort(hints, network, service)
	result <- portLookupResult{port, err}
}

func cgoLookupIPCNAME(network, name string) (addrs []IPAddr, cname string, err error) {
	acquireThread()
	defer releaseThread()

	var hints  /*line :147:12*/_Ctype_struct_addrinfo /*line :147:29*/
	hints.ai_flags = cgoAddrInfoFlags
	hints.ai_socktype = ( /*line :149:22*/_Ciconst_SOCK_STREAM /*line :149:34*/)
	hints.ai_family = ( /*line :150:20*/_Ciconst_AF_UNSPEC /*line :150:30*/)
	switch ipVersion(network) {
	case '4':
		hints.ai_family = ( /*line :153:21*/_Ciconst_AF_INET /*line :153:29*/)
	case '6':
		hints.ai_family = ( /*line :155:21*/_Ciconst_AF_INET6 /*line :155:30*/)
	}

	h := make([]byte, len(name)+1)
	copy(h, name)
	var res * /*line :160:11*/_Ctype_struct_addrinfo /*line :160:28*/
	gerrno, err := func() (_Ctype_int, error){ var _cgo0 *_Ctype_char = /*line :161:31*/(*_Ctype_char)(unsafe.Pointer(&h[0])); var _cgo1 *_Ctype_char = /*line :161:65*/nil; _cgoBase2 := /*line :161:70*/&hints; _cgo2 := _cgoBase2; _cgoBase3 := /*line :161:78*/&res; _cgo3 := _cgoBase3; _cgoCheckPointer(_cgoBase2, 0 == 0); _cgoCheckPointer(_cgoBase3, 0 == 0); return _C2func_getaddrinfo(_cgo0, _cgo1, _cgo2, _cgo3); }()
	if gerrno != 0 {
		isErrorNoSuchHost := false
		isTemporary := false
		switch gerrno {
		case ( /*line :166:8*/_Ciconst_EAI_SYSTEM /*line :166:19*/):
err should not be nil, but sometimes getaddrinfo returns gerrno == C.EAI_SYSTEM with err == nil on Linux. The report claims that it happens when we have too many open files, so use syscall.EMFILE (too many open files in system). Most system calls would return ENFILE (too many open files), so at the least EMFILE should be easy to recognize if this comes up again. golang.org/issue/6232.
				err = syscall.EMFILE
			}
		case ( /*line :177:8*/_Ciconst_EAI_NONAME /*line :177:19*/):
			err = errNoSuchHost
			isErrorNoSuchHost = true
		default:
			err = addrinfoErrno(gerrno)
			isTemporary = addrinfoErrno(gerrno).Temporary()
		}

		return nil, "", &DNSError{Err: err.Error(), Name: name, IsNotFound: isErrorNoSuchHost, IsTemporary: isTemporary}
	}
	defer func() func() { _cgo0 := /*line :187:23*/res; return func() { _cgoCheckPointer(_cgo0, nil); _Cfunc_freeaddrinfo(_cgo0); }}()()

	if res != nil {
		cname = ( /*line :190:11*/_Cfunc_GoString /*line :190:20*/)(res.ai_canonname)
		if cname == "" {
			cname = name
		}
		if len(cname) > 0 && cname[len(cname)-1] != '.' {
			cname += "."
		}
	}
We only asked for SOCK_STREAM, but check anyhow.
		if r.ai_socktype != ( /*line :200:23*/_Ciconst_SOCK_STREAM /*line :200:35*/) {
			continue
		}
		switch r.ai_family {
		case ( /*line :204:8*/_Ciconst_AF_INET /*line :204:16*/):
			sa := (*syscall.RawSockaddrInet4)(unsafe.Pointer(r.ai_addr))
			addr := IPAddr{IP: copyIP(sa.Addr[:])}
			addrs = append(addrs, addr)
		case ( /*line :208:8*/_Ciconst_AF_INET6 /*line :208:17*/):
			sa := (*syscall.RawSockaddrInet6)(unsafe.Pointer(r.ai_addr))
			addr := IPAddr{IP: copyIP(sa.Addr[:]), Zone: zoneCache.name(int(sa.Scope_id))}
			addrs = append(addrs, addr)
		}
	}
	return addrs, cname, nil
}

func cgoIPLookup(result chan<- ipLookupResult, network, name string) {
	addrs, cname, err := cgoLookupIPCNAME(network, name)
	result <- ipLookupResult{addrs, cname, err}
}

func cgoLookupIP(ctx context.Context, network, name string) (addrs []IPAddr, err error, completed bool) {
	if ctx.Done() == nil {
		addrs, _, err = cgoLookupIPCNAME(network, name)
		return addrs, err, true
	}
	result := make(chan ipLookupResult, 1)
	go cgoIPLookup(result, network, name)
	select {
	case r := <-result:
		return r.addrs, r.err, true
	case <-ctx.Done():
		return nil, mapErr(ctx.Err()), false
	}
}

func cgoLookupCNAME(ctx context.Context, name string) (cname string, err error, completed bool) {
	if ctx.Done() == nil {
		_, cname, err = cgoLookupIPCNAME("ip", name)
		return cname, err, true
	}
	result := make(chan ipLookupResult, 1)
	go cgoIPLookup(result, "ip", name)
	select {
	case r := <-result:
		return r.cname, r.err, true
	case <-ctx.Done():
		return "", mapErr(ctx.Err()), false
	}
}
These are roughly enough for the following: Source Encoding Maximum length of single name entry Unicast DNS ASCII or <=253 + a NUL terminator Unicode in RFC 5892 252 * total number of labels + delimiters + a NUL terminator Multicast DNS UTF-8 in RFC 5198 or <=253 + a NUL terminator the same as unicast DNS ASCII <=253 + a NUL terminator Local database various depends on implementation
const (
	nameinfoLen    = 64
	maxNameinfoLen = 4096
)

func cgoLookupPTR(ctx context.Context, addr string) (names []string, err error, completed bool) {
	var zone string
	ip := parseIPv4(addr)
	if ip == nil {
		ip, zone = parseIPv6Zone(addr)
	}
	if ip == nil {
		return nil, &DNSError{Err: "invalid address", Name: addr}, true
	}
	sa, salen := cgoSockaddr(ip, zone)
	if sa == nil {
		return nil, &DNSError{Err: "invalid address " + ip.String(), Name: addr}, true
	}
	if ctx.Done() == nil {
		names, err := cgoLookupAddrPTR(addr, sa, salen)
		return names, err, true
	}
	result := make(chan reverseLookupResult, 1)
	go cgoReverseLookup(result, addr, sa, salen)
	select {
	case r := <-result:
		return r.names, r.err, true
	case <-ctx.Done():
		return nil, mapErr(ctx.Err()), false
	}
}

func cgoLookupAddrPTR(addr string, sa * /*line :292:40*/_Ctype_struct_sockaddr /*line :292:57*/, salen  /*line :292:65*/_Ctype_socklen_t /*line :292:76*/) (names []string, err error) {
	acquireThread()
	defer releaseThread()

	var gerrno int
	var b []byte
	for l := nameinfoLen; l <= maxNameinfoLen; l *= 2 {
		b = make([]byte, l)
		gerrno, err = cgoNameinfoPTR(b, sa, salen)
		if gerrno == 0 || gerrno != ( /*line :301:31*/_Ciconst_EAI_OVERFLOW /*line :301:44*/) {
			break
		}
	}
	if gerrno != 0 {
		isTemporary := false
		switch gerrno {
		case ( /*line :308:8*/_Ciconst_EAI_SYSTEM /*line :308:19*/):
			if err == nil { // see golang.org/issue/6232
				err = syscall.EMFILE
			}
		default:
			err = addrinfoErrno(gerrno)
			isTemporary = addrinfoErrno(gerrno).Temporary()
		}
		return nil, &DNSError{Err: err.Error(), Name: addr, IsTemporary: isTemporary}
	}
	for i := 0; i < len(b); i++ {
		if b[i] == 0 {
			b = b[:i]
			break
		}
	}
	return []string{absDomainName(b)}, nil
}

func cgoReverseLookup(result chan<- reverseLookupResult, addr string, sa * /*line :327:75*/_Ctype_struct_sockaddr /*line :327:92*/, salen  /*line :327:100*/_Ctype_socklen_t /*line :327:111*/) {
	names, err := cgoLookupAddrPTR(addr, sa, salen)
	result <- reverseLookupResult{names, err}
}

func cgoSockaddr(ip IP, zone string) (* /*line :332:40*/_Ctype_struct_sockaddr /*line :332:57*/,  /*line :332:59*/_Ctype_socklen_t /*line :332:70*/) {
	if ip4 := ip.To4(); ip4 != nil {
		return cgoSockaddrInet4(ip4),  /*line :334:33*/_Ctype_socklen_t /*line :334:44*/(syscall.SizeofSockaddrInet4)
	}
	if ip6 := ip.To16(); ip6 != nil {
		return cgoSockaddrInet6(ip6, zoneCache.index(zone)),  /*line :337:56*/_Ctype_socklen_t /*line :337:67*/(syscall.SizeofSockaddrInet6)
	}
	return nil, 0
}

func copyIP(x IP) IP {
	if len(x) < 16 {
		return x.To16()
	}
	y := make(IP, len(x))
	copy(y, x)
	return y