---
name: "sd_is_mq"
section: "3"
platform: "linux"
package: "libsystemd-dev"
version: "257.13-1~deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/sd_is_fifo"
---

# sd\_is\_mq(3)

Check the type of a file descriptor

Part of [sd\_is\_fifo(3)](/sd_is_fifo/3.md).

## NAME

sd\_is\_fifo, sd\_is\_socket, sd\_is\_socket\_inet, sd\_is\_socket\_unix, sd\_is\_socket\_sockaddr, sd\_is\_mq, sd\_is\_special - Check the type of a file descriptor

## SYNOPSIS

```
#include <systemd/sd-daemon.h>
```

**int sd\_is\_fifo(int** *fd***, const char \****path***);**

**int sd\_is\_socket(int** *fd***, int** *family***, int** *type***, int** *listening***);**

**int sd\_is\_socket\_inet(int** *fd***, int** *family***, int** *type***, int** *listening***, uint16\_t** *port***);**

**int sd\_is\_socket\_sockaddr(int** *fd***, int** *type***, const struct sockaddr \****addr***, unsigned** *addr\_len***, int** *listening***);**

**int sd\_is\_socket\_unix(int** *fd***, int** *type***, int** *listening***, const char \****path***, size\_t** *length***);**

**int sd\_is\_mq(int** *fd***, const char \****path***);**

**int sd\_is\_special(int** *fd***, const char \****path***);**

## DESCRIPTION

**sd\_is\_fifo()** may be called to check whether the specified file descriptor refers to a FIFO or pipe. If the *path* parameter is not **NULL**, it is checked whether the FIFO is bound to the specified file system path.

**sd\_is\_socket()** may be called to check whether the specified file descriptor refers to a socket. If the *family* parameter is not **AF\_UNSPEC**, it is checked whether the socket is of the specified family (**AF\_UNIX**, **AF\_INET**, ...). If the *type* parameter is not 0, it is checked whether the socket is of the specified type (**SOCK\_STREAM**, **SOCK\_DGRAM**, ...). If the *listening* parameter is positive, it is checked whether the socket is in accepting mode, i.e. **listen()** has been called for it. If *listening* is 0, it is checked whether the socket is not in this mode. If the parameter is negative, no such check is made. The *listening* parameter should only be used for stream sockets and should be set to a negative value otherwise.

**sd\_is\_socket\_inet()** is similar to **sd\_is\_socket()**, but optionally checks the IPv4 or IPv6 port number the socket is bound to, unless *port* is zero. For this call *family* must be passed as either **AF\_UNSPEC**, **AF\_INET**, or **AF\_INET6**.

**sd\_is\_socket\_sockaddr()** is similar to **sd\_is\_socket\_inet()**, but checks if the socket is bound to the address specified by *addr*. The *family* specified by *addr* must be either **AF\_INET** or **AF\_INET6** and *addr\_len* must be large enough for that family. If *addr* specifies a non-zero port, it is also checked if the socket is bound to this port. In addition, for IPv6, if *addr* specifies non-zero *sin6\_flowinfo* or *sin6\_scope\_id*, it is checked if the socket has the same values.

**sd\_is\_socket\_unix()** is similar to **sd\_is\_socket()** but optionally checks the **AF\_UNIX** path the socket is bound to, unless the *path* parameter is **NULL**. For normal file system **AF\_UNIX** sockets, set the *length* parameter to 0. For Linux abstract namespace sockets, set the *length* to the size of the address, including the initial 0 byte, and set the *path* to the initial 0 byte of the socket address.

**sd\_is\_mq()** may be called to check whether the specified file descriptor refers to a POSIX message queue. If the *path* parameter is not **NULL**, it is checked whether the message queue is bound to the specified name.

**sd\_is\_special()** may be called to check whether the specified file descriptor refers to a special file. If the *path* parameter is not **NULL**, it is checked whether the file descriptor is bound to the specified filename. Special files in this context are character device nodes and files in /proc/ or /sys/.

## RETURN VALUE

On failure, these calls return a negative errno-style error code. If the file descriptor is of the specified type and bound to the specified address, a positive return value is returned, otherwise zero.

## NOTES

Functions described here are available as a shared library, which can be compiled against and linked to with the **libsystemd** [**pkg-config**(1)](/pkg-config/1.md) file.

Internally, these functions use a combination of [**fstat**(2)](/fstat/2.md) and [**getsockname**(2)](/getsockname/2.md) to check the file descriptor type and where it is bound to.

## HISTORY

**sd\_is\_special()** was added in version 209.

**sd\_is\_socket\_sockaddr()** was added in version 233.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-daemon**(3)](/sd-daemon/3.md), [**sd\_listen\_fds**(3)](/sd_listen_fds/3.md), [**systemd.service**(5)](/systemd.service/5.md), [**systemd.socket**(5)](/systemd.socket/5.md), [**ip**(7)](/ip/7.md), [**ipv6**(7)](/ipv6/7.md), [**unix**(7)](/unix/7.md), [**fifo**(7)](/fifo/7.md), [**mq\_overview**(7)](/mq_overview/7.md), [**socket**(7)](/socket/7.md).
