|
|
|
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `socket` mod in crate `nix`."><meta name="keywords" content="rust, rustlang, rust-lang, socket"><title>nix::sys::socket - Rust</title><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../dark.css"><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><script src="../../../storage.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="shortcut icon" href="../../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../../nix/index.html'><div class='logo-container'><img src='../../../rust-logo.png' alt='logo'></div></a><p class='location'>Module socket</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li><li><a href="#types">Type Definitions</a></li></ul></div><p class='location'><a href='../../index.html'>nix</a>::<wbr><a href='../index.html'>sys</a></p><script>window.sidebarCurrent = {name: 'socket', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../../../settings.html"><img src="../../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span><a class='srclink' href='../../../src/nix/sys/socket/mod.rs.html#1-1338' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../../index.html'>nix</a>::<wbr><a href='../index.html'>sys</a>::<wbr><a class="mod" href=''>socket</a></span></h1><div class='docblock'><p>Socket interface functions</p>
|
|
|
|
|
<p><a href="http://man7.org/linux/man-pages/man7/socket.7.html">Further reading</a></p>
|
|
|
|
|
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
|
|
|
|
|
<table><tr class='module-item'><td><a class="mod" href="sockopt/index.html" title='nix::sys::socket::sockopt mod'>sockopt</a></td><td class='docblock-short'></td></tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
|
|
|
|
<table><tr class='module-item'><td><a class="struct" href="struct.AlgAddr.html" title='nix::sys::socket::AlgAddr struct'>AlgAddr</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.CmsgIterator.html" title='nix::sys::socket::CmsgIterator struct'>CmsgIterator</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.CmsgSpace.html" title='nix::sys::socket::CmsgSpace struct'>CmsgSpace</a></td><td class='docblock-short'><p>A structure used to make room in a cmsghdr passed to recvmsg. The
|
|
|
|
|
size and alignment match that of a cmsghdr followed by a T, but the
|
|
|
|
|
fields are not accessible, as the actual types will change on a call
|
|
|
|
|
to recvmsg.</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="struct" href="struct.IpMembershipRequest.html" title='nix::sys::socket::IpMembershipRequest struct'>IpMembershipRequest</a></td><td class='docblock-short'><p>Request for multicast socket operations</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Ipv4Addr.html" title='nix::sys::socket::Ipv4Addr struct'>Ipv4Addr</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.Ipv6Addr.html" title='nix::sys::socket::Ipv6Addr struct'>Ipv6Addr</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.Ipv6MembershipRequest.html" title='nix::sys::socket::Ipv6MembershipRequest struct'>Ipv6MembershipRequest</a></td><td class='docblock-short'><p>Request for ipv6 multicast socket operations</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="struct" href="struct.LinkAddr.html" title='nix::sys::socket::LinkAddr struct'>LinkAddr</a></td><td class='docblock-short'><p>Hardware Address</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="struct" href="struct.MsgFlags.html" title='nix::sys::socket::MsgFlags struct'>MsgFlags</a></td><td class='docblock-short'><p>Flags for send/recv and their relatives</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="struct" href="struct.NetlinkAddr.html" title='nix::sys::socket::NetlinkAddr struct'>NetlinkAddr</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.RecvMsg.html" title='nix::sys::socket::RecvMsg struct'>RecvMsg</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.SockFlag.html" title='nix::sys::socket::SockFlag struct'>SockFlag</a></td><td class='docblock-short'><p>Additional socket options</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="struct" href="struct.UnixAddr.html" title='nix::sys::socket::UnixAddr struct'>UnixAddr</a></td><td class='docblock-short'><p>A wrapper around <code>sockaddr_un</code>.</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="struct" href="struct.UnixCredentials.html" title='nix::sys::socket::UnixCredentials struct'>UnixCredentials</a></td><td class='docblock-short'><p>Unix credentials of the sending process.</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="struct" href="struct.cmsghdr.html" title='nix::sys::socket::cmsghdr struct'>cmsghdr</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.msghdr.html" title='nix::sys::socket::msghdr struct'>msghdr</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.sockaddr.html" title='nix::sys::socket::sockaddr struct'>sockaddr</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.sockaddr_in.html" title='nix::sys::socket::sockaddr_in struct'>sockaddr_in</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.sockaddr_in6.html" title='nix::sys::socket::sockaddr_in6 struct'>sockaddr_in6</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.sockaddr_storage.html" title='nix::sys::socket::sockaddr_storage struct'>sockaddr_storage</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="struct" href="struct.sockaddr_un.html" title='nix::sys::socket::sockaddr_un struct'>sockaddr_un</a></td><td class='docblock-short'></td></tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
|
|
|
|
|
<table><tr class='module-item'><td><a class="enum" href="enum.AddressFamily.html" title='nix::sys::socket::AddressFamily enum'>AddressFamily</a></td><td class='docblock-short'><p>These constants specify the protocol family to be used
|
|
|
|
|
in <a href="fn.socket.html"><code>socket</code></a> and <a href="fn.socketpair.html"><code>socketpair</code></a></p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="enum" href="enum.ControlMessage.html" title='nix::sys::socket::ControlMessage enum'>ControlMessage</a></td><td class='docblock-short'><p>A type-safe zero-copy wrapper around a single control message, as used wih
|
|
|
|
|
<a href="#fn.sendmsg"><code>sendmsg</code></a>. More types may be added to this enum; do not
|
|
|
|
|
exhaustively pattern-match it.</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="enum" href="enum.ControlMessageOwned.html" title='nix::sys::socket::ControlMessageOwned enum'>ControlMessageOwned</a></td><td class='docblock-short'><p>A type-safe wrapper around a single control message, as used with
|
|
|
|
|
<a href="#fn.recvmsg"><code>recvmsg</code></a>.</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="enum" href="enum.InetAddr.html" title='nix::sys::socket::InetAddr enum'>InetAddr</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="enum" href="enum.IpAddr.html" title='nix::sys::socket::IpAddr enum'>IpAddr</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="enum" href="enum.Shutdown.html" title='nix::sys::socket::Shutdown enum'>Shutdown</a></td><td class='docblock-short'></td></tr><tr class='module-item'><td><a class="enum" href="enum.SockAddr.html" title='nix::sys::socket::SockAddr enum'>SockAddr</a></td><td class='docblock-short'><p>Represents a socket address</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="enum" href="enum.SockLevel.html" title='nix::sys::socket::SockLevel enum'>SockLevel</a></td><td class='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><tr class='module-item'><td><a class="enum" href="enum.SockProtocol.html" title='nix::sys::socket::SockProtocol enum'>SockProtocol</a></td><td class='docblock-short'><p>Constants used in <a href="fn.socket.html"><code>socket</code></a> and <a href="fn.socketpair.html"><code>socketpair</code></a>
|
|
|
|
|
to specify the protocol to use.</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="enum" href="enum.SockType.html" title='nix::sys::socket::SockType enum'>SockType</a></td><td class='docblock-short'><p>These constants are used to specify the communication semantics
|
|
|
|
|
when creating a socket with <a href="fn.socket.html"><code>socket()</code></a></p>
|
|
|
|
|
</td></tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
|
|
|
|
|
<table><tr class='module-item'><td><a class="trait" href="trait.CmsgBuffer.html" title='nix::sys::socket::CmsgBuffer trait'>CmsgBuffer</a></td><td class='docblock-short'><p>A type that can be used to store ancillary data received by
|
|
|
|
|
<a href="fn.recvmsg.html"><code>recvmsg</code></a></p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="trait" href="trait.GetSockOpt.html" title='nix::sys::socket::GetSockOpt trait'>GetSockOpt</a></td><td class='docblock-short'><p>Represents a socket option that can be accessed or set. Used as an argument
|
|
|
|
|
to <code>getsockopt</code></p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="trait" href="trait.SetSockOpt.html" title='nix::sys::socket::SetSockOpt trait'>SetSockOpt</a></td><td class='docblock-short'><p>Represents a socket option that can be accessed or set. Used as an argument
|
|
|
|
|
to <code>setsockopt</code></p>
|
|
|
|
|
</td></tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
|
|
|
|
|
<table><tr class='module-item'><td><a class="fn" href="fn.accept.html" title='nix::sys::socket::accept fn'>accept</a></td><td class='docblock-short'><p>Accept a connection on a socket</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.accept4.html" title='nix::sys::socket::accept4 fn'>accept4</a></td><td class='docblock-short'><p>Accept a connection on a socket</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.bind.html" title='nix::sys::socket::bind fn'>bind</a></td><td class='docblock-short'><p>Bind a name to a socket</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.connect.html" title='nix::sys::socket::connect fn'>connect</a></td><td class='docblock-short'><p>Initiate a connection on a socket</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.getpeername.html" title='nix::sys::socket::getpeername fn'>getpeername</a></td><td class='docblock-short'><p>Get the address of the peer connected to the socket <code>fd</code>.</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.getsockname.html" title='nix::sys::socket::getsockname fn'>getsockname</a></td><td class='docblock-short'><p>Get the current address to which the socket <code>fd</code> is bound.</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.getsockopt.html" title='nix::sys::socket::getsockopt fn'>getsockopt</a></td><td class='docblock-short'><p>Get the current value for the requested socket option</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.listen.html" title='nix::sys::socket::listen fn'>listen</a></td><td class='docblock-short'><p>Listen for connections on a socket</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.recv.html" title='nix::sys::socket::recv fn'>recv</a></td><td class='docblock-short'><p>Receive data from a connection-oriented socket. Returns the number of
|
|
|
|
|
bytes read</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.recvfrom.html" title='nix::sys::socket::recvfrom fn'>recvfrom</a></td><td class='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><tr class='module-item'><td><a class="fn" href="fn.recvmsg.html" title='nix::sys::socket::recvmsg fn'>recvmsg</a></td><td class='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><tr class='module-item'><td><a class="fn" href="fn.send.html" title='nix::sys::socket::send fn'>send</a></td><td class='docblock-short'><p>Send data to a connection-oriented socket. Returns the number of bytes read</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.sendmsg.html" title='nix::sys::socket::sendmsg fn'>sendmsg</a></td><td class='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><tr class='module-item'><td><a class="fn" href="fn.sendto.html" title='nix::sys::socket::sendto fn'>sendto</a></td><td class='docblock-short'><p>Send a message to a socket</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.setsockopt.html" title='nix::sys::socket::setsockopt fn'>setsockopt</a></td><td class='docblock-short'><p>Sets the value for the requested socket option</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.shutdown.html" title='nix::sys::socket::shutdown fn'>shutdown</a></td><td class='docblock-short'><p>Shut down part of a full-duplex connection.</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.sockaddr_storage_to_addr.html" title='nix::sys::socket::sockaddr_storage_to_addr fn'>sockaddr_storage_to_addr</a><a title='unsafe function' href='#'><sup>⚠</sup></a></td><td class='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><tr class='module-item'><td><a class="fn" href="fn.socket.html" title='nix::sys::socket::socket fn'>socket</a></td><td class='docblock-short'><p>Create an endpoint for communication</p>
|
|
|
|
|
</td></tr><tr class='module-item'><td><a class="fn" href="fn.socketpair.html" title='nix::sys::socket::socketpair fn'>socketpair</a></td><td class='docblock-short'><p>Create a pair of connected sockets</p>
|
|
|
|
|
</td></tr></table><h2 id='types' class='section-header'><a href="#types">Type Definitions</a></h2>
|
|
|
|
|
<table><tr class='module-item'><td><a class="type" href="type.sa_family_t.html" title='nix::sys::socket::sa_family_t type'>sa_family_t</a></td><td class='docblock-short'></td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="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><div class="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><script src="../../../aliases.js"></script><script src="../../../main.js"></script><script defer src="../../../search-index.js"></script></body></html>
|