diff --git a/src/internal/syscall/unix/net_darwin.go b/src/internal/syscall/unix/net_darwin.go index bbaa94b0d21..7e8f2ac12c6 100644 --- a/src/internal/syscall/unix/net_darwin.go +++ b/src/internal/syscall/unix/net_darwin.go @@ -16,12 +16,13 @@ const ( AI_V4MAPPED = 0x800 AI_MASK = 0x1407 - EAI_AGAIN = 2 - EAI_NODATA = 7 - EAI_NONAME = 8 - EAI_SERVICE = 9 - EAI_SYSTEM = 11 - EAI_OVERFLOW = 14 + EAI_ADDRFAMILY = 1 + EAI_AGAIN = 2 + EAI_NODATA = 7 + EAI_NONAME = 8 + EAI_SERVICE = 9 + EAI_SYSTEM = 11 + EAI_OVERFLOW = 14 NI_NAMEREQD = 4 ) diff --git a/src/net/cgo_unix.go b/src/net/cgo_unix.go index bc374c2c768..e866150f29a 100644 --- a/src/net/cgo_unix.go +++ b/src/net/cgo_unix.go @@ -16,6 +16,7 @@ import ( "errors" "internal/bytealg" "net/netip" + "runtime" "syscall" "unsafe" @@ -195,6 +196,16 @@ func cgoLookupHostIP(network, name string) (addrs []IPAddr, err error) { return nil, newDNSError(err, name, "") case _C_EAI_NONAME, _C_EAI_NODATA: return nil, newDNSError(errNoSuchHost, name, "") + case _C_EAI_ADDRFAMILY: + if runtime.GOOS == "freebsd" { + // FreeBSD began returning EAI_ADDRFAMILY for valid hosts without + // an A record in 13.2. We previously returned "no such host" for + // this case. + // + // https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=273912 + return nil, newDNSError(errNoSuchHost, name, "") + } + fallthrough default: return nil, newDNSError(addrinfoErrno(gerrno), name, "") } diff --git a/src/net/cgo_unix_cgo.go b/src/net/cgo_unix_cgo.go index d38ae0a84f2..c4b8197c620 100644 --- a/src/net/cgo_unix_cgo.go +++ b/src/net/cgo_unix_cgo.go @@ -22,6 +22,11 @@ package net #define EAI_NODATA -5 #endif +// If nothing else defined EAI_ADDRFAMILY, make sure it has a value. +#ifndef EAI_ADDRFAMILY +#define EAI_ADDRFAMILY -9 +#endif + // If nothing else defined EAI_OVERFLOW, make sure it has a value. #ifndef EAI_OVERFLOW #define EAI_OVERFLOW -12 @@ -31,19 +36,20 @@ import "C" import "unsafe" const ( - _C_AF_INET = C.AF_INET - _C_AF_INET6 = C.AF_INET6 - _C_AF_UNSPEC = C.AF_UNSPEC - _C_EAI_AGAIN = C.EAI_AGAIN - _C_EAI_NODATA = C.EAI_NODATA - _C_EAI_NONAME = C.EAI_NONAME - _C_EAI_SERVICE = C.EAI_SERVICE - _C_EAI_OVERFLOW = C.EAI_OVERFLOW - _C_EAI_SYSTEM = C.EAI_SYSTEM - _C_IPPROTO_TCP = C.IPPROTO_TCP - _C_IPPROTO_UDP = C.IPPROTO_UDP - _C_SOCK_DGRAM = C.SOCK_DGRAM - _C_SOCK_STREAM = C.SOCK_STREAM + _C_AF_INET = C.AF_INET + _C_AF_INET6 = C.AF_INET6 + _C_AF_UNSPEC = C.AF_UNSPEC + _C_EAI_ADDRFAMILY = C.EAI_ADDRFAMILY + _C_EAI_AGAIN = C.EAI_AGAIN + _C_EAI_NODATA = C.EAI_NODATA + _C_EAI_NONAME = C.EAI_NONAME + _C_EAI_SERVICE = C.EAI_SERVICE + _C_EAI_OVERFLOW = C.EAI_OVERFLOW + _C_EAI_SYSTEM = C.EAI_SYSTEM + _C_IPPROTO_TCP = C.IPPROTO_TCP + _C_IPPROTO_UDP = C.IPPROTO_UDP + _C_SOCK_DGRAM = C.SOCK_DGRAM + _C_SOCK_STREAM = C.SOCK_STREAM ) type ( diff --git a/src/net/cgo_unix_syscall.go b/src/net/cgo_unix_syscall.go index 735dcdfe368..9cfc5783721 100644 --- a/src/net/cgo_unix_syscall.go +++ b/src/net/cgo_unix_syscall.go @@ -14,19 +14,20 @@ import ( ) const ( - _C_AF_INET = syscall.AF_INET - _C_AF_INET6 = syscall.AF_INET6 - _C_AF_UNSPEC = syscall.AF_UNSPEC - _C_EAI_AGAIN = unix.EAI_AGAIN - _C_EAI_NONAME = unix.EAI_NONAME - _C_EAI_SERVICE = unix.EAI_SERVICE - _C_EAI_NODATA = unix.EAI_NODATA - _C_EAI_OVERFLOW = unix.EAI_OVERFLOW - _C_EAI_SYSTEM = unix.EAI_SYSTEM - _C_IPPROTO_TCP = syscall.IPPROTO_TCP - _C_IPPROTO_UDP = syscall.IPPROTO_UDP - _C_SOCK_DGRAM = syscall.SOCK_DGRAM - _C_SOCK_STREAM = syscall.SOCK_STREAM + _C_AF_INET = syscall.AF_INET + _C_AF_INET6 = syscall.AF_INET6 + _C_AF_UNSPEC = syscall.AF_UNSPEC + _C_EAI_ADDRFAMILY = unix.EAI_ADDRFAMILY + _C_EAI_AGAIN = unix.EAI_AGAIN + _C_EAI_NONAME = unix.EAI_NONAME + _C_EAI_SERVICE = unix.EAI_SERVICE + _C_EAI_NODATA = unix.EAI_NODATA + _C_EAI_OVERFLOW = unix.EAI_OVERFLOW + _C_EAI_SYSTEM = unix.EAI_SYSTEM + _C_IPPROTO_TCP = syscall.IPPROTO_TCP + _C_IPPROTO_UDP = syscall.IPPROTO_UDP + _C_SOCK_DGRAM = syscall.SOCK_DGRAM + _C_SOCK_STREAM = syscall.SOCK_STREAM ) type (