10 printf("uuidgen [-rthV]\n");
12 void print_version() {
13 printf("uuidgen version 1.0\n");
16 int main(int ac, char *av[]) {
17 pd_uuid_t u; /* generated uuid */
18 pd_uuid_t nsuuid; /* namespace uuid */
19 pd_uuid_t *nsid = 0; /* pointer to namespace uuid */
20 char *ns = 0; /* literal ns id string */
22 struct pd_uuid_state s;
23 char uuid[PD_UUID_STRLEN+1];
35 * T = time with random mac
49 while ((opt = getopt(ac, av, "Vhq:tTrmsv:n:DUOX")) != -1) {
53 if (mode != 3 && mode != 5) mode = 5;
56 nsid = &pd_uuid_ns_dns;
59 nsid = &pd_uuid_ns_url;
62 nsid = &pd_uuid_ns_oid;
65 nsid = &pd_uuid_ns_x500;
97 warn("uuidgen: unknown option '%c'", opt);
103 pd_uuid_init_state(&s);
105 if (mode == 3 || mode == 5) {
106 /* TODO warn if q != 1 */
110 die("must specify namespace for version %d uuids", mode);
112 if (!strcmp(ns, "dns")) {
113 nsid = &pd_uuid_ns_dns;
114 } else if (!strcmp(ns, "url")) {
115 nsid = &pd_uuid_ns_url;
116 } else if (!strcmp(ns, "oid")) {
117 nsid = &pd_uuid_ns_oid;
118 } else if (!strcmp(ns, "x500")) {
119 nsid = &pd_uuid_ns_x500;
122 if (pd_uuid_set_string(nsid, ns) != 0) {
123 die("malformed ns uuid: %s\n", ns);
127 for (i = optind; i < ac; i++) {
130 pd_uuid_get_string(nsid, uuid);
131 pd_uuid_make_v3(0, &u, nsid, av[i], len);
133 pd_uuid_make_v5(&s, &u, nsid, av[i], len);
135 pd_uuid_get_string(&u, uuid);
136 printf("%s\n", uuid);
144 pd_uuid_make_v1mc(&s, &u);
147 pd_uuid_make_v1(&s, &u);
150 pd_uuid_make_v4(&s, &u);
153 die("uuidgen: unknown uuid version '%d'\n", mode);
155 pd_uuid_get_string(&u, uuid);
156 printf("%s\n", uuid);