/*
- * Copyright (c) 2004-2010 Apple Inc. All rights reserved.
+ * Copyright (c) 2004-2011 Apple Inc. All rights reserved.
*
* %Begin-Header%
* Redistribution and use in source and binary forms, with or without
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
#include <sys/systm.h>
#include <sys/time.h>
-#include <net/if.h>
-#include <net/if_dl.h>
-#include <net/if_types.h>
-
-UUID_DEFINE(UUID_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+extern int uuid_get_ethernet(u_int8_t *);
static void
read_node(uint8_t *node)
{
#if NETWORKING
- struct ifnet *ifp;
- struct sockaddr_dl *sdl;
-
- ifnet_head_lock_shared();
- TAILQ_FOREACH(ifp, &ifnet_head, if_link) {
- ifnet_lock_shared(ifp);
- IFA_LOCK_SPIN(ifp->if_lladdr);
- sdl = (struct sockaddr_dl *)ifp->if_lladdr->ifa_addr;
- if (sdl->sdl_type == IFT_ETHER) {
- memcpy(node, LLADDR(sdl), 6);
- IFA_UNLOCK(ifp->if_lladdr);
- ifnet_lock_done(ifp);
- ifnet_head_done();
- return;
- }
- IFA_UNLOCK(ifp->if_lladdr);
- ifnet_lock_done(ifp);
+ if (uuid_get_ethernet(node) == 0) {
+ return;
}
- ifnet_head_done();
#endif /* NETWORKING */
read_random(node, 6);
memcpy(dst, src, sizeof(uuid_t));
}
+static void
+uuid_random_setflags(uuid_t out)
+{
+ out[6] = (out[6] & 0x0F) | 0x40;
+ out[8] = (out[8] & 0x3F) | 0x80;
+}
+
void
uuid_generate_random(uuid_t out)
{
read_random(out, sizeof(uuid_t));
+ uuid_random_setflags(out);
+}
- out[6] = (out[6] & 0x0F) | 0x40;
- out[8] = (out[8] & 0x3F) | 0x80;
+void
+uuid_generate_early_random(uuid_t out)
+{
+ read_frandom(out, sizeof(uuid_t));
+ uuid_random_setflags(out);
}
void
out[5] = (uint8_t)(time >> 32);
out[6] = (uint8_t)(time >> 56);
out[7] = (uint8_t)(time >> 48);
-
+
out[6] = (out[6] & 0x0F) | 0x10;
out[8] = (out[8] & 0x3F) | 0x80;
}
int n = 0;
sscanf(in,
- "%2hhx%2hhx%2hhx%2hhx-"
- "%2hhx%2hhx-"
- "%2hhx%2hhx-"
- "%2hhx%2hhx-"
- "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%n",
- &uu[0], &uu[1], &uu[2], &uu[3],
- &uu[4], &uu[5],
- &uu[6], &uu[7],
- &uu[8], &uu[9],
- &uu[10], &uu[11], &uu[12], &uu[13], &uu[14], &uu[15], &n);
-
- return (n != 36 || in[n] != '\0' ? -1 : 0);
+ "%2hhx%2hhx%2hhx%2hhx-"
+ "%2hhx%2hhx-"
+ "%2hhx%2hhx-"
+ "%2hhx%2hhx-"
+ "%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%n",
+ &uu[0], &uu[1], &uu[2], &uu[3],
+ &uu[4], &uu[5],
+ &uu[6], &uu[7],
+ &uu[8], &uu[9],
+ &uu[10], &uu[11], &uu[12], &uu[13], &uu[14], &uu[15], &n);
+
+ return n != 36 || in[n] != '\0' ? -1 : 0;
}
void
uuid_unparse_lower(const uuid_t uu, uuid_string_t out)
{
snprintf(out,
- sizeof(uuid_string_t),
- "%02x%02x%02x%02x-"
- "%02x%02x-"
- "%02x%02x-"
- "%02x%02x-"
- "%02x%02x%02x%02x%02x%02x",
- uu[0], uu[1], uu[2], uu[3],
- uu[4], uu[5],
- uu[6], uu[7],
- uu[8], uu[9],
- uu[10], uu[11], uu[12], uu[13], uu[14], uu[15]);
+ sizeof(uuid_string_t),
+ "%02x%02x%02x%02x-"
+ "%02x%02x-"
+ "%02x%02x-"
+ "%02x%02x-"
+ "%02x%02x%02x%02x%02x%02x",
+ uu[0], uu[1], uu[2], uu[3],
+ uu[4], uu[5],
+ uu[6], uu[7],
+ uu[8], uu[9],
+ uu[10], uu[11], uu[12], uu[13], uu[14], uu[15]);
}
void
uuid_unparse_upper(const uuid_t uu, uuid_string_t out)
{
snprintf(out,
- sizeof(uuid_string_t),
- "%02X%02X%02X%02X-"
- "%02X%02X-"
- "%02X%02X-"
- "%02X%02X-"
- "%02X%02X%02X%02X%02X%02X",
- uu[0], uu[1], uu[2], uu[3],
- uu[4], uu[5],
- uu[6], uu[7],
- uu[8], uu[9],
- uu[10], uu[11], uu[12], uu[13], uu[14], uu[15]);
+ sizeof(uuid_string_t),
+ "%02X%02X%02X%02X-"
+ "%02X%02X-"
+ "%02X%02X-"
+ "%02X%02X-"
+ "%02X%02X%02X%02X%02X%02X",
+ uu[0], uu[1], uu[2], uu[3],
+ uu[4], uu[5],
+ uu[6], uu[7],
+ uu[8], uu[9],
+ uu[10], uu[11], uu[12], uu[13], uu[14], uu[15]);
}
void