🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.pascal
Article #92397

Re: 16-bitowy generator GUID

#92397
From: Łukasz 'Maly' Ostrowski
Date: Sun, 06 Jan 2008 15:54
96 lines
3561 bytes
Magda S wrote:
> No i z aplikacją DOSową jest pod tym względem problem. Czy znacie
> jakieś namiary na 16-bitowe generatory GUID-ów wg tej samej zasady co
> w Win32? Albo przynajmniej 16-bajtowe (lub dłuższe?) GUID-y wg
> jakiejkolwiek zasady?


Z Win32 źródeł podać nie mogę bo mnie m$ będzie ścigał ;),
ale za to ReactOS ma własną implementację:

RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
{
    static int initialised, count;

    ULONGLONG time;
    static ULONGLONG timelast;
    static WORD sequence;

    static DWORD status;
    static BYTE address[MAX_ADAPTER_ADDRESS_LENGTH];

    EnterCriticalSection(&uuid_cs);

    if (!initialised) {
        RPC_UuidGetSystemTime(&timelast);
        count = TICKS_PER_CLOCK_TICK;

        sequence = ((rand() & 0xff) << 8) + (rand() & 0xff);
        sequence &= 0x1fff;

        status = RPC_UuidGetNodeAddress(address);
        initialised = 1;
    }

    /* Generate time element of the UUID. Account for going faster
       than our clock as well as the clock going backwards. */
    while (1) {
        RPC_UuidGetSystemTime(&time);
        if (time > timelast) {
            count = 0;
            break;
        }
        if (time < timelast) {
            sequence = (sequence + 1) & 0x1fff;
            count = 0;
            break;
        }
        if (count < TICKS_PER_CLOCK_TICK) {
            count++;
            break;
        }
    }

    timelast = time;
    time += count;

    /* Pack the information into the UUID structure. */

    Uuid->Data1  = (unsigned long)(time & 0xffffffff);
    Uuid->Data2  = (unsigned short)((time >> 32) & 0xffff);
    Uuid->Data3  = (unsigned short)((time >> 48) & 0x0fff);

    /* This is a version 1 UUID */
    Uuid->Data3 |= (1 << 12);

    Uuid->Data4[0]  = sequence & 0xff;
    Uuid->Data4[1]  = (sequence & 0x3f00) >> 8;
    Uuid->Data4[1] |= 0x80;

    Uuid->Data4[2] = address[0];
    Uuid->Data4[3] = address[1];
    Uuid->Data4[4] = address[2];
    Uuid->Data4[5] = address[3];
    Uuid->Data4[6] = address[4];
    Uuid->Data4[7] = address[5];

    LeaveCriticalSection(&uuid_cs);

    TRACE("%s\n", debugstr_guid(Uuid));

    return status;
}

Mówiąc wprost, MAC address + aktualny czas + numer sekwencyjny,
Win32 dorzuca jeszcze chyba jakiś random num, ale z racji że
jest on zależny od czasu, tutaj go nie ma ;-).

Kod jest 32-bitowy, ale jak się uprzeć to nie powinno być
problemu żeby zrobić porta 16-bit.

P.S. CoCreateGuid() jest proxy do UuidCreate() z modułu RPC.

-- 
Pozdrawiam,
Łukasz 'Maly' Ostrowski.
http://maly.nemo.pl/ 
Technical Details
Message-ID: <flqtok$vlb$1@news.dialog.net.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.dialog.net.pl!not-for-mail
References: <flqqq8$6gq$2@news.onet.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.dialog.net.pl!not-for-mail
From: Łukasz 'Maly' Ostrowski <maly@USUNnemo.pl>
Newsgroups: pl.comp.lang.pascal
Subject: Re: 16-bitowy generator GUID
Date: Sun, 6 Jan 2008 16:54:04 +0100
Organization: Dialog Net
Lines: 97
Message-ID: <flqtok$vlb$1@news.dialog.net.pl>
References: <flqqq8$6gq$2@news.onet.pl>
NNTP-Posting-Host: xdsl-2911.zgora.dialog.net.pl
Mime-Version: 1.0
X-Trace: news.dialog.net.pl 1199635028 32427 81.168.239.95 (6 Jan 2008 15:57:08 GMT)
X-Complaints-To: abuse@dialog.net.pl
NNTP-Posting-Date: Sun, 6 Jan 2008 15:57:08 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit