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 <refentrytitle>sd_is_fifo
</refentrytitle>
19 <manvolnum>3</manvolnum>
23 <refname>sd_is_fifo
</refname>
24 <refname>sd_is_socket
</refname>
25 <refname>sd_is_socket_inet
</refname>
26 <refname>sd_is_socket_unix
</refname>
27 <refname>sd_is_socket_sockaddr
</refname>
28 <refname>sd_is_mq
</refname>
29 <refname>sd_is_special
</refname>
30 <refpurpose>Check the type of a file descriptor
</refpurpose>
35 <funcsynopsisinfo>#include
<systemd/sd-daemon.h
></funcsynopsisinfo>
38 <funcdef>int
<function>sd_is_fifo
</function></funcdef>
39 <paramdef>int
<parameter>fd
</parameter></paramdef>
40 <paramdef>const char *
<parameter>path
</parameter></paramdef>
44 <funcdef>int
<function>sd_is_socket
</function></funcdef>
45 <paramdef>int
<parameter>fd
</parameter></paramdef>
46 <paramdef>int
<parameter>family
</parameter></paramdef>
47 <paramdef>int
<parameter>type
</parameter></paramdef>
48 <paramdef>int
<parameter>listening
</parameter></paramdef>
52 <funcdef>int
<function>sd_is_socket_inet
</function></funcdef>
53 <paramdef>int
<parameter>fd
</parameter></paramdef>
54 <paramdef>int
<parameter>family
</parameter></paramdef>
55 <paramdef>int
<parameter>type
</parameter></paramdef>
56 <paramdef>int
<parameter>listening
</parameter></paramdef>
57 <paramdef>uint16_t
<parameter>port
</parameter></paramdef>
61 <funcdef>int
<function>sd_is_socket_sockaddr
</function></funcdef>
62 <paramdef>int
<parameter>fd
</parameter></paramdef>
63 <paramdef>int
<parameter>type
</parameter></paramdef>
64 <paramdef>const struct sockaddr *
<parameter>addr
</parameter></paramdef>
65 <paramdef>unsigned
<parameter>addr_len
</parameter></paramdef>
66 <paramdef>int
<parameter>listening
</parameter></paramdef>
70 <funcdef>int
<function>sd_is_socket_unix
</function></funcdef>
71 <paramdef>int
<parameter>fd
</parameter></paramdef>
72 <paramdef>int
<parameter>type
</parameter></paramdef>
73 <paramdef>int
<parameter>listening
</parameter></paramdef>
74 <paramdef>const char *
<parameter>path
</parameter></paramdef>
75 <paramdef>size_t
<parameter>length
</parameter></paramdef>
79 <funcdef>int
<function>sd_is_mq
</function></funcdef>
80 <paramdef>int
<parameter>fd
</parameter></paramdef>
81 <paramdef>const char *
<parameter>path
</parameter></paramdef>
85 <funcdef>int
<function>sd_is_special
</function></funcdef>
86 <paramdef>int
<parameter>fd
</parameter></paramdef>
87 <paramdef>const char *
<parameter>path
</parameter></paramdef>
94 <title>Description
</title>
96 <para><function>sd_is_fifo()
</function> may be called to check
97 whether the specified file descriptor refers to a FIFO or pipe. If
98 the
<parameter>path
</parameter> parameter is not
99 <constant>NULL
</constant>, it is checked whether the FIFO is bound
100 to the specified file system path.
</para>
102 <para><function>sd_is_socket()
</function> may be called to check
103 whether the specified file descriptor refers to a socket. If the
104 <parameter>family
</parameter> parameter is not
105 <constant>AF_UNSPEC
</constant>, it is checked whether the socket
106 is of the specified family (
<constant>AF_UNIX
</constant>,
107 <constant>AF_INET
</constant>, …). If the
<parameter>type
</parameter>
108 parameter is not
0, it is checked whether the socket is of the
109 specified type (
<constant>SOCK_STREAM
</constant>,
110 <constant>SOCK_DGRAM
</constant>, …). If the
111 <parameter>listening
</parameter> parameter is positive, it is
112 checked whether the socket is in accepting mode, i.e.
113 <function>listen()
</function> has been called for it. If
114 <parameter>listening
</parameter> is
0, it is checked whether the
115 socket is not in this mode. If the parameter is negative, no such
116 check is made. The
<parameter>listening
</parameter> parameter
117 should only be used for stream sockets and should be set to a
118 negative value otherwise.
</para>
120 <para><function>sd_is_socket_inet()
</function> is similar to
121 <function>sd_is_socket()
</function>, but optionally checks the
122 IPv4 or IPv6 port number the socket is bound to, unless
123 <parameter>port
</parameter> is zero. For this call
124 <parameter>family
</parameter> must be passed as either
125 <constant>AF_UNSPEC
</constant>,
<constant>AF_INET
</constant>, or
126 <constant>AF_INET6
</constant>.
</para>
128 <para><function>sd_is_socket_sockaddr()
</function> is similar to
129 <function>sd_is_socket_inet()
</function>, but checks if the socket is bound to the
130 address specified by
<parameter>addr
</parameter>. The
131 <structfield>family
</structfield> specified by
<parameter>addr
</parameter> must be
132 either
<constant>AF_INET
</constant> or
<constant>AF_INET6
</constant> and
133 <parameter>addr_len
</parameter> must be large enough for that family. If
134 <parameter>addr
</parameter> specifies a non-zero port, it is also checked if the
135 socket is bound to this port. In addition, for IPv6, if
<parameter>addr
</parameter>
136 specifies non-zero
<structfield>sin6_flowinfo
</structfield> or
137 <structfield>sin6_scope_id
</structfield>, it is checked if the socket has the same
140 <para><function>sd_is_socket_unix()
</function> is similar to
141 <function>sd_is_socket()
</function> but optionally checks the
142 <constant>AF_UNIX
</constant> path the socket is bound to, unless
143 the
<parameter>path
</parameter> parameter is
144 <constant>NULL
</constant>. For normal file system
145 <constant>AF_UNIX
</constant> sockets, set the
146 <parameter>length
</parameter> parameter to
0. For Linux abstract
147 namespace sockets, set the
<parameter>length
</parameter> to the
148 size of the address, including the initial
0 byte, and set the
149 <parameter>path
</parameter> to the initial
0 byte of the socket
152 <para><function>sd_is_mq()
</function> may be called to check
153 whether the specified file descriptor refers to a POSIX message
154 queue. If the
<parameter>path
</parameter> parameter is not
155 <constant>NULL
</constant>, it is checked whether the message queue
156 is bound to the specified name.
</para>
158 <para><function>sd_is_special()
</function> may be called to check
159 whether the specified file descriptor refers to a special file. If
160 the
<parameter>path
</parameter> parameter is not
161 <constant>NULL
</constant>, it is checked whether the file
162 descriptor is bound to the specified filename. Special files in
163 this context are character device nodes and files in
164 <filename>/proc
</filename> or
<filename>/sys
</filename>.
</para>
168 <title>Return Value
</title>
170 <para>On failure, these calls return a negative errno-style error
171 code. If the file descriptor is of the specified type and bound to
172 the specified address, a positive return value is returned,
173 otherwise zero.
</para>
179 <xi:include href=
"libsystemd-pkgconfig.xml" xpointer=
"pkgconfig-text"/>
181 <para>Internally, these function use a combination of
182 <filename>fstat()
</filename> and
183 <filename>getsockname()
</filename> to check the file descriptor
184 type and where it is bound to.
</para>
188 <title>See Also
</title>
190 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
191 <citerefentry><refentrytitle>sd-daemon
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
192 <citerefentry><refentrytitle>sd_listen_fds
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
193 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
194 <citerefentry><refentrytitle>systemd.socket
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
195 <citerefentry project='man-pages'
><refentrytitle>ip
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
196 <citerefentry project='man-pages'
><refentrytitle>ipv6
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
197 <citerefentry project='man-pages'
><refentrytitle>unix
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
198 <citerefentry project='man-pages'
><refentrytitle>fifo
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
199 <citerefentry project='man-pages'
><refentrytitle>mq_overview
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
200 <citerefentry project='man-pages'
><refentrytitle>socket
</refentrytitle><manvolnum>7</manvolnum></citerefentry>.