136#define getpid() _getpid()
137#define srandom(seed) srand(seed)
138#define random() rand()
141#include <sys/socket.h>
143#if defined(R__LINUX) && !defined(R__WINGCC)
144#include <sys/sysinfo.h>
147#include <netinet/in.h>
168 assert(&
fNode[5] -
reinterpret_cast<unsigned char *
>(&
fTimeLow) + 1 == 16);
189 uuid_time_t *time_last_ptr = TTHREAD_TLS_PTR(time_last);
199 using namespace std::chrono;
200 system_clock::time_point today = system_clock::now();
201 seed = (
UInt_t)(system_clock::to_time_t ( today )) + ::getpid();
205 clockseq = 1+(
UShort_t)(65536*random()/(RAND_MAX+1.0));
215 if (
CmpTime(×tamp, time_last_ptr) == -1) {
216 clockseq = (clockseq + 1) & 0x3FFF;
217 if (clockseq == 0) clockseq++;
220 Format(clockseq, timestamp);
222 time_last = timestamp;
239 if (
t1->high < t2->
high)
return -1;
240 if (
t1->high > t2->
high)
return 1;
241 if (
t1->low < t2->
low)
return -1;
242 if (
t1->low > t2->
low)
return 1;
255 int timeHiAndVersion;
256 int clockSeqHiAndRes;
260 sscanf(uuid,
"%8lx-%4x-%4x-%2x%2x-%2x%2x%2x%2x%2x%2x",
266 &node[0], &node[1], &node[2], &node[3], &node[4], &node[5]);
298 Error(
"TUUID",
"null string not allowed");
309 tobuf(buffer, version);
315 for (
Int_t i = 0; i < 6; i++)
331 for (
Int_t i = 0; i < 6; i++)
347 for (
UInt_t i = 0; i < 6; i++) {
374 const UShort_t uuids_per_tick = 1024;
377 TTHREAD_TLS(
UShort_t) uuids_this_tick(0);
380 uuid_time_t *time_last_ptr = TTHREAD_TLS_PTR(time_last);
384 uuids_this_tick = uuids_per_tick;
394 if (
CmpTime(time_last_ptr, &time_now)) {
399 if (uuids_this_tick < uuids_per_tick) {
406 time_last = time_now;
408 if (uuids_this_tick != 0) {
409 if (time_now.
low & 0x80000000) {
410 time_now.
low += uuids_this_tick;
411 if (!(time_now.
low & 0x80000000))
414 time_now.
low += uuids_this_tick;
418 timestamp->
low = time_now.
low;
428 GetSystemTimeAsFileTime((FILETIME *)&time);
434 (
unsigned __int64) (1000*1000*10)
435 * (
unsigned __int64) (60 * 60 * 24)
436 * (
unsigned __int64) (17+30+31+365*18+5);
438 timestamp->
high = time.HighPart;
439 timestamp->
low = time.LowPart;
442 gettimeofday(&tp,
nullptr);
447 0x01B21DD213814000LL;
449 timestamp->
low = (
UInt_t) (uuid_time & 0xFFFFFFFF);
466 struct ifaddrs *ifAddrStruct =
nullptr;
467 struct ifaddrs *ifa =
nullptr;
469 if (getifaddrs(&ifAddrStruct) != 0) {
472 for (ifa = ifAddrStruct; ifa !=
nullptr; ifa = ifa->ifa_next) {
473 if (!ifa->ifa_addr) {
476 if (ifa->ifa_addr->sa_family != AF_INET) {
479 if (strncmp(ifa->ifa_name,
"lo",2) == 0) {
482 addr = ntohl(((
struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr);
487 if (ifAddrStruct !=
nullptr)
488 freeifaddrs(ifAddrStruct);
501 PIP_ADAPTER_INFO ainfo = (PIP_ADAPTER_INFO)
malloc(
sizeof(IP_ADAPTER_INFO));
502 ULONG buflen =
sizeof(IP_ADAPTER_INFO);
503 DWORD stat = GetAdaptersInfo(ainfo, &buflen);
504 if (stat == ERROR_BUFFER_OVERFLOW) {
506 ainfo = (PIP_ADAPTER_INFO)
malloc(buflen);
507 stat = GetAdaptersInfo(ainfo, &buflen);
509 if (stat != ERROR_SUCCESS)
513 PIP_ADAPTER_INFO adapter = ainfo;
515 sscanf(adapter->IpAddressList.IpAddress.String,
"%d.%d.%d.%d",
517 adr = (
a << 24) | (
b << 16) | (
c << 8) |
d;
523 memcpy(
fNode, &adr, 4);
552 char hostname[MAX_COMPUTERNAME_LENGTH + 1];
555 memset(&
r, 0,
sizeof(
r));
558 GlobalMemoryStatus(&
r.m);
562 GetSystemTimeAsFileTime(&
r.t);
564 QueryPerformanceCounter(&
r.pc);
566 r.tc = GetTickCount();
567 r.l = MAX_COMPUTERNAME_LENGTH + 1;
568 GetComputerName(
r.hostname, &
r.l);
571#if defined(R__LINUX) && !defined(R__WINGCC)
578 memset(&
r, 0,
sizeof(
r));
580#if defined(R__LINUX) && !defined(R__WINGCC)
583 gettimeofday(&
r.t,
nullptr);
584 gethostname(
r.hostname, 256);
604 TTHREAD_TLS(
char) uuid[40];
606 snprintf(uuid,40,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
628 c0 += *
c++;
c1 += c0;
629 c0 += *
c++;
c1 += c0;
630 c0 += *
c++;
c1 += c0;
631 c0 += *
c++;
c1 += c0;
633 c0 += *
c++;
c1 += c0;
634 c0 += *
c++;
c1 += c0;
635 c0 += *
c++;
c1 += c0;
636 c0 += *
c++;
c1 += c0;
638 c0 += *
c++;
c1 += c0;
639 c0 += *
c++;
c1 += c0;
640 c0 += *
c++;
c1 += c0;
641 c0 += *
c++;
c1 += c0;
643 c0 += *
c++;
c1 += c0;
644 c0 += *
c++;
c1 += c0;
645 c0 += *
c++;
c1 += c0;
646 c0 += *
c++;
c1 += c0;
669#define CHECK(f1, f2) if (f1 != f2) return f1 < f2 ? -1 : 1;
675 for (
int i = 0; i < 6; i++) {
692 memcpy(&addr,
fNode, 4);
715 uuid_time -= 0x01B21DD213814000LL;
716 uuid_time /= 10000000LL;
738 Error(
"SetUUID",
"null string not allowed");
void frombuf(char *&buf, Bool_t *x)
void tobuf(char *&buf, Bool_t x)
void Streamer(TBuffer &) override
unsigned short UShort_t
Unsigned Short integer 2 bytes (unsigned short).
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
short Short_t
Signed Short integer 2 bytes (short).
long long Long64_t
Portable signed long integer 8 bytes.
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
externTVirtualMutex * gROOTMutex
TBuffer & operator<<(TBuffer &buf, const TUUID &uuid)
Input operator. Delegate to Streamer.
#define R__LOCKGUARD(mutex)
Buffer base class used for serializing objects.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
void Set()
Set Date/Time to current time as reported by the system.
This class represents an Internet Protocol (IP) address.
This code implements the MD5 message-digest algorithm.
void Update(const UChar_t *buf, UInt_t len)
Update TMD5 object to reflect the concatenation of another buffer full of bytes.
void Final()
MD5 finalization, ends an MD5 message-digest operation, writing the the message digest and zeroizing ...
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
UChar_t fClockSeqHiAndReserved
void GetCurrentTime(uuid_time_t *timestamp)
Get current time as 60 bit 100ns ticks since whenever.
static constexpr Version_t Class_Version()
Int_t CmpTime(uuid_time_t *t1, uuid_time_t *t2)
Compare two time values.
void GetSystemTime(uuid_time_t *timestamp)
Get system time with 100ns precision. Time is since Oct 15, 1582.
virtual ~TUUID()
delete this TUUID
void ReadBuffer(char *&buffer)
Stream UUID from input buffer.
static TUUID UUIDv4()
Create a UUID version 4 (variant 1) UUID according to RFC 4122.
void SetFromString(const char *uuid_str)
Set this UUID to the value specified in uuid ((which must be in TUUID::AsString() format).
void Format(UShort_t clockseq, uuid_time_t ts)
Make a UUID from timestamp, clockseq and node id.
TDatime GetTime() const
Get time from UUID.
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
void GetUUID(UChar_t uuid[16]) const
Return uuid in specified buffer (16 byte = 128 bits).
TInetAddress GetHostAddress() const
Get address of host encoded in UUID.
void SetUUID(const char *uuid_str)
Set this UUID to the value specified in uuid ((which must be in TUUID::AsString() format).
UShort_t Hash() const
Compute 16-bit hash value of the UUID.
UShort_t fTimeHiAndVersion
UInt_t fUUIDIndex
!index in the list of UUIDs in TProcessUUID
void GetRandomInfo(UChar_t seed[16])
Get random info based on some machine parameters.
void Print() const
Print UUID.
Int_t Compare(const TUUID &u) const
Compare two UUIDs "lexically" and return.
TUUID(TV4Marker)
Create a version 4 UUID.
void FillBuffer(char *&buffer)
Stream UUID into output buffer.
void GetNodeIdentifier()
Get node identifier.
void StreamerV1(TBuffer &b)
Stream UUID from input buffer.
bool GetCryptoRandom(void *buf, unsigned int len)
Get random bytes from the operating system's cryptographic random number generator The requested numb...