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