diff options
author | green <green@FreeBSD.org> | 2000-01-20 01:49:41 +0000 |
---|---|---|
committer | green <green@FreeBSD.org> | 2000-01-20 01:49:41 +0000 |
commit | 10377a13d6a2b2cb88d5e7c5fc85539ef3171c01 (patch) | |
tree | fe09f5bc69207cd96b5bf9067ae779852cd29c61 /usr.sbin/inetd/builtins.c | |
parent | f9060bc85d26d665cb1618cf12dfaa14e9a07b5c (diff) | |
download | FreeBSD-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.c | 22 |
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; |