1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id="sd_is_fifo"
10 xmlns:xi="http://www.w3.org/2001/XInclude">
13 <title>sd_is_fifo</title>
14 <productname>systemd</productname>
18 <contrib>Developer</contrib>
19 <firstname>Lennart</firstname>
20 <surname>Poettering</surname>
21 <email>lennart@poettering.net</email>
27 <refentrytitle>sd_is_fifo</refentrytitle>
28 <manvolnum>3</manvolnum>
32 <refname>sd_is_fifo</refname>
33 <refname>sd_is_socket</refname>
34 <refname>sd_is_socket_inet</refname>
35 <refname>sd_is_socket_unix</refname>
36 <refname>sd_is_socket_sockaddr</refname>
37 <refname>sd_is_mq</refname>
38 <refname>sd_is_special</refname>
39 <refpurpose>Check the type of a file descriptor</refpurpose>
44 <funcsynopsisinfo>#include <systemd/sd-daemon.h></funcsynopsisinfo>
47 <funcdef>int <function>sd_is_fifo</function></funcdef>
48 <paramdef>int <parameter>fd</parameter></paramdef>
49 <paramdef>const char *<parameter>path</parameter></paramdef>
53 <funcdef>int <function>sd_is_socket</function></funcdef>
54 <paramdef>int <parameter>fd</parameter></paramdef>
55 <paramdef>int <parameter>family</parameter></paramdef>
56 <paramdef>int <parameter>type</parameter></paramdef>
57 <paramdef>int <parameter>listening</parameter></paramdef>
61 <funcdef>int <function>sd_is_socket_inet</function></funcdef>
62 <paramdef>int <parameter>fd</parameter></paramdef>
63 <paramdef>int <parameter>family</parameter></paramdef>
64 <paramdef>int <parameter>type</parameter></paramdef>
65 <paramdef>int <parameter>listening</parameter></paramdef>
66 <paramdef>uint16_t <parameter>port</parameter></paramdef>
70 <funcdef>int <function>sd_is_socket_sockaddr</function></funcdef>
71 <paramdef>int <parameter>fd</parameter></paramdef>
72 <paramdef>int <parameter>type</parameter></paramdef>
73 <paramdef>const struct sockaddr *<parameter>addr</parameter></paramdef>
74 <paramdef>unsigned <parameter>addr_len</parameter></paramdef>
75 <paramdef>int <parameter>listening</parameter></paramdef>
79 <funcdef>int <function>sd_is_socket_unix</function></funcdef>
80 <paramdef>int <parameter>fd</parameter></paramdef>
81 <paramdef>int <parameter>type</parameter></paramdef>
82 <paramdef>int <parameter>listening</parameter></paramdef>
83 <paramdef>const char *<parameter>path</parameter></paramdef>
84 <paramdef>size_t <parameter>length</parameter></paramdef>
88 <funcdef>int <function>sd_is_mq</function></funcdef>
89 <paramdef>int <parameter>fd</parameter></paramdef>
90 <paramdef>const char *<parameter>path</parameter></paramdef>
94 <funcdef>int <function>sd_is_special</function></funcdef>
95 <paramdef>int <parameter>fd</parameter></paramdef>
96 <paramdef>const char *<parameter>path</parameter></paramdef>
103 <title>Description</title>
105 <para><function>sd_is_fifo()</function> may be called to check
106 whether the specified file descriptor refers to a FIFO or pipe. If
107 the <parameter>path</parameter> parameter is not
108 <constant>NULL</constant>, it is checked whether the FIFO is bound
109 to the specified file system path.</para>
111 <para><function>sd_is_socket()</function> may be called to check
112 whether the specified file descriptor refers to a socket. If the
113 <parameter>family</parameter> parameter is not
114 <constant>AF_UNSPEC</constant>, it is checked whether the socket
115 is of the specified family (<constant>AF_UNIX</constant>,
116 <constant>AF_INET</constant>, …). If the <parameter>type</parameter>
117 parameter is not 0, it is checked whether the socket is of the
118 specified type (<constant>SOCK_STREAM</constant>,
119 <constant>SOCK_DGRAM</constant>, …). If the
120 <parameter>listening</parameter> parameter is positive, it is
121 checked whether the socket is in accepting mode, i.e.
122 <function>listen()</function> has been called for it. If
123 <parameter>listening</parameter> is 0, it is checked whether the
124 socket is not in this mode. If the parameter is negative, no such
125 check is made. The <parameter>listening</parameter> parameter
126 should only be used for stream sockets and should be set to a
127 negative value otherwise.</para>
129 <para><function>sd_is_socket_inet()</function> is similar to
130 <function>sd_is_socket()</function>, but optionally checks the
131 IPv4 or IPv6 port number the socket is bound to, unless
132 <parameter>port</parameter> is zero. For this call
133 <parameter>family</parameter> must be passed as either
134 <constant>AF_UNSPEC</constant>, <constant>AF_INET</constant>, or
135 <constant>AF_INET6</constant>.</para>
137 <para><function>sd_is_socket_sockaddr()</function> is similar to
138 <function>sd_is_socket_inet()</function>, but checks if the socket is bound to the
139 address specified by <parameter>addr</parameter>. The
140 <structfield>family</structfield> specified by <parameter>addr</parameter> must be
141 either <constant>AF_INET</constant> or <constant>AF_INET6</constant> and
142 <parameter>addr_len</parameter> must be large enough for that family. If
143 <parameter>addr</parameter> specifies a non-zero port, it is also checked if the
144 socket is bound to this port. In addition, for IPv6, if <parameter>addr</parameter>
145 specifies non-zero <structfield>sin6_flowinfo</structfield> or
146 <structfield>sin6_scope_id</structfield>, it is checked if the socket has the same
149 <para><function>sd_is_socket_unix()</function> is similar to
150 <function>sd_is_socket()</function> but optionally checks the
151 <constant>AF_UNIX</constant> path the socket is bound to, unless
152 the <parameter>path</parameter> parameter is
153 <constant>NULL</constant>. For normal file system
154 <constant>AF_UNIX</constant> sockets, set the
155 <parameter>length</parameter> parameter to 0. For Linux abstract
156 namespace sockets, set the <parameter>length</parameter> to the
157 size of the address, including the initial 0 byte, and set the
158 <parameter>path</parameter> to the initial 0 byte of the socket
161 <para><function>sd_is_mq()</function> may be called to check
162 whether the specified file descriptor refers to a POSIX message
163 queue. If the <parameter>path</parameter> parameter is not
164 <constant>NULL</constant>, it is checked whether the message queue
165 is bound to the specified name.</para>
167 <para><function>sd_is_special()</function> may be called to check
168 whether the specified file descriptor refers to a special file. If
169 the <parameter>path</parameter> parameter is not
170 <constant>NULL</constant>, it is checked whether the file
171 descriptor is bound to the specified filename. Special files in
172 this context are character device nodes and files in
173 <filename>/proc</filename> or <filename>/sys</filename>.</para>
177 <title>Return Value</title>
179 <para>On failure, these calls return a negative errno-style error
180 code. If the file descriptor is of the specified type and bound to
181 the specified address, a positive return value is returned,
182 otherwise zero.</para>
188 <xi:include href="libelogind-pkgconfig.xml" xpointer="pkgconfig-text"/>
190 <para>Internally, these function use a combination of
191 <filename>fstat()</filename> and
192 <filename>getsockname()</filename> to check the file descriptor
193 type and where it is bound to.</para>
197 <title>See Also</title>
199 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
200 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
201 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
202 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
203 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
204 <citerefentry project='man-pages'><refentrytitle>ip</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
205 <citerefentry project='man-pages'><refentrytitle>ipv6</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
206 <citerefentry project='man-pages'><refentrytitle>unix</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
207 <citerefentry project='man-pages'><refentrytitle>fifo</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
208 <citerefentry project='man-pages'><refentrytitle>mq_overview</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
209 <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>.