2
* Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
2
* Copyright (C) 2004, 2005, 2007, 2009, 2010 Internet Systems Consortium, Inc. ("ISC")
3
3
* Copyright (C) 2000-2003 Internet Software Consortium.
5
5
* Permission to use, copy, modify, and/or distribute this software for any
15
15
* PERFORMANCE OF THIS SOFTWARE.
18
/* $Id: genrandom.c,v 1.4 2009/03/07 23:47:45 tbox Exp $ */
18
/* $Id: genrandom.c,v 1.4.152.3 2010/05/17 23:49:51 tbox Exp $ */
21
21
#include <config.h>
23
#include <isc/commandline.h>
24
#include <isc/print.h>
25
#include <isc/stdlib.h>
26
#include <isc/stdlib.h>
29
main(int argc, char **argv) {
31
const char *program = "genrandom";
33
ISC_PLATFORM_NORETURN_PRE static void
34
usage(void) ISC_PLATFORM_NORETURN_POST;
38
fprintf(stderr, "usage: %s [-n 2..9] k file\n", program);
43
generate(char *filename, unsigned int bytes) {
36
printf("usage: genrandom k file\n");
39
k = strtoul(argv[1], &endp, 10);
41
printf("usage: genrandom k file\n");
46
fp = fopen(argv[2], "w");
46
fp = fopen(filename, "w");
48
printf("failed to open %s\n", argv[2]);
48
printf("failed to open %s\n", filename);
52
#ifndef HAVE_ARC4RANDOM
55
52
while (bytes > 0) {
56
53
#ifndef HAVE_ARC4RANDOM
57
54
unsigned short int x = (rand() & 0xFFFF);
61
58
unsigned char c = x & 0xFF;
62
59
if (putc(c, fp) == EOF) {
63
printf("error writing to file\n");
60
printf("error writing to %s\n", filename);
67
64
if (putc(c, fp) == EOF) {
68
printf("error writing to file\n");
65
printf("error writing to %s\n", filename);
74
main(int argc, char **argv) {
82
isc_commandline_errprint = ISC_FALSE;
84
while ((c = isc_commandline_parse(argc, argv, "hn:")) != EOF) {
87
n = strtol(isc_commandline_argument, &endp, 10);
88
if ((*endp != 0) || (n <= 1) || (n > 9))
93
if (isc_commandline_option != '?')
94
fprintf(stderr, "%s: invalid argument -%c\n",
95
program, isc_commandline_option);
100
fprintf(stderr, "%s: unhandled option -%c\n",
101
program, isc_commandline_option);
106
if (isc_commandline_index + 2 != argc)
109
k = strtoul(argv[isc_commandline_index++], &endp, 10);
114
#ifndef HAVE_ARC4RANDOM
118
generate(argv[isc_commandline_index], bytes);
122
len = strlen(argv[isc_commandline_index]) + 2;
123
name = (char *) malloc(len);
129
for (i = 1; i <= n; i++) {
130
snprintf(name, len, "%s%d", argv[isc_commandline_index], i);
131
generate(name, bytes);