1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
8 This file is part of systemd.
10 Copyright 2012 Lennart Poettering
13 <refentry id=
"sd-id128"
14 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
17 <title>sd-id128
</title>
18 <productname>systemd
</productname>
22 <contrib>Developer
</contrib>
23 <firstname>Lennart
</firstname>
24 <surname>Poettering
</surname>
25 <email>lennart@poettering.net
</email>
31 <refentrytitle>sd-id128
</refentrytitle>
32 <manvolnum>3</manvolnum>
36 <refname>sd-id128
</refname>
37 <refname>sd_id128_t
</refname>
38 <refname>SD_ID128_MAKE
</refname>
39 <refname>SD_ID128_MAKE_STR
</refname>
40 <refname>SD_ID128_NULL
</refname>
41 <refname>SD_ID128_CONST_STR
</refname>
42 <refname>SD_ID128_FORMAT_STR
</refname>
43 <refname>SD_ID128_FORMAT_VAL
</refname>
44 <refname>sd_id128_equal
</refname>
45 <refname>sd_id128_is_null
</refname>
46 <refpurpose>APIs for processing
128-bit IDs
</refpurpose>
51 <funcsynopsisinfo>#include
<systemd/sd-id128.h
></funcsynopsisinfo>
55 <command>pkg-config --cflags --libs libsystemd
</command>
61 <title>Description
</title>
63 <para><filename>sd-id128.h
</filename> provides APIs to process and
64 generate
128-bit ID values. The
128-bit ID values processed and
65 generated by these APIs are a generalization of OSF UUIDs as
66 defined by
<ulink url=
"https://tools.ietf.org/html/rfc4122">RFC
67 4122</ulink> but use a simpler string format. These functions
68 impose no structure on the used IDs, much unlike OSF UUIDs or
69 Microsoft GUIDs, but are fully compatible with those types of IDs.
73 <citerefentry><refentrytitle>sd_id128_to_string
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
74 <citerefentry><refentrytitle>sd_id128_randomize
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
76 <citerefentry><refentrytitle>sd_id128_get_machine
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
77 for more information about the implemented functions.
</para>
79 <para>A
128-bit ID is implemented as the following
82 <programlisting>typedef union sd_id128 {
85 } sd_id128_t;
</programlisting>
87 <para>This union type allows accessing the
128-bit ID as
16
88 separate bytes or two
64-bit words. It is generally safer to
89 access the ID components by their
8-bit array to avoid endianness
90 issues. This union is intended to be passed call-by-value (as
91 opposed to call-by-reference) and may be directly manipulated by
94 <para>A couple of macros are defined to denote and decode
128-bit
97 <para><function>SD_ID128_MAKE()
</function> may be used to denote a
98 constant
128-bit ID in source code. A commonly used idiom is to
99 assign a name to a
128-bit ID using this macro:
</para>
101 <programlisting>#define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,
2e,
22,bc,
6e,e6,
47,b6,b9,
07,
29,ab,
34,a2,
50,b1)
</programlisting>
103 <para><function>SD_ID128_NULL
</function> may be used to refer to the
128bit ID consisting of only NUL
106 <para><function>SD_ID128_MAKE_STR()
</function> is similar to
<function>SD_ID128_MAKE()
</function>, but creates a
107 <type>const char*
</type> expression that can be conveniently used in message formats and such:
</para>
109 <programlisting>#include
<stdio.h
>
110 #define SD_MESSAGE_COREDUMP_STR SD_ID128_MAKE_STR(fc,
2e,
22,bc,
6e,e6,
47,b6,b9,
07,
29,ab,
34,a2,
50,b1)
112 int main(int argc, char **argv) {
113 puts(
"Match for coredumps: MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR);
117 <para><function>SD_ID128_CONST_STR()
</function> may be used to
118 convert constant
128-bit IDs into constant strings for output. The
119 following example code will output the string
120 "fc2e22bc6ee647b6b90729ab34a250b1":
</para>
121 <programlisting>int main(int argc, char *argv[]) {
122 puts(
"Match for coredumps: %s", SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
125 <para><function>SD_ID128_FORMAT_STR()
</function> and
126 <function>SD_ID128_FORMAT_VAL()
</function> may be used to format a
128 <citerefentry project='man-pages'
><refentrytitle>printf
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
129 format string, as shown in the following example:
</para>
131 <programlisting>int main(int argc, char *argv[]) {
133 id = SD_ID128_MAKE(ee,
89,be,
71,bd,
6e,
43,d6,
91,e6,c5,
5d,eb,
03,
02,
07);
134 printf(
"The ID encoded in this C file is " SD_ID128_FORMAT_STR
".\n", SD_ID128_FORMAT_VAL(id));
138 <para>Use
<function>sd_id128_equal()
</function> to compare two
128-bit IDs:
</para>
140 <programlisting>int main(int argc, char *argv[]) {
142 a = SD_ID128_MAKE(ee,
89,be,
71,bd,
6e,
43,d6,
91,e6,c5,
5d,eb,
03,
02,
07);
143 b = SD_ID128_MAKE(f2,
28,
88,
9c,
5f,
09,
44,
15,
9d,d7,
04,
77,
58,cb,e7,
3e);
145 assert(sd_id128_equal(a, c));
146 assert(!sd_id128_equal(a, b));
150 <para>Use
<function>sd_id128_is_null()
</function> to check if an
128bit ID consists of only NUL bytes:
</para>
152 <programlisting>int main(int argc, char *argv[]) {
153 assert(sd_id128_is_null(SD_ID128_NULL));
156 <para>Note that new, randomized IDs may be generated with
157 <citerefentry><refentrytitle>journalctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s
158 <option>--new-id128
</option> option.
</para>
161 <xi:include href=
"libsystemd-pkgconfig.xml" />
164 <title>See Also
</title>
166 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
167 <citerefentry><refentrytitle>sd_id128_to_string
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
168 <citerefentry><refentrytitle>sd_id128_randomize
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
169 <citerefentry><refentrytitle>sd_id128_get_machine
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
170 <citerefentry project='man-pages'
><refentrytitle>printf
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
171 <citerefentry><refentrytitle>journalctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
172 <citerefentry><refentrytitle>sd-journal
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
173 <citerefentry project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
174 <citerefentry><refentrytitle>machine-id
</refentrytitle><manvolnum>5</manvolnum></citerefentry>