summaryrefslogtreecommitdiffstats
path: root/usr.sbin/inetd/builtins.c
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>2000-01-20 01:49:41 +0000
committergreen <green@FreeBSD.org>2000-01-20 01:49:41 +0000
commit10377a13d6a2b2cb88d5e7c5fc85539ef3171c01 (patch)
treefe09f5bc69207cd96b5bf9067ae779852cd29c61 /usr.sbin/inetd/builtins.c
parentf9060bc85d26d665cb1618cf12dfaa14e9a07b5c (diff)
downloadFreeBSD-src-10377a13d6a2b2cb88d5e7c5fc85539ef3171c01.zip
FreeBSD-src-10377a13d6a2b2cb88d5e7c5fc85539ef3171c01.tar.gz
I like base-36 better.
Diffstat (limited to 'usr.sbin/inetd/builtins.c')
-rw-r--r--usr.sbin/inetd/builtins.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/usr.sbin/inetd/builtins.c b/usr.sbin/inetd/builtins.c
index 2107b95..6ba404c 100644
--- a/usr.sbin/inetd/builtins.c
+++ b/usr.sbin/inetd/builtins.c
@@ -378,13 +378,27 @@ ident_stream(s, sep) /* Ident service (AKA "auth") */
case 'g':
gflag = 1;
random = 0; /* Shush, compiler. */
+ /*
+ * The number of bits in "random" divided
+ * by the number of bits needed per iteration
+ * gives a more optimal way to reload the
+ * random number only when necessary.
+ *
+ * I'm using base-36, so I need at least 6
+ * bits; round it up to 8 bits to make it
+ * easier.
+ */
for (i = 0; i < sizeof(garbage) - 1; i++) {
- if (i % (sizeof(random) * 8 / 4) == 0)
+ const char *const base36 =
+ "0123456789"
+ "abcdefghijklmnopqrstuvwxyz";
+ if (i % (sizeof(random) * 8 / 8) == 0)
random = arc4random();
- snprintf(garbage + i, 2, "%.1x",
- (int)random & 0xf);
- random >>= 4;
+ garbage[i] =
+ base36[(random & 0xff) % 36];
+ random >>= 8;
}
+ garbage[i] = '\0';
break;
case 'n':
nflag = 1;
OpenPOWER on IntegriCloud