+1999-07-03 <tytso@rsts-11.mit.edu>
+
+ * uuidgen.c: Add option parsing so that user can ask for either a
+ time-based UUID or a random-based UUID.
+
1999-07-02 <tytso@rsts-11.mit.edu>
* fsck.c: Added support for LABEL= and UUID= specifications for
.SH NAME
uuidgen \- command\-line utility to create a new UUID value
.SH SYNOPSIS
-.nf
-.B uuidgen
-.fi
+.B uuidgen
+[
+.B -r
+] [
+.B -t
+]
.SH DESCRIPTION
The
.B uuidgen
program creates a new universally unique identifier (UUID) using the
-.BR libuuid "(3) functions " uuid_generate "(3) and " uuid_unparse "(3)."
-The new UUID can reasonably be considered unique among all UUIDs created
-on the local system, and among UUIDs created on other systems in the past
+.BR libuuid (3)
+library. The new UUID can reasonably be considered unique among
+all UUIDs created on the local system,
+and among UUIDs created on other systems in the past
and in the future.
+.PP
+There are two types of UUID's which
+.B uuidgen
+can generate: time-based UUID's and random-based UUID's. By
+default
+.B uuidgen
+will generatea random-based UUID if a high-quality random number
+generator is present. Otherwise, it will chose a time-based UUID. It
+is possible to force the generation of one of these two
+UUID types by using the
+.IR -r " or " -t " options."
+.SH "OPTIONS"
+.TP
+.I -r
+Generate a random-based UUID. This method creates a UUID consisting mostly
+of random bits. It requires that the operating system have a high
+quality random number generator, such as /dev/random.
+.TP
+.I -t
+Generate a time-based UUID. This method creates a UUID based on the system
+clock plus the system's ethernet hardware address, if present.
.SH RETURN VALUE
The UUID of the form 1b4e28ba\-2fa1\-11d2\-883f\-b9a761bde3fb (in
.BR printf (3)
/*
* gen_uuid.c --- generate a DCE-compatible uuid
*
- * Copyright (C) 1999, Andreas Dilger
+ * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
*/
#include <stdio.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
#include "uuid/uuid.h"
+#define DO_TYPE_TIME 1
+#define DO_TYPE_RANDOM 2
+
+void usage(const char *progname)
+{
+ fprintf(stderr, "Usage: %s [-r] [-t]\n", progname);
+ exit(1);
+}
+
int
main (int argc, char *argv[])
{
- char str[37];
- uuid_t uu;
+ int c;
+ int do_type = 0;
+ char str[37];
+ uuid_t uu;
- uuid_generate(uu);
- uuid_unparse(uu, str);
+ while ((c = getopt (argc, argv, "tr")) != EOF)
+ switch (c) {
+ case 't':
+ do_type = DO_TYPE_TIME;
+ break;
+ case 'r':
+ do_type = DO_TYPE_RANDOM;
+ break;
+ default:
+ usage(argv[0]);
+ }
+
+ switch (do_type) {
+ case DO_TYPE_TIME:
+ uuid_generate_time(uu);
+ break;
+ case DO_TYPE_RANDOM:
+ uuid_generate_random(uu);
+ break;
+ default:
+ uuid_generate(uu);
+ break;
+ }
+
+ uuid_unparse(uu, str);
- printf("%s\n", str);
+ printf("%s\n", str);
- return 0;
+ return 0;
}