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

NAME

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

SYNOPSIS

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

DESCRIPTION

16       sd-id128.h provides APIs to process and generate 128-bit ID values. The
17       128-bit ID values processed and generated by these APIs are a
18       generalization of OSF UUIDs as defined by RFC 4122[1] but use a simpler
19       string format. These functions impose no structure on the used IDs,
20       much unlike OSF UUIDs or Microsoft GUIDs, but are fully compatible with
21       those types of IDs.
22
23       See sd_id128_to_string(3), sd_id128_randomize(3) and
24       sd_id128_get_machine(3) for more information about the implemented
25       functions.
26
27       A 128-bit ID is implemented as the following union type:
28
29           typedef union sd_id128 {
30             uint8_t bytes[16];
31             uint64_t qwords[2];
32           } sd_id128_t;
33
34       This union type allows accessing the 128-bit ID as 16 separate bytes or
35       two 64-bit words. It is generally safer to access the ID components by
36       their 8-bit array to avoid endianness issues. This union is intended to
37       be passed call-by-value (as opposed to call-by-reference) and may be
38       directly manipulated by clients.
39
40       A couple of macros are defined to denote and decode 128-bit IDs:
41
42       SD_ID128_MAKE() may be used to denote a constant 128-bit ID in source
43       code. A commonly used idiom is to assign a name to a 128-bit ID using
44       this macro:
45
46           #define SD_MESSAGE_COREDUMP SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)
47
48       SD_ID128_CONST_STR() may be used to convert constant 128-bit IDs into
49       constant strings for output. The following example code will output the
50       string "fc2e22bc6ee647b6b90729ab34a250b1":
51
52           int main(int argc, char *argv[]) {
53             puts(SD_ID128_CONST_STR(SD_MESSAGE_COREDUMP));
54           }
55
56       SD_ID128_FORMAT_STR and SD_ID128_FORMAT_VAL() may be used to format a
57       128-bit ID in a printf(3) format string, as shown in the following
58       example:
59
60           int main(int argc, char *argv[]) {
61             sd_id128_t id;
62             id = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
63             printf("The ID encoded in this C file is " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(id));
64             return 0;
65           }
66
67       Use sd_id128_equal() to compare two 128-bit IDs:
68
69           int main(int argc, char *argv[]) {
70             sd_id128_t a, b, c;
71             a = SD_ID128_MAKE(ee,89,be,71,bd,6e,43,d6,91,e6,c5,5d,eb,03,02,07);
72             b = SD_ID128_MAKE(f2,28,88,9c,5f,09,44,15,9d,d7,04,77,58,cb,e7,3e);
73             c = a;
74             assert(sd_id128_equal(a, c));
75             assert(!sd_id128_equal(a, b));
76             return 0;
77           }
78
79       Note that new, randomized IDs may be generated with journalctl(1)'s
80       --new-id option.
81

NOTES

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

SEE ALSO

87       systemd(1), sd_id128_to_string(3), sd_id128_randomize(3),
88       sd_id128_get_machine(3), printf(3), journalctl(1), sd-journal(7), pkg-
89       config(1), machine-id(5)
90

NOTES

92        1. RFC 4122
93           https://tools.ietf.org/html/rfc4122
94
95
96
97systemd 219                                                        SD-ID128(3)
Impressum