1SD-ID128(3)                        sd-id128                        SD-ID128(3)
2
3
4

NAME

6       sd-id128, sd_id128_t, SD_ID128_MAKE, SD_ID128_MAKE_STR, SD_ID128_NULL,
7       SD_ID128_CONST_STR, SD_ID128_FORMAT_STR, SD_ID128_UUID_FORMAT_STR,
8       SD_ID128_FORMAT_VAL, sd_id128_equal, sd_id128_is_null - APIs for
9       processing 128-bit IDs
10

SYNOPSIS

12       #include <systemd/sd-id128.h>
13
14       pkg-config --cflags --libs libsystemd
15

DESCRIPTION

17       sd-id128.h provides APIs to process and generate 128-bit ID values. The
18       128-bit ID values processed and generated by these APIs are a
19       generalization of OSF UUIDs as defined by RFC 4122[1] but use a simpler
20       string format. These functions impose no structure on the used IDs,
21       much unlike OSF UUIDs or Microsoft GUIDs, but are fully compatible with
22       those types of IDs.
23
24       See sd_id128_to_string(3), sd_id128_randomize(3) and
25       sd_id128_get_machine(3) for more information about the implemented
26       functions.
27
28       A 128-bit ID is implemented as the following union type:
29
30           typedef union sd_id128 {
31                   uint8_t bytes[16];
32                   uint64_t qwords[2];
33           } sd_id128_t;
34
35       This union type allows accessing the 128-bit ID as 16 separate bytes or
36       two 64-bit words. It is generally safer to access the ID components by
37       their 8-bit array to avoid endianness issues. This union is intended to
38       be passed call-by-value (as opposed to call-by-reference) and may be
39       directly manipulated by clients.
40
41       A couple of macros are defined to denote and decode 128-bit IDs:
42
43       SD_ID128_MAKE() may be used to denote a constant 128-bit ID in source
44       code. A commonly used idiom is to assign a name to a 128-bit ID using
45       this macro:
46
47           #define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)
48
49       SD_ID128_NULL may be used to refer to the 128bit ID consisting of only
50       NUL bytes.
51
52       SD_ID128_MAKE_STR() is similar to SD_ID128_MAKE(), but creates a const
53       char* expression that can be conveniently used in message formats and
54       such:
55
56           #include <stdio.h>
57           #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)
58
59           int main(int argc, char **argv) {
60                   puts("Match for coredumps: MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR);
61           }
62
63
64       SD_ID128_CONST_STR() may be used to convert constant 128-bit IDs into
65       constant strings for output. The following example code will output the
66       string "fc2e22bc6ee647b6b90729ab34a250b1":
67
68           int main(int argc, char *argv[]) {
69                   puts("Match for coredumps: %s", SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
70           }
71
72       SD_ID128_FORMAT_STR() and SD_ID128_FORMAT_VAL() may be used to format a
73       128-bit ID in a printf(3) format string, as shown in the following
74       example:
75
76           int main(int argc, char *argv[]) {
77                   sd_id128_t id;
78                   id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
79                   printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id));
80                   return 0;
81           }
82
83       SD_ID128_UUID_FORMAT_STR() is similar to SD_ID128_FORMAT_STR() but
84       includes separating hyphens to conform to the "canonical
85       representation[2]".
86
87       Use sd_id128_equal() to compare two 128-bit IDs:
88
89           int main(int argc, char *argv[]) {
90                   sd_id128_t a, b, c;
91                   a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
92                   b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e);
93                   c = a;
94                   assert(sd_id128_equal(a, c));
95                   assert(!sd_id128_equal(a, b));
96                   return 0;
97           }
98
99       Use sd_id128_is_null() to check if an 128bit ID consists of only NUL
100       bytes:
101
102           int main(int argc, char *argv[]) {
103                   assert(sd_id128_is_null(SD_ID128_NULL));
104           }
105
106       Note that new, randomized IDs may be generated with systemd-id128(1)'s
107       new command.
108

NOTES

110       These APIs are implemented as a shared library, which can be compiled
111       and linked to with the libsystemd pkg-config(1) file.
112

SEE ALSO

114       systemd(1), sd_id128_to_string(3), sd_id128_randomize(3),
115       sd_id128_get_machine(3), printf(3), journalctl(1), sd-journal(7), pkg-
116       config(1), machine-id(5)
117

NOTES

119        1. RFC 4122
120           https://tools.ietf.org/html/rfc4122
121
122        2. canonical representation
123           https://en.wikipedia.org/wiki/Universally_unique_identifier#Format
124
125
126
127systemd 243                                                        SD-ID128(3)
Impressum