Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

rand.c

Go to the documentation of this file.
00001 /*
00002  * rand.c
00003  *
00004  * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
00005  *
00006  * $Id: rand.c,v 1.1 2002/03/29 06:07:49 dugsong Exp $
00007  */
00008 
00009 #include "config.h"
00010 
00011 #include <sys/types.h>
00012 
00013 #include <err.h>
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <unistd.h>
00017 
00018 #include "dnet.h"
00019 #include "mod.h"
00020 
00021 void
00022 rand_usage(void)
00023 {
00024         fprintf(stderr, "Usage: dnet rand <len>\n");
00025         exit(1);
00026 }
00027 
00028 int
00029 rand_main(int argc, char *argv[])
00030 {
00031         rand_t *r;
00032         int len;
00033         u_char *p;
00034         
00035         if (argc != 2 || *(argv[1]) == '-')
00036                 rand_usage();
00037         
00038         if ((len = atoi(argv[1])) == 0)
00039                 rand_usage();
00040 
00041         if ((p = malloc(len)) == NULL)
00042                 err(1, "malloc");
00043 
00044         if ((r = rand_open()) == NULL)
00045                 err(1, "rand_init");
00046 
00047         if (rand_get(r, p, len) < 0)
00048                 err(1, "rand_get");
00049         
00050         if (write(STDOUT_FILENO, p, len) != len)
00051                 err(1, "write");
00052         
00053         return (0);
00054 }
00055 
00056 struct mod mod_rand = {
00057         "rand",
00058         MOD_TYPE_DATA,
00059         rand_main
00060 };

Generated on Sun May 14 14:51:12 2006 by  doxygen 1.4.2