1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="sd_machine_get_class" xmlns:xi="http://www.w3.org/2001/XInclude">
9 <title>sd_machine_get_class</title>
10 <productname>systemd</productname>
14 <refentrytitle>sd_machine_get_class</refentrytitle>
15 <manvolnum>3</manvolnum>
19 <refname>sd_machine_get_class</refname>
20 <refname>sd_machine_get_ifindices</refname>
21 <refpurpose>Determine the class and network interface indices of a
22 locally running virtual machine or container</refpurpose>
27 <funcsynopsisinfo>#include <systemd/sd-login.h></funcsynopsisinfo>
30 <funcdef>int <function>sd_machine_get_class</function></funcdef>
31 <paramdef>const char* <parameter>machine</parameter></paramdef>
32 <paramdef>char **<parameter>class</parameter></paramdef>
36 <funcdef>int <function>sd_machine_get_ifindices</function></funcdef>
37 <paramdef>const char* <parameter>machine</parameter></paramdef>
38 <paramdef>int **<parameter>ret_ifindices</parameter></paramdef>
44 <title>Description</title>
46 <para><function>sd_machine_get_class()</function> may be used to
47 determine the class of a locally running virtual machine or
48 container that is registered with
49 <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
50 The string returned is either <literal>vm</literal> or
51 <literal>container</literal>. The returned string needs to be
52 freed with the libc <citerefentry
53 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
54 call after use.</para>
56 <para><function>sd_machine_get_ifindices()</function> may be used to determine the numeric indices of the
57 network interfaces on the host that are pointing towards the specified locally running virtual machine or
58 container. The vm or container must be registered with
59 <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
60 The output parameter <parameter>ret_ifindices</parameter> may be passed as <constant>NULL</constant> when
61 the output value is not needed. The returned array needs to be freed with the libc <citerefentry
62 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry> call after
67 <title>Return Value</title>
69 <para>On success, these functions return a non-negative integer.
70 <function>sd_machine_get_ifindices()</function> returns the number of the relevant network interfaces.
71 On failure, these calls return a negative errno-style error code.</para>
76 <para>Returned errors may indicate the following problems:</para>
81 <term><constant>-ENXIO</constant></term>
83 <listitem><para>The specified machine does not exist or is currently not running.</para>
88 <term><constant>-EINVAL</constant></term>
90 <listitem><para>An input parameter was invalid (out of range, or <constant>NULL</constant>, where
91 that is not accepted).</para></listitem>
95 <term><constant>-ENOMEM</constant></term>
97 <listitem><para>Memory allocation failed.</para></listitem>
103 <xi:include href="libsystemd-pkgconfig.xml" />
106 <title>History</title>
107 <para><function>sd_machine_get_class()</function> and
108 <function>sd_machine_get_ifindices()</function> were added in version 217.</para>
112 <title>See Also</title>
115 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
116 <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
117 <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
118 <citerefentry><refentrytitle>sd_pid_get_machine_name</refentrytitle><manvolnum>3</manvolnum></citerefentry>