---
name: "io_uring_prep_cmd_sock"
section: "3"
platform: "linux"
package: "liburing"
version: "2.15-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/io_uring_prep_cmd_sock"
---

# io\_uring\_prep\_cmd\_sock(3)

prepare a command request for a socket

## NAME

io\_uring\_prep\_cmd\_sock - prepare a command request for a socket

## SYNOPSIS

```
#include <liburing.h>
```

**void io\_uring\_prep\_cmd\_sock(struct io\_uring\_sqe \****sqe***,**                             **int** *cmd\_op***,**                             **int** *fd***,**                             **int** *level***,**                             **int** *optname***,**                             **void** *\*optval***,**                             **int** *optlen***);**

## DESCRIPTION

The [**io\_uring\_prep\_cmd\_sock**(3)](/io_uring_prep_cmd_sock/3.md) function prepares an cmd request for a socket. The submission queue entry *sqe* is setup to use the socket file descriptor pointed to by *fd* to start an command operation defined by *cmd\_op.*

This is a generic function, and each command has their own individual *level, optname, optval* values.  The optlen defines the size pointed by *optval.*

## Available commands

- **SOCKET\_URING\_OP\_SIOCINQ**

  Returns the amount of queued unread data in the receive buffer. The socket must not be in LISTEN state, otherwise an error **-EINVAL** is returned in the CQE *res* field. The following arguments are not used for this command *level, optname, optval* and *optlen.*

  Negative return value means an error.

  For more information about this command, please check **[unix(7)](/unix/7.md).**

  Available since 6.7.

- **SOCKET\_URING\_OP\_SIOCOUTQ**

  Returns the amount of unsent data in the socket send queue. The socket must not be in LISTEN state, otherwise an error **-EINVAL** is returned in the CQE *res.* field. The following arguments are not used for this command *level, optname, optval* and *optlen.*

  Negative return value means an error.

  For more information about this command, please check **[unix(7)](/unix/7.md).**

- **SOCKET\_URING\_OP\_GETSOCKOPT**

  Command to get options for the socket referred to by the socket file descriptor *fd.* The arguments are similar to the **[getsockopt(2)](/getsockopt/2.md)** system call.

  The **SOCKET\_URING\_OP\_GETSOCKOPT** command is limited to **SOL\_SOCKET** *level.*

  Differently from the **[getsockopt(2)](/getsockopt/2.md)** system call, the updated *optlen* value is returned in the CQE *res* field, on success. On failure, the CQE *res* contains a negative error number.

- **SOCKET\_URING\_OP\_SETSOCKOPT**

  Command to set options for the socket referred to by the socket file descriptor *fd.* The arguments are similar to the **[setsockopt(2)](/setsockopt/2.md)** system call.

  Available since 6.7.

- **SOCKET\_URING\_OP\_TX\_TIMESTAMP**

  Retrieve transmit timestamps from the socket's error queue. This provides an alternative to the traditional **[recvmsg(2)](/recvmsg/2.md)** error queue interface for obtaining TX timestamps.

  The command operates in a polled multishot mode: io\_uring will poll the socket and keep posting timestamps as CQEs until the request is cancelled or fails. The ring must be created with **IORING\_SETUP\_CQE32** or **IORING\_SETUP\_CQE\_MIXED** to provide space for the timestamp data.

  The socket must first be configured for timestamping via **[setsockopt(2)](/setsockopt/2.md)** with **SO\_TIMESTAMPING** at the **SOL\_SOCKET** level, specifying the desired timestamp types (e.g. **SOF\_TIMESTAMPING\_TX\_SOFTWARE**, **SOF\_TIMESTAMPING\_TX\_SCHED**, **SOF\_TIMESTAMPING\_TX\_ACK**) along with **SOF\_TIMESTAMPING\_SOFTWARE** and **SOF\_TIMESTAMPING\_OPT\_TSONLY**.

  The following arguments are not used for this command: *level, optname, optval* and *optlen.*

  Each timestamp is delivered as a CQE with **IORING\_CQE\_F\_MORE** set in *cqe-\>flags* to indicate more timestamps may follow. The *cqe-\>res* field contains the timestamp key (*tskey*), which corresponds to the byte offset (for TCP) or packet count (for UDP). The timestamp type (*SCM\_TSTAMP\_SCHED*, *SCM\_TSTAMP\_SND* or *SCM\_TSTAMP\_ACK*) is stored in the upper bits of *cqe-\>flags* at offset **IORING\_TIMESTAMP\_TYPE\_SHIFT**. If the timestamp is a hardware timestamp, the **IORING\_CQE\_F\_TSTAMP\_HW** flag is set.

  The actual timestamp value is stored in the extended CQE area as a **struct io\_timespec** (with 64-bit *tv\_sec* and *tv\_nsec* fields), accessible at *(cqe + 1)*.

  The final CQE will not have **IORING\_CQE\_F\_MORE** set, and its *cqe-\>res* will contain 0 on success or a negative error code on failure.

  Available since 6.17.

- **SOCKET\_URING\_OP\_GETSOCKNAME**

  Returns the current address to which the socket is bound. The result is stored in the buffer pointed to by *optval,* which should be a pointer to a *struct sockaddr* (or appropriate variant). The *optlen* argument specifies the size of the buffer. On success, the CQE *res* field contains the actual size of the socket address. If the buffer is too small, the result is truncated.

  This is the io\_uring equivalent of [**getsockname**(2)](/getsockname/2.md).

  Available since 6.19.

## NOTES

The memory block pointed by *optval* needs to be valid/live until the CQE returns.

## RETURN VALUE

Dependent on the command.

## ERRORS

The CQE *res* field will contain the result of the operation.

## SEE ALSO

[**io\_uring\_get\_sqe**(3)](/io_uring_get_sqe/3.md), [**io\_uring\_submit**(3)](/io_uring_submit/3.md), [**io\_uring\_register**(2)](/io_uring_register/2.md), [**unix**(7)](/unix/7.md)
