ARES_SET_SERVERS_CSV(3)
π ARES_SET_SERVERS_CSV(3) π
okay bestie, welcome to the Library Functions Manual entry for the c-ares server-list CSV situation. Weβre setting or getting the list of DNS servers used for queries. No cap, this is the whole squad. π«Ά
β¨ NAME β¨
ares_set_servers_csv, ares_set_servers_ports_csv, ares_get_servers_csv β Set or Get a list of DNS servers used for queries.
πΈ SYNOPSIS πΈ
#include <ares.h>
int ares_set_servers_csv(ares_channel_t *channel, const char* servers)
int ares_set_servers_ports_csv(ares_channel_t *channel, const char* servers)
char *ares_get_servers_csv(const ares_channel_t *channel)
π DESCRIPTION π
The ares_set_servers_csv and ares_set_servers_ports_csv functions set the list of DNS servers that c-ares will query. As of v1.22.0 this function can be called on an active channel with running queries β previously it would return ARES_ENOTIMP. glow-up, honestly. β¨
Though not recommended, passing NULL for servers will clear all configured servers and make an inoperable channel. This may be advantageous for test simulation but is unlikely to be useful in production. β οΈ
The ares_get_servers_csv retrieves the list of servers in comma delimited format. π
The input and output format is a comma separated list of servers. Two formats are available: the typical resolv.conf(5) nameserver format, as well as a URI format. Both formats can be used at the same time in the provided CSV string. iconic behavior. π
π The nameserver format π
ip[:port][%iface]
- The ip may be encapsulated in square brackets (
[ ]), and must be if using ipv6 and also specifying a port. - The port is optional, and will default to
53or the value specified inares_init_options(3). - The iface is specific to IPv6 link-local servers (
fe80::/10) and should not otherwise be used.
nameserver format examples:
192.168.1.100
192.168.1.101:53
[1:2:3::4]:53
[fe80::1]:53%eth0
π¦ The URI format π¦
The URI format is made up of these defined schemes:
dns://β Normal DNS server (UDP + TCP). We need to be careful not to conflict with query params defined inRFC4501since weβd technically be extending this URI scheme. Port defaults to53.dns+tls://β DNS over TLS. Port defaults to853.dns+https://β DNS over HTTPS. Port defaults to443.
Query parameters are defined as below. Additional parameters may be defined in the future. π
tcpportβ TCP port to use, only fordns://scheme. The port specified as part of the authority component of the URI will be used for both UDP and TCP by default, this option will override the TCP port.ipaddrβ Only fordns+tls://anddns+https://. If the authority component of the URI contains a hostname, this is used to specify the ip address of the hostname. If not specified, will need to use a non-secure server to perform a DNS lookup to retrieve this information. It is always recommended to have both the ip address and fully qualified domain name specified.hostnameβ Only fordns+tls://anddns+https://. If the authority component of the URI contains an ip address, this is used to specify the fully qualified domain name of the server. If not specified, will need to use a non-secure server to perform a DNS reverse lookup to retrieve this information. It is always recommended to have both the ip address and fully qualified domain name specified.domainβ If specified, this server is a domain-specific server. Any queries for this domain will be routed to this server. Multiple servers may be tagged with the same domain.
URI format Examples:
dns://8.8.8.8
dns://[2001:4860:4860::8888]
dns://[fe80::b542:84df:1719:65e3%en0]
dns://192.168.1.1:55
dns://192.168.1.1?tcpport=1153
dns://10.0.1.1?domain=myvpn.com
dns+tls://8.8.8.8?hostname=dns.google
dns+tls://one.one.one.one?ipaddr=1.1.1.1
NOTE: While we are defining the scheme for things like domain-specific servers, DNS over TLS and DNS over HTTPS, the underlying implementations for those features do not yet exist and therefore will result in errors if they are attempted to be used. π
As of c-ares 1.24.0, ares_set_servers_csv and ares_set_servers_ports_csv are identical. Prior versions would simply omit ports in ares_set_servers_csv but due to the addition of link local interface support, this difference was removed. π
π§ REENTRANCY π§
These functions may be called from within a c-ares callback. Removing a server closes its connections, which ends the lookups that were using it and invokes their callbacks, so a reconfiguration can be requested from inside one. π
A nested call reconciles the whole server list, and the outer call leaves that result in place rather than deleting the servers the nested call installed. The consequence is that the outer callβs own list does not survive, even though it returns ARES_SUCCESS: the last configuration applied is the one the channel keeps. An application that reconfigures from a callback should therefore not assume the list it passed to the outer call is in effect when that call returns. π
This applies as of c-ares version 1.35.0, and c-ares version 1.34.9 on the 1.34 branch.
π EXAMPLE π
a little combo plate of both formats:
192.168.1.100,[fe80::1]:53%eth0,dns://192.168.1.1?tcpport=1153
π RETURN VALUES π
ares_set_servers_csv(3) and ares_set_servers_ports_csv(3) may return any of the following values:
ARES_SUCCESSβ The name servers configuration was successfully initialized.ARES_ENOMEMβ The processβs available memory was exhausted.ARES_ENODATAβ The channel data identified by channel was invalid.ARES_ENOTINITIALIZEDβ c-ares library initialization not yet performed.
ares_get_servers_csv(3) returns a string representing the servers configured which must be freed with ares_free_string(3). If it returns NULL, this is an out of memory condition. π«
π SEE ALSO π
π AVAILABILITY π
ares_set_servers_csvwas added in c-ares1.7.2ares_set_servers_ports_csvwas added in c-ares1.11.0.ares_get_servers_csvwas added in c-ares1.24.0. URI support was added in c-ares1.34.0.
xoxo, bestie π β c-ares Library Functions Manual, ARES_SET_SERVERS_CSV(3), 5 Dec 2023 π
π¦ where this page comes from
- alpine 3.22: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.23: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.24: c-ares-doc 1.34.9-r0 Β· MIT
- arch rolling: c-ares 1.34.9-1 Β· MIT
- centos-stream 10: c-ares-devel 1.34.9-1.el10 Β· MIT
- nixos 26.05: c-ares 1.34.9
- π the page's license: MIT
- Copyright 2010 by Ben Greear <greearb@candelatech.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms