1 /* $NetBSD: uuid.c,v 1.4 2009/06/23 05:11:47 agc Exp $ */
4 * Copyright © 2006 Alistair Crooks. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior written
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifdef HAVE_INTTYPES_H
36 #include <sys/types.h>
38 #ifdef HAVE_SYS_PARAM_H
39 #include <sys/param.h>
42 #ifdef HAVE_SYS_TIME_H
55 /* just fill the struct with random values for now */
57 nbuuid_create(nbuuid_t
*uuid
, uint32_t *status
)
63 ether
= ((uint64_t)random() << 32) | random();
64 uuid
->time_low
= (int)t
;
65 uuid
->time_mid
= (uint16_t)(random() & 0xffff);
66 uuid
->time_hi_and_version
= (uint16_t)(random() & 0xffff);
67 uuid
->clock_seq_low
= (uint8_t)(random() & 0xff);
68 uuid
->clock_seq_hi_and_reserved
= (uint8_t)(random() & 0xff);
69 (void) memcpy(&uuid
->node
, ðer
, sizeof(uuid
->node
));
73 /* convert the struct to a printable string */
75 nbuuid_to_string(nbuuid_t
*uuid
, char **str
, uint32_t *status
)
79 (void) snprintf(s
, sizeof(s
), "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
82 uuid
->time_hi_and_version
,
83 uuid
->clock_seq_hi_and_reserved
,