---
name: "ares_set_socket_callback"
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_socket_callback"
---

# ares\_set\_socket\_callback(3)

Set a socket creation callback

## NAME

ares\_set\_socket\_callback - Set a socket creation callback

## SYNOPSIS

```
#include <ares.h>
typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd,
                                         int type,
                                         void *userdata)
void ares_set_socket_callback(ares_channel_t *channel,
                              ares_sock_create_callback callback,
                              void *userdata)
```

**cc file.c -lcares**

## DESCRIPTION

This function sets a *callback* in the given ares channel handle. This callback function will be invoked after the socket has been created, and connected to the remote server. The callback must return ARES\_SUCCESS if things are fine, or return -1 to signal an error. A returned error will abort the ares operation.

The callback is invoked while c-ares is part-way through opening a connection.  It must not call any c-ares function on the same channel; see *[ares\_set\_socket\_functions(3)](/ares_set_socket_functions/3.md)*.

## SEE ALSO

[**ares\_init\_options**(3)](/ares_init_options/3.md), [**ares\_set\_socket\_configure\_callback**(3)](/ares_set_socket_configure_callback/3.md)

## AVAILABILITY

[ares\_set\_socket\_callback(3)](/ares_set_socket_callback/3.md) was added in c-ares 1.6.0
