---
name: "ares_set_sortlist"
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_sortlist"
---

# ares\_set\_sortlist(3)

Initialize an ares\_channel\_t \*sortlist configuration

## NAME

ares\_set\_sortlist - Initialize an ares\_channel\_t \*sortlist configuration

## SYNOPSIS

```
#include <ares.h>
int ares_set_sortlist(ares_channel_t *channel, const char *sortstr)
```

## DESCRIPTION

The **[ares\_set\_sortlist(3)](/ares_set_sortlist/3.md)** function initializes an address sortlist configuration for the channel data identified by *channel*, so that addresses returned by **[ares\_gethostbyname(3)](/ares_gethostbyname/3.md)** are sorted according to the sortlist.  The provided *sortstr* string that holds a space separated list of IP-address-netmask pairs.  The netmask is optional but follows the address after a slash if present.  For example, "130.155.160.0/255.255.240.0 130.155.0.0".

This function replaces any potentially previously configured address sortlist with the ones given in the configuration string.

## RETURN VALUES

**[ares\_set\_sortlist(3)](/ares_set_sortlist/3.md)** may return any of the following values:

- **ARES\_SUCCESS**

  The sortlist 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.

## SEE ALSO

[**ares\_init\_options**(3)](/ares_init_options/3.md), [**ares\_dup**(3)](/ares_dup/3.md)

## AVAILABILITY

[ares\_set\_sortlist(3)](/ares_set_sortlist/3.md) was added in c-ares 1.11.0
