]> git.proxmox.com Git - systemd.git/blob - man/sd_is_socket.html
Imported Upstream version 204
[systemd.git] / man / sd_is_socket.html
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_is_fifo</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style>
2 a.headerlink {
3 color: #c60f0f;
4 font-size: 0.8em;
5 padding: 0 4px 0 4px;
6 text-decoration: none;
7 visibility: hidden;
8 }
9
10 a.headerlink:hover {
11 background-color: #c60f0f;
12 color: white;
13 }
14
15 h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
16 visibility: visible;
17 }
18 </style><a href="index.html">Index </a>·
19 <a href="systemd.directives.html">Directives </a>·
20 <a href="../python-systemd/index.html">Python </a>·
21 <a href="../libudev/index.html">libudev </a>·
22 <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 204</span><hr><div class="refentry"><a name="sd_is_fifo"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_is_fifo, sd_is_socket, sd_is_socket_inet, sd_is_socket_unix, sd_is_mq — Check the type of a file descriptor</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;systemd/sd-daemon.h&gt;</pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_fifo</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">path</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_socket</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">family</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">type</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">listening</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_socket_inet</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">family</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">type</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">listening</var>, </td></tr><tr><td> </td><td>uint16_t <var class="pdparam">port</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_socket_unix</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">type</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">listening</var>, </td></tr><tr><td> </td><td>const char* <var class="pdparam">path</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">length</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_mq</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">path</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm259784659536"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description"></a></h2><p><code class="function">sd_is_fifo()</code> may be called
23 to check whether the specified file descriptor refers
24 to a FIFO or pipe. If the <em class="parameter"><code>path</code></em>
25 parameter is not NULL, it is checked whether the FIFO
26 is bound to the specified file system path.</p><p><code class="function">sd_is_socket()</code> may be
27 called to check whether the specified file descriptor
28 refers to a socket. If the
29 <em class="parameter"><code>family</code></em> parameter is not
30 AF_UNSPEC it is checked whether the socket is of the
31 specified family (AF_UNIX, AF_INET, ...). If the
32 <em class="parameter"><code>type</code></em> parameter is not 0 it is
33 checked whether the socket is of the specified type
34 (SOCK_STREAM, SOCK_DGRAM, ...). If the
35 <em class="parameter"><code>listening</code></em> parameter is positive
36 it is checked whether the socket is in accepting mode,
37 i.e. <code class="function">listen()</code> has been called for
38 it. If <em class="parameter"><code>listening</code></em> is 0, it is
39 checked whether the socket is not in this mode. If the
40 parameter is negative, no such check is made. The
41 <em class="parameter"><code>listening</code></em> parameter should only
42 be used for stream sockets and should be set to a
43 negative value otherwise.</p><p><code class="function">sd_is_socket_inet()</code> is
44 similar to <code class="function">sd_is_socket()</code>, but
45 optionally checks the IPv4 or IPv6 port number the
46 socket is bound to, unless <em class="parameter"><code>port</code></em>
47 is zero. For this call <em class="parameter"><code>family</code></em>
48 must be passed as either AF_UNSPEC, AF_INET, or
49 AF_INET6.</p><p><code class="function">sd_is_socket_unix()</code> is
50 similar to <code class="function">sd_is_socket()</code>, but
51 optionally checks the AF_UNIX path the socket is bound
52 to, unless the <em class="parameter"><code>path</code></em> parameter
53 is NULL. For normal file system AF_UNIX sockets set
54 the <em class="parameter"><code>length</code></em> parameter to 0. For
55 Linux abstract namespace sockets set the
56 <em class="parameter"><code>length</code></em> to the size of the
57 address, including the initial 0 byte and set
58 <em class="parameter"><code>path</code></em> to the initial 0 byte of
59 the socket address.</p><p><code class="function">sd_is_mq()</code> may be called to
60 check whether the specified file descriptor refers to
61 a POSIX message queue. If the
62 <em class="parameter"><code>path</code></em> parameter is not NULL, it
63 is checked whether the message queue is bound to the
64 specified name.</p></div><div class="refsect1"><a name="idm259784633360"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value"></a></h2><p>On failure, these calls return a negative
65 errno-style error code. If the file descriptor is of
66 the specified type and bound to the specified address
67 a positive return value is returned, otherwise
68 zero.</p></div><div class="refsect1"><a name="idm259784631888"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes"></a></h2><p>These functions are provided by the reference
69 implementation of APIs for new-style daemons and
70 distributed with the systemd package. The algorithms
71 they implement are simple, and can easily be
72 reimplemented in daemons if it is important to support
73 this interface without using the reference
74 implementation.</p><p>Internally, these function use a combination of
75 <code class="filename">fstat()</code> and
76 <code class="filename">getsockname()</code> to check the file
77 descriptor type and where it is bound to.</p><p>For details about the algorithms check the
78 liberally licensed reference implementation sources:
79 <a class="ulink" href="http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c" target="_top">http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c</a>
80 and <a class="ulink" href="http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h" target="_top">http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h</a></p><p><code class="function">sd_is_fifo()</code> and the
81 related functions are implemented in the reference
82 implementation's <code class="filename">sd-daemon.c</code> and
83 <code class="filename">sd-daemon.h</code> files. These
84 interfaces are available as shared library, which can
85 be compiled and linked to with the
86 <code class="literal">libsystemd-daemon</code>
87 <a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
88 file. Alternatively, applications consuming these APIs
89 may copy the implementation into their source
90 tree. For more details about the reference
91 implementation see
92 <a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>.</p><p>These functions continue to work as described,
93 even if -DDISABLE_SYSTEMD is set during
94 compilation.</p></div><div class="refsect1"><a name="idm259784621312"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also"></a></h2><p>
95 <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
96 <a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>,
97 <a href="sd_listen_fds.html"><span class="citerefentry"><span class="refentrytitle">sd_listen_fds</span>(3)</span></a>,
98 <a href="systemd.service.html"><span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span></a>,
99 <a href="systemd.socket.html"><span class="citerefentry"><span class="refentrytitle">systemd.socket</span>(5)</span></a>
100 </p></div></div></body></html>