|
|
@@ -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 |