A C library for asynchronous DNS requests https://c-ares.org/
  • C 89.4%
  • M4 5.8%
  • CMake 3.6%
  • Python 0.6%
  • Makefile 0.4%
  • Other 0.2%
Find a file
Salman f1342b30bc
addrinfo: recognize fully qualified localhost names (#1439)
## Summary

- Recognize `localhost.` and names ending in `.localhost.` as localhost
names per RFC 6761 section 6.3.
- Add shared `ares_str_caseendswith()` with documentation and unit
tests, and reuse it for localhost, onion-domain, and NOFQDN handling.
- Cover `localhost.` and `app.localhost.` through `ares_getaddrinfo()`,
`ares_gethostbyname()`, and `ares_gethostbyname_file()` with hostile,
missing, and undotted hosts-file entries, plus case and boundary
coverage.

Fixes #1436.

## Root cause

`ares_is_localhost()` only matched `localhost` and suffixes ending in
`.localhost` without a trailing root dot. Fully qualified localhost
names therefore missed the loopback handling and could use non-loopback
hosts-file addresses or fall through to DNS.

## Verification

The new no-hosts-file and undotted-entry cases were run against the
original unfixed source: **0 passed, 6 failed**. With the reviewed
implementation, the identical six tests pass.

```text
Focused helper/localhost suite:
[  PASSED  ] 74 tests.

Normal full non-live suite:
[  PASSED  ] 867 tests.

Shared CARES_SYMBOL_HIDING=ON full non-live suite:
[  PASSED  ] 830 tests.
```

clang-format 20.1.8 reports no changes; `git diff --check` passes.

Signed-off-by: Salman <salch-cred@users.noreply.github.com>
Co-authored-by: salch-cred <salch-cred@users.noreply.github.com>
2026-12-01 07:14:01 -05:00
.github ci: bump the github-actions group with 8 updates (#1441) 2026-12-01 04:09:28 +00:00
.reuse docs: add AGENTS.md and modernize contributor documentation (#1231) 2026-07-05 13:05:21 -04:00
ci MacOS and iOS CI fixes (#1030) 2025-09-07 12:16:21 -04:00
cmake Fix propagation of C++ flags to the test targets (#1250) 2026-10-18 12:21:46 -04:00
docs ares_init: add ares_reinit_after_restore() (#1414) 2026-11-30 21:55:18 -05:00
include ares_init: add ares_reinit_after_restore() (#1414) 2026-11-30 21:55:18 -05:00
LICENSES Punycode/IDNA support and encoding of Windows unicode search suffixes (#1031) 2026-07-08 08:26:22 -04:00
m4 Fix a few build issues on MidnightBSD. (#983) 2025-04-15 07:51:51 -04:00
src addrinfo: recognize fully qualified localhost names (#1439) 2026-12-01 07:14:01 -05:00
test addrinfo: recognize fully qualified localhost names (#1439) 2026-12-01 07:14:01 -05:00
.clang-format ci: validate clang-format on PR-changed lines (#1185) 2026-07-03 17:43:10 -04:00
.gitattributes recursive git attributes 2023-10-27 07:24:13 -04:00
.gitignore gitignore: ignore .dirstamp (#868) 2024-08-26 06:14:15 -04:00
AGENTS.md ares_mem: overflow-check the remaining multiplied allocation sizes (#1297) 2026-10-19 12:50:56 -04:00
AUTHORS Android JNI code leaks local references in some cases (#175) 2018-02-03 04:31:38 -05:00
BACKPORTING.md Add comment-driven backport workflow for release branches (#1175) 2026-07-02 08:24:35 -04:00
buildconf provide SPDX identifiers and a REUSE CI job to verify 2023-06-09 20:09:21 +02:00
buildconf.bat provide SPDX identifiers and a REUSE CI job to verify 2023-06-09 20:09:21 +02:00
c-ares-config.cmake.in provide SPDX identifiers and a REUSE CI job to verify 2023-06-09 20:09:21 +02:00
CMakeLists.txt ares_str: fold case with the ASCII table, not libc strcasecmp() (#1375) 2026-11-30 08:50:58 -05:00
configure.ac ares_str: fold case with the ASCII table, not libc strcasecmp() (#1375) 2026-11-30 08:50:58 -05:00
CONTRIBUTING.md docs: add AGENTS.md and modernize contributor documentation (#1231) 2026-07-05 13:05:21 -04:00
DEVELOPER-NOTES.md docs: add AGENTS.md and modernize contributor documentation (#1231) 2026-07-05 13:05:21 -04:00
FEATURES.md Probe for failed servers instead of redirecting query (#877) 2024-09-09 10:04:04 -04:00
FUZZING.md array: fix array shifting when using an offset 2024-09-15 20:42:45 -04:00
GIT-INFO docs: convert INSTALL to MarkDown & tweak (#83) 2017-01-11 10:36:31 +00:00
INSTALL.md update some build instructions 2024-06-20 14:01:58 -04:00
libcares.pc.cmake CMake pkg-config windows: fix static library options 2024-08-07 09:43:39 -04:00
libcares.pc.in attempt to fix pkgconfig on windows for static builds 2024-01-28 12:38:59 -05:00
LICENSE.md don't put a heading on the license 2024-07-05 09:25:38 -04:00
Makefile.am chore: update some missed files to new MIT license (#920) 2024-12-07 07:53:43 -05:00
Makefile.dj Expose library/utility functions to tools (#860) 2024-08-22 19:09:33 -04:00
Makefile.m32 Port: restore Windows XP minimal support (#958) 2025-01-08 19:51:06 -05:00
Makefile.msvc chore: update some missed files to new MIT license (#920) 2024-12-07 07:53:43 -05:00
Makefile.netware ares_str: fold case with the ASCII table, not libc strcasecmp() (#1375) 2026-11-30 08:50:58 -05:00
Makefile.Watcom adig: rework command line arguments to mimic dig from bind (#890) 2024-09-25 11:13:53 -04:00
README.md ci: replace AppVeyor with GitHub Actions; drop dead Cirrus config (#1234) 2026-07-05 17:18:29 -04:00
README.msvc remove acountry from built tools as nerd.dk is gone (#554) 2023-09-27 18:20:54 -04:00
RELEASE-NOTES.md release-1.34.5 2025-04-08 07:00:32 -04:00
RELEASE-PROCEDURE.md RELEASE-PROCEDURE: document bumping the package version (AC_INIT / PROJECT) (#1241) 2026-07-06 23:58:58 +00:00
SECURITY.md [doc]: Security reporting requirement updates (#959) 2025-01-09 13:30:03 -05:00
sonar-project.properties SonarCloud: Fix additional code smells 2023-10-15 18:15:15 -04:00

c-ares logo

Build Status Windows Build Status Coverage Status CII Best Practices Fuzzing Status Bugs Coverity Scan Status

Overview

c-ares is a modern DNS (stub) resolver library, written in C. It provides interfaces for asynchronous queries while trying to abstract the intricacies of the underlying DNS protocol. It was originally intended for applications which need to perform DNS queries without blocking, or need to perform multiple DNS queries in parallel.

One of the goals of c-ares is to be a better DNS resolver than is provided by your system, regardless of which system you use. We recommend using the c-ares library in all network applications even if the initial goal of asynchronous resolution is not necessary to your application.

c-ares will build with any C89 compiler and is MIT licensed, which makes it suitable for both free and commercial software. c-ares runs on Linux, FreeBSD, OpenBSD, MacOS, Solaris, AIX, Windows, Android, iOS and many more operating systems.

c-ares has a strong focus on security, implementing safe parsers and data builders used throughout the code, thus avoiding many of the common pitfalls of other C libraries. Through automated testing with our extensive testing framework, c-ares is constantly validated with a range of static and dynamic analyzers, as well as being constantly fuzzed by OSS Fuzz.

While c-ares has been around for over 20 years, it has been actively maintained both in regards to the latest DNS RFCs as well as updated to follow the latest best practices in regards to C coding standards.

Code

The full source code and revision history is available in our GitHub repository. Our signed releases are available in the release archives.

See the INSTALL.md file for build information.

Communication

Issues and Feature Requests should be reported to our GitHub Issues page.

Discussions around c-ares and its use, are held on GitHub Discussions or the Mailing List. Mailing List archive here. Please, do not mail volunteers privately about c-ares.

Security vulnerabilities are treated according to our Security Procedure, please email c-ares-security at haxx.se if you suspect one.

Release keys

Primary GPG keys for c-ares Releasers (some Releasers sign with subkeys):

To import the full set of trusted release keys (including subkeys possibly used to sign releases):

gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 27EDEAF22F3ABCEB50DB9A125CC908FDB71E12C2 # Daniel Stenberg
gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys DA7D64E4C82C6294CB73A20E22E3D13B5411B7CA # Brad House

Verifying signatures

For each release c-ares-X.Y.Z.tar.gz there is a corresponding c-ares-X.Y.Z.tar.gz.asc file which contains the detached signature for the release.

After fetching all of the possible valid signing keys and loading into your keychain as per the prior section, you can simply run the command below on the downloaded package and detached signature:

% gpg -v --verify c-ares-1.29.0.tar.gz.asc c-ares-1.29.0.tar.gz
gpg: enabled compatibility flags:
gpg: Signature made Fri May 24 02:50:38 2024 EDT
gpg:                using RSA key 27EDEAF22F3ABCEB50DB9A125CC908FDB71E12C2
gpg: using pgp trust model
gpg: Good signature from "Daniel Stenberg <daniel@haxx.se>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 27ED EAF2 2F3A BCEB 50DB  9A12 5CC9 08FD B71E 12C2
gpg: binary signature, digest algorithm SHA512, key algorithm rsa2048

SLSA Provenance

This project generates SLSA provenance for its releases! This enables you to verify the integrity of the downloaded artifacts and ensure that the release was generated from the intended repository.

To verify the provenance of the release, please follow the instructions here.

Example:

$ curl -sO https://github.com/c-ares/c-ares/releases/download/v1.34.3/c-ares-1.34.3.intoto.jsonl
$ curl -sO https://github.com/c-ares/c-ares/releases/download/v1.34.3/c-ares-1.34.3.tar.gz
$ slsa-verifier verify-artifact c-ares-1.34.3.tar.gz \
    --provenance-path c-ares-1.34.3.intoto.jsonl \
    --source-uri github.com/c-ares/c-ares \
    --source-tag v1.34.3
Verified signature against tlog entry index 147812470 at URL: https://rekor.sigstore.dev/api/v1/log/entries/108e9186e8c5677a9bfd5bc5181d05ada688a805f9a59cfd082dec27cb6d6567f85b7382eea39dc5
Verified build using builder "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@refs/tags/v2.0.0" at commit c29e75d54c3743783d51a609980495cf553b4bca
Verifying artifact c-ares-1.34.3.tar.gz: PASSED

PASSED: SLSA verification passed

Features

See Features

Supported RFCs and Proposals

  • RFC1035. Initial/Base DNS RFC
  • RFC2671, RFC6891. EDNS0 option (meta-RR)
  • RFC3596. IPv6 Address. AAAA Record.
  • RFC2782. Server Selection. SRV Record.
  • RFC3403. Naming Authority Pointer. NAPTR Record.
  • RFC6698. DNS-Based Authentication of Named Entities (DANE) Transport Layer Security (TLS) Protocol. TLSA Record.
  • RFC9460. General Purpose Service Binding, Service Binding type for use with HTTPS. SVCB and HTTPS Records.
  • RFC7553. Uniform Resource Identifier. URI Record.
  • RFC6844. Certification Authority Authorization. CAA Record.
  • RFC2535, RFC2931. SIG0 Record. Only basic parser, not full implementation.
  • RFC4034. Resource Records for the DNS Security Extensions (DNSSEC). DS, DNSKEY, RRSIG, and NSEC Records. Parsing and writing only; no DNSSEC validation is performed.
  • RFC5155. DNS Security (DNSSEC) Hashed Authenticated Denial of Existence. NSEC3 and NSEC3PARAM Records.
  • RFC4255. Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints. SSHFP Record.
  • RFC7873, RFC9018. DNS Cookie off-path dns poisoning and amplification mitigation.
  • draft-vixie-dnsext-dns0x20-00. DNS 0x20 query name case randomization to prevent cache poisioning attacks.
  • RFC7686. Reject queries for .onion domain names with NXDOMAIN.
  • RFC2606, RFC6761. Special case treatment for localhost/.localhost.
  • RFC2308, RFC9520. Negative Caching of DNS Resolution Failures.
  • RFC6724. IPv6 address sorting as used by ares_getaddrinfo().
  • RFC7413. TCP FastOpen (TFO) for 0-RTT TCP Connection Resumption.
  • RFC3986. Uniform Resource Identifier (URI). Used for server configuration.