about summary refs log tree commit diff
path: root/src/network/gethostbyname2_r.c
Commit message (Collapse)AuthorAgeFilesLines
* getaddrinfo: add EAI_NODATA error code to distinguish NODATA vs NxDomainRich Felker2022-09-201-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | this was apparently omitted long ago out of a lack of understanding of its importance and the fact that POSIX doesn't specify it. despite not being officially standardized, however, it turns out that at least AIX, glibc, NetBSD, OpenBSD, QNX, and Solaris document and support it. in certain usage cases, such as implementing a DNS gateway on top of the stub resolver interfaces, it's necessary to distinguish the case where a name does not exit (NxDomain) from one where it exists but has no addresses (or other records) of the requested type (NODATA). in fact, even the legacy gethostbyname API had this distinction, which we were previously unable to support correctly because the backend lacked it. apart from fixing an important functionality gap, adding this distinction helps clarify to users how search domain fallback works (falling back in cases corresponding to EAI_NONAME, not in ones corresponding to EAI_NODATA), a topic that has been a source of ongoing confusion and frustration. as a result of this change, EAI_NONAME is no longer a valid universal error code for getaddrinfo in the case where AI_ADDRCONFIG has suppressed use of all address families. in order to return an accurate result in this case, getaddrinfo is modified to still perform at least one lookup. this will almost surely fail (with a network error, since there is no v4 or v6 network to query DNS over) unless a result comes from the hosts file or from ip literal parsing, but in case it does succeed, the result is replaced by EAI_NODATA. glibc has a related error code, EAI_ADDRFAMILY, that could be used for the AI_ADDRCONFIG case and certain NODATA cases, but distinguishing them properly in full generality seems to require additional DNS queries that are otherwise not useful. on glibc, it is only used for ip literals with mismatching family, not for DNS or hosts file results where the name has addresses only in the opposite family. since this seems misleading and inconsistent, and since EAI_NODATA already covers the semantic case where the "name" exists but doesn't have any addresses in the requested family, we do not adopt EAI_ADDRFAMILY at this time. this could be changed at some point if desired, but the logic for getting all the corner cases with AI_ADDRCONFIG right is slightly nontrivial.
* remove impossible error case from gethostbyname2_rRich Felker2022-09-191-1/+0
| | | | | | | | EAI_MEMORY is not possible because the resolver backend does not allocate. if it did, it would be necessary for us to explicitly return ENOMEM as the error, since errno is not guaranteed to reflect the error cause except in the case of EAI_SYSTEM, so the existing code was not correct anyway.
* fix return value of gethostnbyname[2]_r on result not foundRich Felker2022-09-191-1/+1
| | | | | | | | these functions are horribly underspecified, inconsistent between historical systems, and should never have been included. however, the signatures we have match the glibc ones, and the glibc behavior is to treat NxDomain and NODATA results as a success condition, not an ENOENT error.
* remove dead case in gethostbyname2_rDaniel Sabogal2016-09-241-2/+0
| | | | | this case statement was accidently left behind when this function was refactored in commit e8f39ca4898237cf71657500f0b11534c47a0521.
* fix misaligned address buffers in gethostbyname[2][_r] resultsRich Felker2016-06-271-7/+7
| | | | | mistakenly ordering strings before addresses in the result buffer broke the alignment that the preceding code had set up.
* fix gethostby*_r result pointer value on errorTimo Teräs2014-06-201-0/+1
| | | | | | | according to the documentation in the man pages, the GNU extension functions gethostbyaddr_r, gethostbyname_r and gethostbyname2_r are guaranteed to set the result pointer to NULL in case of error or no result.
* improve gethostbyname2_r using new resolver backendRich Felker2014-06-011-35/+22
| | | | | | | | these changes reduce the size of the function somewhat and remove many of its dependencies, including free. in principle it should now be async-signal-safe, but this has not been verified in detail. minor changes to error handling are also made.
* include cleanups: remove unused headers and add feature test macrosSzabolcs Nagy2013-12-121-1/+1
|
* fix memory leak due to double call to getaddrinfo in gethostbyname*Rich Felker2013-02-021-1/+0
|
* fix error returns in gethostby*_r functionsRich Felker2013-02-021-9/+5
| | | | they're supposed to return an error code rather than using errno.
* initial check-in, version 0.5.0 v0.5.0Rich Felker2011-02-121-0/+99