---
name: "ares_get_servers_csv"
section: "3"
platform: "linux"
package: "c-ares"
version: "1.34.9-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/ares_set_servers_csv"
---

# ares\_get\_servers\_csv(3)

Set or Get a list of DNS servers used for queries.

Part of [ares\_set\_servers\_csv(3)](/ares_set_servers_csv/3.md).

## 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.

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 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)](/resolv.conf/5.md)** *nameserver* format, as well as a *URI* format.  Both formats can be used at the same time in the provided CSV string.

The *nameserver* format is:

```
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 53 or the value specified in **[ares\_init\_options(3)](/ares_init_options/3.md)**.

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 is 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 in RFC4501 since we'd technically be extending this URI scheme. Port defaults to 53.

*dns+tls://* - DNS over TLS. Port defaults to 853.

*dns+https://* - DNS over HTTPS. Port defaults to 443.

Query parameters are defined as below.  Additional parameters may be defined in the future.

*tcpport* - TCP port to use, only for *dns://* 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 for *dns+tls://* and *dns+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 for *dns+tls://* and *dns+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

```
192.168.1.100,[fe80::1]:53%eth0,dns://192.168.1.1?tcpport=1153
```

## RETURN VALUES

**[ares\_set\_servers\_csv(3)](/ares_set_servers_csv/3.md)** and **[ares\_set\_servers\_ports\_csv(3)](/ares_set_servers_ports_csv/3.md)** 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)](/ares_get_servers_csv/3.md)** returns a string representing the servers configured which must be freed with **[ares\_free\_string(3)](/ares_free_string/3.md)**.  If it returns NULL, this is an out of memory condition.

## SEE ALSO

[**ares\_set\_servers**(3)](/ares_set_servers/3.md)

## AVAILABILITY

**ares\_set\_servers\_csv** was added in c-ares 1.7.2 **ares\_set\_servers\_ports\_csv** was added in c-ares 1.11.0. **ares\_get\_servers\_csv** was added in c-ares 1.24.0. *URI* support was added in c-ares 1.34.0.
