Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <ftdi.h> // requires <sys/types.h>
|
#include <ftdi.h> // requires <sys/types.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include "infnoise.h"
|
#include "infnoise.h"
|
||||||
#include "libinfnoise.h"
|
#include "libinfnoise.h"
|
||||||
#include "libinfnoise_private.h"
|
#include "libinfnoise_private.h"
|
||||||
@@ -32,77 +33,103 @@ static void initOpts(struct opt_struct *opts) {
|
|||||||
opts->serial = NULL;
|
opts->serial = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
// getopt_long(3) options descriptor
|
||||||
{
|
|
||||||
|
static struct option longopts[] = {{"raw", no_argument, NULL, 'r'},
|
||||||
|
{"debug", no_argument, NULL, 'D'},
|
||||||
|
{"dev-random", no_argument, NULL, 'R'},
|
||||||
|
{"no-output", no_argument, NULL, 'n'},
|
||||||
|
{"multiplier", required_argument, NULL, 'm'},
|
||||||
|
{"pidfile", required_argument, NULL, 'p'},
|
||||||
|
{"serial", required_argument, NULL, 's'},
|
||||||
|
{"daemon", no_argument, NULL, 'd'},
|
||||||
|
{"list-devices", no_argument, NULL, 'l'},
|
||||||
|
{"version", no_argument, NULL, 'v'},
|
||||||
|
{"help", no_argument, NULL, 'h'},
|
||||||
|
{NULL, 0, NULL, 0}};
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
struct ftdi_context ftdic;
|
struct ftdi_context ftdic;
|
||||||
struct opt_struct opts;
|
struct opt_struct opts;
|
||||||
int xArg;
|
int ch;
|
||||||
bool multiplierAssigned = false;
|
bool multiplierAssigned = false;
|
||||||
|
|
||||||
initOpts(&opts);
|
initOpts(&opts);
|
||||||
|
|
||||||
// Process arguments
|
// Process arguments
|
||||||
for(xArg = 1; xArg < argc; xArg++) {
|
while ((ch = getopt_long(argc, argv, "rDRnm:p:s:dlvh", longopts, NULL)) !=
|
||||||
if(!strcmp(argv[xArg], "--raw")) {
|
-1) {
|
||||||
|
switch (ch) {
|
||||||
|
case 'r':
|
||||||
opts.raw = true;
|
opts.raw = true;
|
||||||
} else if(!strcmp(argv[xArg], "--debug")) {
|
break;
|
||||||
|
case 'D':
|
||||||
opts.debug = true;
|
opts.debug = true;
|
||||||
} else if(!strcmp(argv[xArg], "--dev-random")) {
|
break;
|
||||||
|
case 'R':
|
||||||
opts.devRandom = true;
|
opts.devRandom = true;
|
||||||
} else if(!strcmp(argv[xArg], "--no-output")) {
|
break;
|
||||||
|
case 'n':
|
||||||
opts.noOutput = true;
|
opts.noOutput = true;
|
||||||
} else if(!strcmp(argv[xArg], "--multiplier") && xArg+1 < argc) {
|
break;
|
||||||
xArg++;
|
case 'm':
|
||||||
multiplierAssigned = true;
|
multiplierAssigned = true;
|
||||||
int tmpOutputMult = atoi(argv[xArg]);
|
int tmpOutputMult = atoi(optarg);
|
||||||
if(tmpOutputMult < 0) {
|
if (tmpOutputMult < 0) {
|
||||||
fputs("Multiplier must be >= 0\n", stderr);
|
fputs("Multiplier must be >= 0\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
opts.outputMultiplier = tmpOutputMult;
|
opts.outputMultiplier = tmpOutputMult;
|
||||||
} else if(!strcmp(argv[xArg], "--pidfile")) {
|
break;
|
||||||
xArg++;
|
case 'p':
|
||||||
opts.pidFileName = argv[xArg];
|
opts.pidFileName = optarg;
|
||||||
if(opts.pidFileName == NULL || !strcmp("", opts.pidFileName)) {
|
if (opts.pidFileName == NULL || !strcmp("", opts.pidFileName)) {
|
||||||
fputs("--pidfile without file name\n", stderr);
|
fputs("--pidfile without file name\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if(!strcmp(argv[xArg], "--serial")) {
|
break;
|
||||||
xArg++;
|
case 's':
|
||||||
opts.serial = argv[xArg];
|
opts.serial = optarg;
|
||||||
if(opts.serial == NULL || !strcmp("",opts.serial)) {
|
if (opts.serial == NULL || !strcmp("", opts.serial)) {
|
||||||
fputs("--serial without value\n", stderr);
|
fputs("--serial without value\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if(!strcmp(argv[xArg], "--daemon")) {
|
break;
|
||||||
|
case 'd':
|
||||||
opts.daemon = true;
|
opts.daemon = true;
|
||||||
} else if(!strcmp(argv[xArg], "--list-devices")) {
|
break;
|
||||||
|
case 'l':
|
||||||
opts.listDevices = true;
|
opts.listDevices = true;
|
||||||
} else if(!strcmp(argv[xArg], "--version") || !strcmp(argv[xArg], "-v")) {
|
break;
|
||||||
|
case 'v':
|
||||||
opts.version = true;
|
opts.version = true;
|
||||||
} else if(!strcmp(argv[xArg], "--help") || !strcmp(argv[xArg], "-h")) {
|
break;
|
||||||
|
case 'h':
|
||||||
opts.help = true;
|
opts.help = true;
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
opts.help = true;
|
opts.help = true;
|
||||||
opts.none = true;
|
opts.none = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.help) {
|
if (opts.help) {
|
||||||
fputs("Usage: infnoise [options]\n"
|
fputs("Usage: infnoise [options]\n"
|
||||||
"Options are:\n"
|
"Options are:\n"
|
||||||
" --debug - turn on some debug output\n"
|
" -D, --debug - turn on some debug output\n"
|
||||||
" --dev-random - write entropy to /dev/random instead of stdout\n"
|
" -R, --dev-random - write entropy to /dev/random instead of "
|
||||||
" --raw - do not whiten the output\n"
|
"stdout\n"
|
||||||
" --multiplier <value> - write 256 bits * value for each 512 bits written to\n"
|
" -r, --raw - do not whiten the output\n"
|
||||||
" the Keccak sponge. Default of 0 means write all the entropy.\n"
|
" -m, --multiplier <value> - write 256 bits * value for each 512 bits written to\n"
|
||||||
" --no-output - do not write random output data\n"
|
" the Keccak sponge. Default of 0 means write all the entropy.\n"
|
||||||
" --pidfile <file> - write process ID to file\n"
|
" -n, --no-output - do not write random output data\n"
|
||||||
" --daemon - run in the background\n"
|
" -p, --pidfile <file> - write process ID to file\n"
|
||||||
" --serial <serial> - use specified device\n"
|
" -d, --daemon - run in the background\n"
|
||||||
" --list-devices - list available devices\n"
|
" -s, --serial <serial> - use specified device\n"
|
||||||
" --version - show version information\n"
|
" -l, --list-devices - list available devices\n"
|
||||||
" --help - this help output\n", stdout);
|
" -v, --version - show version information\n"
|
||||||
|
" -h, --help - this help output\n",
|
||||||
|
stdout);
|
||||||
if (opts.none) {
|
if (opts.none) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user