[vbox-dev] UUID's

Dmitry A. Kuminov dmik at sun.com
Wed Aug 13 16:29:48 GMT 2008


Hi James,

James Lucas wrote:

> void uuid_unpack(const uuid_t in, struct uuid *uu)
> {
>         const uint8_t   *ptr = in;
>         uint32_t                tmp;
> 
>         tmp = *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         uu->time_low = tmp;
> 
>         tmp = *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         uu->time_mid = tmp;
> 
>         tmp = *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         uu->time_hi_and_version = tmp;
> 
>         tmp = *ptr++;
>         tmp = (tmp << 8) | *ptr++;
>         uu->clock_seq = tmp;
> 
>         memcpy(uu->node, ptr, 6);
> }

As you can see, uuid_unpack() always assumes that the most significant 
bytes come first in memory, i.e. it uses the so called network byte 
order according to RFC4211 (http://www.ietf.org/rfc/rfc4122.txt).

However, Microsoft seems to use the platform endiness (which is little 
endian for x86 and amd64 platforms) when it comes to converting binary 
UUID representations to strings and vice versa. Little endian means that 
least significant bytes come first. Due to the reasons of compatibility 
with Windows where UUID (GUID) is widely used by the system itself we 
have chosen the Microsoft way of interpreting the binary UUID 
representation and here is the difference between RTUuidToStr() and 
uuid_unpack()/uuid_unparse() and their counterparts that parse the 
string and pack it to UUID.

A possible solution here is to link to te VBoxRT.so (VBoxRT.dll) library 
shipped with every VirtualBox version and use RTUuidToStr() and 
RTUuidFromStr() from that library.

-- 
Regards,
Dmitry A. Kuminov





More information about the vbox-dev mailing list