// Code generated by cmd/cgo; DO NOT EDIT.

//line /home/circleci/project/client-sdk-codegen/go-client-sdk/target/install-go/go/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 ( addrinfoErrno) () 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*/())) }
func ( addrinfoErrno) () bool { return  == ( /*line :37:59*/_Ciconst_EAI_AGAIN /*line :37:69*/) }
func ( addrinfoErrno) () 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 ( context.Context,  string) ( []string,  error,  bool) {
	, ,  := cgoLookupIP(, "ip", )
	for ,  := range  {
		 = append(, .String())
	}
	return
}

func ( context.Context, ,  string) ( int,  error,  bool) {
	var   /*line :65:12*/_Ctype_struct_addrinfo /*line :65:29*/
	switch  {
	case "": // no hints
	case "tcp", "tcp4", "tcp6":
		.ai_socktype = ( /*line :69:23*/_Ciconst_SOCK_STREAM /*line :69:35*/)
		.ai_protocol = ( /*line :70:23*/_Ciconst_IPPROTO_TCP /*line :70:35*/)
	case "udp", "udp4", "udp6":
		.ai_socktype = ( /*line :72:23*/_Ciconst_SOCK_DGRAM /*line :72:34*/)
		.ai_protocol = ( /*line :73:23*/_Ciconst_IPPROTO_UDP /*line :73:35*/)
	default:
		return 0, &DNSError{Err: "unknown network", Name:  + "/" + }, true
	}
	switch ipVersion() {
	case '4':
		.ai_family = ( /*line :79:21*/_Ciconst_AF_INET /*line :79:29*/)
	case '6':
		.ai_family = ( /*line :81:21*/_Ciconst_AF_INET6 /*line :81:30*/)
	}
	if .Done() == nil {
		,  := cgoLookupServicePort(&, , )
		return , , true
	}
	 := make(chan portLookupResult, 1)
	go cgoPortLookup(, &, , )
	select {
	case  := <-:
		return .port, .err, true
	case <-.Done():
		// 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(.Err()), false
	}
}

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

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

func ( chan<- portLookupResult,  * /*line :138:59*/_Ctype_struct_addrinfo /*line :138:76*/, ,  string) {
	,  := cgoLookupServicePort(, , )
	 <- portLookupResult{, }
}

func (,  string) ( []IPAddr,  string,  error) {
	acquireThread()
	defer releaseThread()

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

	 := make([]byte, len()+1)
	copy(, )
	var  * /*line :160:11*/_Ctype_struct_addrinfo /*line :160:28*/
	,  := func() (_Ctype_int, error){ var  *_Ctype_char = /*line :161:31*/(*_Ctype_char)(unsafe.Pointer(&[0])); var  *_Ctype_char = /*line :161:65*/nil;  := /*line :161:70*/&;  := ;  := /*line :161:78*/&;  := ; _cgoCheckPointer(, 0 == 0); _cgoCheckPointer(, 0 == 0); return _C2func_getaddrinfo(, , , ); }()
	if  != 0 {
		 := false
		 := false
		switch  {
		case ( /*line :166:8*/_Ciconst_EAI_SYSTEM /*line :166:19*/):
			if  == nil {
				// 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.
				 = syscall.EMFILE
			}
		case ( /*line :177:8*/_Ciconst_EAI_NONAME /*line :177:19*/):
			 = errNoSuchHost
			 = true
		default:
			 = addrinfoErrno()
			 = addrinfoErrno().Temporary()
		}

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

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

func ( chan<- ipLookupResult, ,  string) {
	, ,  := cgoLookupIPCNAME(, )
	 <- ipLookupResult{, , }
}

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

func ( context.Context,  string) ( string,  error,  bool) {
	if .Done() == nil {
		_, ,  = cgoLookupIPCNAME("ip", )
		return , , true
	}
	 := make(chan ipLookupResult, 1)
	go cgoIPLookup(, "ip", )
	select {
	case  := <-:
		return .cname, .err, true
	case <-.Done():
		return "", mapErr(.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 ( context.Context,  string) ( []string,  error,  bool) {
	var  string
	 := parseIPv4()
	if  == nil {
		,  = parseIPv6Zone()
	}
	if  == nil {
		return nil, &DNSError{Err: "invalid address", Name: }, true
	}
	,  := cgoSockaddr(, )
	if  == nil {
		return nil, &DNSError{Err: "invalid address " + .String(), Name: }, true
	}
	if .Done() == nil {
		,  := cgoLookupAddrPTR(, , )
		return , , true
	}
	 := make(chan reverseLookupResult, 1)
	go cgoReverseLookup(, , , )
	select {
	case  := <-:
		return .names, .err, true
	case <-.Done():
		return nil, mapErr(.Err()), false
	}
}

func ( string,  * /*line :292:40*/_Ctype_struct_sockaddr /*line :292:57*/,   /*line :292:65*/_Ctype_socklen_t /*line :292:76*/) ( []string,  error) {
	acquireThread()
	defer releaseThread()

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

func ( chan<- reverseLookupResult,  string,  * /*line :327:75*/_Ctype_struct_sockaddr /*line :327:92*/,   /*line :327:100*/_Ctype_socklen_t /*line :327:111*/) {
	,  := cgoLookupAddrPTR(, , )
	 <- reverseLookupResult{, }
}

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

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