<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="API documentation for the Rust `socket` mod in crate `nix`."><metaname="keywords"content="rust, rustlang, rust-lang, socket"><title>nix::sys::socket - Rust</title><linkrel="stylesheet"type="text/css"href="../../../normalize.css"><linkrel="stylesheet"type="text/css"href="../../../rustdoc.css"id="mainThemeStyle"><linkrel="stylesheet"type="text/css"href="../../../dark.css"><linkrel="stylesheet"type="text/css"href="../../../light.css"id="themeStyle"><scriptsrc="../../../storage.js"></script><noscript><linkrel="stylesheet"href="../../../noscript.css"></noscript><linkrel="shortcut icon"href="../../../favicon.ico"><styletype="text/css">#crate-search{background-image:url("../../../down-arrow.svg");}</style></head><bodyclass="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="sidebar"><divclass="sidebar-menu">☰</div><ahref='../../../nix/index.html'><divclass='logo-container'><imgsrc='../../../rust-logo.png'alt='logo'></div></a><pclass='location'>Module socket</p><divclass="sidebar-elems"><divclass="block items"><ul><li><ahref="#modules">Modules</a></li><li><ahref="#structs">Structs</a></li><li><ahref="#enums">Enums</a></li><li><ahref="#traits">Traits</a></li><li><ahref="#functions">Functions</a></li><li><ahref="#types">Type Definitions</a></li></ul></div><pclass='location'><ahref='../../index.html'>nix</a>::<wbr><ahref='../index.html'>sys</a></p><script>window.sidebarCurrent={name:'socket',ty:'mod',relpath:'../'};</script><scriptdefersrc="../sidebar-items.js"></script></div></nav><divclass="theme-picker"><buttonid="theme-picker"aria-label="Pick another theme!"><imgsrc="../../../brush.svg"width="18"alt="Pick another theme!"></button><divid="theme-choices"></div></div><scriptsrc="../../../theme.js"></script><navclass="sub"><formclass="search-form js-only"><divclass="search-container"><div><selectid="crate-search"><optionvalue="All crates">All crates</option></select><inputclass="search-input"name="search"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"></div><aid="settings-menu"href="../../../settings.html"><imgsrc="../../../wheel.svg"width="18"alt="Change settings"></a></div></form></nav><sectionid="main"class="content"><h1class='fqn'><spanclass='out-of-band'><spanid='render-detail'><aid="toggle-all-docs"href="javascript:void(0)"title="collapse all docs">[<spanclass='inner'>−</span>]</a></span><aclass='srclink'href='../../../src/nix/sys/socket/mod.rs.html#1-1294'title='goto source code'>[src]</a></span><spanclass='in-band'>Module <ahref='../../index.html'>nix</a>::<wbr><ahref='../index.html'>sys</a>::<wbr><aclass="mod"href=''>socket</a></span></h1><divclass='docblock'><p>Socket interface functions</p>
<table><trclass='module-item'><td><aclass="struct"href="struct.CmsgIterator.html"title='nix::sys::socket::CmsgIterator struct'>CmsgIterator</a></td><tdclass='docblock-short'></td></tr><trclass='module-item'><td><aclass="struct"href="struct.CmsgSpace.html"title='nix::sys::socket::CmsgSpace struct'>CmsgSpace</a></td><tdclass='docblock-short'><p>A structure used to make room in a cmsghdr passed to recvmsg. The
</td></tr><trclass='module-item'><td><aclass="struct"href="struct.MsgFlags.html"title='nix::sys::socket::MsgFlags struct'>MsgFlags</a></td><tdclass='docblock-short'><p>Flags for send/recv and their relatives</p>
</td></tr><trclass='module-item'><td><aclass="struct"href="struct.UnixAddr.html"title='nix::sys::socket::UnixAddr struct'>UnixAddr</a></td><tdclass='docblock-short'><p>A wrapper around <code>sockaddr_un</code>.</p>
<table><trclass='module-item'><td><aclass="enum"href="enum.AddressFamily.html"title='nix::sys::socket::AddressFamily enum'>AddressFamily</a></td><tdclass='docblock-short'><p>These constants specify the protocol family to be used
in <ahref="fn.socket.html"><code>socket</code></a> and <ahref="fn.socketpair.html"><code>socketpair</code></a></p>
</td></tr><trclass='module-item'><td><aclass="enum"href="enum.ControlMessage.html"title='nix::sys::socket::ControlMessage enum'>ControlMessage</a></td><tdclass='docblock-short'><p>A type-safe zero-copy wrapper around a single control message, as used wih
<ahref="#fn.sendmsg"><code>sendmsg</code></a>. More types may be added to this enum; do not
exhaustively pattern-match it.</p>
</td></tr><trclass='module-item'><td><aclass="enum"href="enum.ControlMessageOwned.html"title='nix::sys::socket::ControlMessageOwned enum'>ControlMessageOwned</a></td><tdclass='docblock-short'><p>A type-safe wrapper around a single control message, as used with
</td></tr><trclass='module-item'><td><aclass="enum"href="enum.InetAddr.html"title='nix::sys::socket::InetAddr enum'>InetAddr</a></td><tdclass='docblock-short'></td></tr><trclass='module-item'><td><aclass="enum"href="enum.IpAddr.html"title='nix::sys::socket::IpAddr enum'>IpAddr</a></td><tdclass='docblock-short'></td></tr><trclass='module-item'><td><aclass="enum"href="enum.Shutdown.html"title='nix::sys::socket::Shutdown enum'>Shutdown</a></td><tdclass='docblock-short'></td></tr><trclass='module-item'><td><aclass="enum"href="enum.SockAddr.html"title='nix::sys::socket::SockAddr enum'>SockAddr</a></td><tdclass='docblock-short'><p>Represents a socket address</p>
</td></tr><trclass='module-item'><td><aclass="enum"href="enum.SockLevel.html"title='nix::sys::socket::SockLevel enum'>SockLevel</a></td><tdclass='docblock-short'><p>The protocol level at which to get / set socket options. Used as an
argument to <code>getsockopt</code> and <code>setsockopt</code>.</p>
</td></tr><trclass='module-item'><td><aclass="enum"href="enum.SockProtocol.html"title='nix::sys::socket::SockProtocol enum'>SockProtocol</a></td><tdclass='docblock-short'><p>Constants used in <ahref="fn.socket.html"><code>socket</code></a> and <ahref="fn.socketpair.html"><code>socketpair</code></a>
to specify the protocol to use.</p>
</td></tr><trclass='module-item'><td><aclass="enum"href="enum.SockType.html"title='nix::sys::socket::SockType enum'>SockType</a></td><tdclass='docblock-short'><p>These constants are used to specify the communication semantics
when creating a socket with <ahref="fn.socket.html"><code>socket()</code></a></p>
<table><trclass='module-item'><td><aclass="trait"href="trait.CmsgBuffer.html"title='nix::sys::socket::CmsgBuffer trait'>CmsgBuffer</a></td><tdclass='docblock-short'><p>A type that can be used to store ancillary data received by
</td></tr><trclass='module-item'><td><aclass="trait"href="trait.GetSockOpt.html"title='nix::sys::socket::GetSockOpt trait'>GetSockOpt</a></td><tdclass='docblock-short'><p>Represents a socket option that can be accessed or set. Used as an argument
to <code>getsockopt</code></p>
</td></tr><trclass='module-item'><td><aclass="trait"href="trait.SetSockOpt.html"title='nix::sys::socket::SetSockOpt trait'>SetSockOpt</a></td><tdclass='docblock-short'><p>Represents a socket option that can be accessed or set. Used as an argument
<table><trclass='module-item'><td><aclass="fn"href="fn.accept.html"title='nix::sys::socket::accept fn'>accept</a></td><tdclass='docblock-short'><p>Accept a connection on a socket</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.bind.html"title='nix::sys::socket::bind fn'>bind</a></td><tdclass='docblock-short'><p>Bind a name to a socket</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.connect.html"title='nix::sys::socket::connect fn'>connect</a></td><tdclass='docblock-short'><p>Initiate a connection on a socket</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.getpeername.html"title='nix::sys::socket::getpeername fn'>getpeername</a></td><tdclass='docblock-short'><p>Get the address of the peer connected to the socket <code>fd</code>.</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.getsockname.html"title='nix::sys::socket::getsockname fn'>getsockname</a></td><tdclass='docblock-short'><p>Get the current address to which the socket <code>fd</code> is bound.</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.getsockopt.html"title='nix::sys::socket::getsockopt fn'>getsockopt</a></td><tdclass='docblock-short'><p>Get the current value for the requested socket option</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.listen.html"title='nix::sys::socket::listen fn'>listen</a></td><tdclass='docblock-short'><p>Listen for connections on a socket</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.recv.html"title='nix::sys::socket::recv fn'>recv</a></td><tdclass='docblock-short'><p>Receive data from a connection-oriented socket. Returns the number of
bytes read</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.recvfrom.html"title='nix::sys::socket::recvfrom fn'>recvfrom</a></td><tdclass='docblock-short'><p>Receive data from a connectionless or connection-oriented socket. Returns
the number of bytes read and the socket address of the sender.</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.recvmsg.html"title='nix::sys::socket::recvmsg fn'>recvmsg</a></td><tdclass='docblock-short'><p>Receive message in scatter-gather vectors from a socket, and
optionally receive ancillary data into the provided buffer.
If no ancillary data is desired, use () as the type parameter.</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.send.html"title='nix::sys::socket::send fn'>send</a></td><tdclass='docblock-short'><p>Send data to a connection-oriented socket. Returns the number of bytes read</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.sendmsg.html"title='nix::sys::socket::sendmsg fn'>sendmsg</a></td><tdclass='docblock-short'><p>Send data in scatter-gather vectors to a socket, possibly accompanied
by ancillary data. Optionally direct the message at the given address,
as with sendto.</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.sendto.html"title='nix::sys::socket::sendto fn'>sendto</a></td><tdclass='docblock-short'><p>Send a message to a socket</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.setsockopt.html"title='nix::sys::socket::setsockopt fn'>setsockopt</a></td><tdclass='docblock-short'><p>Sets the value for the requested socket option</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.shutdown.html"title='nix::sys::socket::shutdown fn'>shutdown</a></td><tdclass='docblock-short'><p>Shut down part of a full-duplex connection.</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.sockaddr_storage_to_addr.html"title='nix::sys::socket::sockaddr_storage_to_addr fn'>sockaddr_storage_to_addr</a><atitle='unsafe function'href='#'><sup>⚠</sup></a></td><tdclass='docblock-short'><p>Return the appropriate <code>SockAddr</code> type from a <code>sockaddr_storage</code> of a certain
size. In C this would usually be done by casting. The <code>len</code> argument
should be the number of bytes in the <code>sockaddr_storage</code> that are actually
allocated and valid. It must be at least as large as all the useful parts
of the structure. Note that in the case of a <code>sockaddr_un</code>, <code>len</code> need not
include the terminating null.</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.socket.html"title='nix::sys::socket::socket fn'>socket</a></td><tdclass='docblock-short'><p>Create an endpoint for communication</p>
</td></tr><trclass='module-item'><td><aclass="fn"href="fn.socketpair.html"title='nix::sys::socket::socketpair fn'>socketpair</a></td><tdclass='docblock-short'><p>Create a pair of connected sockets</p>
<table><trclass='module-item'><td><aclass="type"href="type.sa_family_t.html"title='nix::sys::socket::sa_family_t type'>sa_family_t</a></td><tdclass='docblock-short'></td></tr></table></section><sectionid="search"class="content hidden"></section><sectionclass="footer"></section><asideid="help"class="hidden"><div><h1class="hidden">Help</h1><divclass="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>⏎</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><divclass="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath="../../../";window.currentCrate="nix";</script><scriptsrc="../../../aliases.js"></script><scriptsrc="../../../main.js"></script><scriptdefersrc="../../../search-index.js"></script></body></html>