<!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 `sysctl` crate."><meta name="keywords" content="rust, rustlang, rust-lang, sysctl"><title>sysctl - 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></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><p class='location'>Crate sysctl</p><div class="sidebar-elems"><a id='all-types' href='all.html'><p>See all sysctl's items</p></a><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#constants">Constants</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'sysctl', ty: 'mod', relpath: '../'};</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"><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><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/sysctl/lib.rs.html#1-2151' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>sysctl</a></span></h1><div class='docblock'><p>A simplified interface to the <code>sysctl</code> system call.</p>
<p>Currently built for and only tested on FreeBSD.</p>
<h1 id="example-get-description-and-value" class="section-header"><a href="#example-get-description-and-value">Example: Get description and value</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">sysctl</span>;
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">not</span>(<span class="ident">target_os</span> <span class="op">=</span> <span class="string">"macos"</span>))]</span>
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="kw">let</span> <span class="ident">ctl</span> <span class="op">=</span> <span class="ident">sysctl</span>::<span class="ident">Ctl</span>::<span class="ident">new</span>(<span class="string">"kern.osrevision"</span>)
.<span class="ident">expect</span>(<span class="string">"could not get sysctl"</span>);
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">ctl</span>.<span class="ident">description</span>()
.<span class="ident">expect</span>(<span class="string">"could not get description"</span>);
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"Description: {:?}"</span>, <span class="ident">d</span>);
<span class="kw">let</span> <span class="ident">val_enum</span> <span class="op">=</span> <span class="ident">ctl</span>.<span class="ident">value</span>()
.<span class="ident">expect</span>(<span class="string">"could not get value"</span>);
<span class="kw">if</span> <span class="kw">let</span> <span class="ident">sysctl</span>::<span class="ident">CtlValue</span>::<span class="ident">Int</span>(<span class="ident">val</span>) <span class="op">=</span> <span class="ident">val_enum</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"Value: {}"</span>, <span class="ident">val</span>);
}
}
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">target_os</span> <span class="op">=</span> <span class="string">"macos"</span>)]</span>
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">ctl</span> <span class="op">=</span> <span class="ident">sysctl</span>::<span class="ident">Ctl</span>::<span class="ident">new</span>(<span class="string">"kern.osrevision"</span>)
.<span class="ident">expect</span>(<span class="string">"could not get sysctl"</span>);
<span class="comment">// description is not available on macos</span>
<span class="kw">let</span> <span class="ident">val_enum</span> <span class="op">=</span> <span class="ident">ctl</span>.<span class="ident">value</span>()
.<span class="ident">expect</span>(<span class="string">"could not get value"</span>);
<span class="kw">if</span> <span class="kw">let</span> <span class="ident">sysctl</span>::<span class="ident">CtlValue</span>::<span class="ident">Int</span>(<span class="ident">val</span>) <span class="op">=</span> <span class="ident">val_enum</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"Value: {}"</span>, <span class="ident">val</span>);
}
}</pre>
<h1 id="example-get-value-as-struct" class="section-header"><a href="#example-get-value-as-struct">Example: Get value as struct</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">sysctl</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">libc</span>;
<span class="kw">use</span> <span class="ident">libc</span>::<span class="ident">c_int</span>;
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Debug</span>)]</span>
<span class="attribute">#[<span class="ident">repr</span>(<span class="ident">C</span>)]</span>
<span class="kw">struct</span> <span class="ident">ClockInfo</span> {
<span class="ident">hz</span>: <span class="ident">c_int</span>, <span class="comment">/* clock frequency */</span>
<span class="ident">tick</span>: <span class="ident">c_int</span>, <span class="comment">/* micro-seconds per hz tick */</span>
<span class="ident">spare</span>: <span class="ident">c_int</span>,
<span class="ident">stathz</span>: <span class="ident">c_int</span>, <span class="comment">/* statistics clock frequency */</span>
<span class="ident">profhz</span>: <span class="ident">c_int</span>, <span class="comment">/* profiling clock frequency */</span>
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">sysctl</span>::<span class="ident">value_as</span>::<span class="op"><</span><span class="ident">ClockInfo</span><span class="op">></span>(<span class="string">"kern.clockrate"</span>));
}</pre>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table>
<tr class=' module-item'>
<td><a class="struct" href="struct.Ctl.html"
title='struct sysctl::Ctl'>Ctl</a></td>
<td class='docblock-short'>
<p>This struct represents a system control.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.CtlFlags.html"
title='struct sysctl::CtlFlags'>CtlFlags</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.CtlInfo.html"
title='struct sysctl::CtlInfo'>CtlInfo</a></td>
<td class='docblock-short'>
<p>A structure representing control metadata</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.CtlIter.html"
title='struct sysctl::CtlIter'>CtlIter</a></td>
<td class='docblock-short'>
<p>An iterator over Sysctl entries.</p>
</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.CtlType.html"
title='enum sysctl::CtlType'>CtlType</a></td>
<td class='docblock-short'>
<p>An Enum that represents a sysctl's type information.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.CtlValue.html"
title='enum sysctl::CtlValue'>CtlValue</a></td>
<td class='docblock-short'>
<p>An Enum that holds all values returned by sysctl calls.
Extract inner value with <code>if let</code> or <code>match</code>.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.SysctlError.html"
title='enum sysctl::SysctlError'>SysctlError</a></td>
<td class='docblock-short'>
</td>
</tr></table><h2 id='constants' class='section-header'><a href="#constants">Constants</a></h2>
<table>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_ANYBODY.html"
title='constant sysctl::CTLFLAG_ANYBODY'>CTLFLAG_ANYBODY</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_CAPRD.html"
title='constant sysctl::CTLFLAG_CAPRD'>CTLFLAG_CAPRD</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_CAPRW.html"
title='constant sysctl::CTLFLAG_CAPRW'>CTLFLAG_CAPRW</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_CAPWR.html"
title='constant sysctl::CTLFLAG_CAPWR'>CTLFLAG_CAPWR</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_DORMANT.html"
title='constant sysctl::CTLFLAG_DORMANT'>CTLFLAG_DORMANT</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_DYING.html"
title='constant sysctl::CTLFLAG_DYING'>CTLFLAG_DYING</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_DYN.html"
title='constant sysctl::CTLFLAG_DYN'>CTLFLAG_DYN</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_MPSAFE.html"
title='constant sysctl::CTLFLAG_MPSAFE'>CTLFLAG_MPSAFE</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_NOFETCH.html"
title='constant sysctl::CTLFLAG_NOFETCH'>CTLFLAG_NOFETCH</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_PRISON.html"
title='constant sysctl::CTLFLAG_PRISON'>CTLFLAG_PRISON</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_RD.html"
title='constant sysctl::CTLFLAG_RD'>CTLFLAG_RD</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_RDTUN.html"
title='constant sysctl::CTLFLAG_RDTUN'>CTLFLAG_RDTUN</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_RW.html"
title='constant sysctl::CTLFLAG_RW'>CTLFLAG_RW</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_RWTUN.html"
title='constant sysctl::CTLFLAG_RWTUN'>CTLFLAG_RWTUN</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_SECURE.html"
title='constant sysctl::CTLFLAG_SECURE'>CTLFLAG_SECURE</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_SECURE1.html"
title='constant sysctl::CTLFLAG_SECURE1'>CTLFLAG_SECURE1</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_SECURE2.html"
title='constant sysctl::CTLFLAG_SECURE2'>CTLFLAG_SECURE2</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_SECURE3.html"
title='constant sysctl::CTLFLAG_SECURE3'>CTLFLAG_SECURE3</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_SKIP.html"
title='constant sysctl::CTLFLAG_SKIP'>CTLFLAG_SKIP</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_STATS.html"
title='constant sysctl::CTLFLAG_STATS'>CTLFLAG_STATS</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_TUN.html"
title='constant sysctl::CTLFLAG_TUN'>CTLFLAG_TUN</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_VNET.html"
title='constant sysctl::CTLFLAG_VNET'>CTLFLAG_VNET</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLFLAG_WR.html"
title='constant sysctl::CTLFLAG_WR'>CTLFLAG_WR</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLMASK_SECURE.html"
title='constant sysctl::CTLMASK_SECURE'>CTLMASK_SECURE</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLSHIFT_SECURE.html"
title='constant sysctl::CTLSHIFT_SECURE'>CTLSHIFT_SECURE</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE.html"
title='constant sysctl::CTLTYPE'>CTLTYPE</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_INT.html"
title='constant sysctl::CTLTYPE_INT'>CTLTYPE_INT</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_LONG.html"
title='constant sysctl::CTLTYPE_LONG'>CTLTYPE_LONG</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_NODE.html"
title='constant sysctl::CTLTYPE_NODE'>CTLTYPE_NODE</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_OPAQUE.html"
title='constant sysctl::CTLTYPE_OPAQUE'>CTLTYPE_OPAQUE</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_S8.html"
title='constant sysctl::CTLTYPE_S8'>CTLTYPE_S8</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_S16.html"
title='constant sysctl::CTLTYPE_S16'>CTLTYPE_S16</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_S32.html"
title='constant sysctl::CTLTYPE_S32'>CTLTYPE_S32</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_S64.html"
title='constant sysctl::CTLTYPE_S64'>CTLTYPE_S64</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_STRING.html"
title='constant sysctl::CTLTYPE_STRING'>CTLTYPE_STRING</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_STRUCT.html"
title='constant sysctl::CTLTYPE_STRUCT'>CTLTYPE_STRUCT</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_U8.html"
title='constant sysctl::CTLTYPE_U8'>CTLTYPE_U8</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_U16.html"
title='constant sysctl::CTLTYPE_U16'>CTLTYPE_U16</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_U32.html"
title='constant sysctl::CTLTYPE_U32'>CTLTYPE_U32</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_U64.html"
title='constant sysctl::CTLTYPE_U64'>CTLTYPE_U64</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_UINT.html"
title='constant sysctl::CTLTYPE_UINT'>CTLTYPE_UINT</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTLTYPE_ULONG.html"
title='constant sysctl::CTLTYPE_ULONG'>CTLTYPE_ULONG</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="constant" href="constant.CTL_MAXNAME.html"
title='constant sysctl::CTL_MAXNAME'>CTL_MAXNAME</a></td>
<td class='docblock-short'>
</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.next_oid.html"
title='fn sysctl::next_oid'>next_oid</a></td>
<td class='docblock-short'>
<p>Get the next OID.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.set_oid_value.html"
title='fn sysctl::set_oid_value'>set_oid_value</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.set_value.html"
title='fn sysctl::set_value'>set_value</a></td>
<td class='docblock-short'>
<p>Sets the value of a sysctl.
Fetches and returns the new value if successful, or a SysctlError
on failure</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.value.html"
title='fn sysctl::value'>value</a></td>
<td class='docblock-short'>
<p>Takes the name of the OID as argument and returns
a result containing the sysctl value if success,
or a SysctlError on failure</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.value_as.html"
title='fn sysctl::value_as'>value_as</a></td>
<td class='docblock-short'>
<p>A generic function that takes a string as argument and
returns a result containing the sysctl value if success,
or a SysctlError on failure.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.value_oid.html"
title='fn sysctl::value_oid'>value_oid</a></td>
<td class='docblock-short'>
<p>Takes an OID as argument and returns a result
containing the sysctl value if success, or a SysctlError
on failure</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="fn" href="fn.value_oid_as.html"
title='fn sysctl::value_oid_as'>value_oid_as</a></td>
<td class='docblock-short'>
<p>A generic function that takes an OID as argument and
returns a result containing the sysctl value if success,
or a SysctlError on failure</p>
</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 = "sysctl";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>