From ab539f5ef74761d0c90878a8efb5bed07d98de33 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 15 Aug 2022 16:05:09 -0700 Subject: [PATCH] forgot to add this w/ a previous commit.. --- ui/medashare/hostid.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ui/medashare/hostid.py diff --git a/ui/medashare/hostid.py b/ui/medashare/hostid.py new file mode 100644 index 0000000..3806dd8 --- /dev/null +++ b/ui/medashare/hostid.py @@ -0,0 +1,38 @@ +import uuid + +from ctypes import CDLL, Structure, POINTER +from ctypes import c_uint8, c_int, c_long, c_int64 + +uuid_t = c_uint8 * 16 + +_clib = CDLL(None) + +__all__ = [ 'hostuuid'] + +class timespec(Structure): + _fields_ = [ + ('tv_sec', c_int64), + ('tv_nsec', c_long), + ] + pass + +timespec_p = POINTER(timespec) + +def hostuuid(): + ts = timespec() + hid = uuid_t() + + r = _clib.gethostuuid(hid, ts) + + if r: + raise OSErrorException() + + return uuid.UUID(bytes=bytes(hid)) + +for r, f, a in ( + (c_int, 'gethostuuid', (uuid_t, timespec_p)), + ): + fun = getattr(_clib, f) + setattr(fun, 'restype', r) + setattr(fun, 'argtypes', a) + locals()[f] = fun