/dev/random - having a (trivial) coding problem

Heusden, Folkert van (f.v.heusden@ftr.nl)
Mon, 7 May 2001 21:00:12 +0200


See this program:

int main(int argc, char *argv[])
{
int h;
char buffer[16];
int nbytes=16,nbits=16*8;
int nin;

h=open("/dev/random", O_RDONLY);
if (h==-1) exit(1);

/* see how many bits there are in it */
printf("returned: %d\n", ioctl(h, RNDGETENTCNT, &nin));
printf("current number of bits: %d\n", nin);

/* add some */
printf("returned: %d\n", ioctl(h, RNDADDENTROPY, buffer, (int
*)&nbits, (int *)&nbytes));

/* see it it succeeded */
printf("returned: %d\n", ioctl(h, RNDGETENTCNT, &nin));
printf("current number of bits: %d\n", nin);

return 0;
}

it always fails!
But if I read the code for /dev/random correctly:
case RNDADDENTROPY:
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
p = (int *) arg;
if (get_user(ent_count, p++))
return -EFAULT;
if (ent_count < 0)
return -EINVAL;
if (get_user(size, p++))
return -EFAULT;
retval = random_write(file, (const char *) p,
size, &file->f_pos);
if (retval < 0)
return retval;
credit_entropy_store(random_state, ent_count);

I did the right thing.
Didn't I? Aren't the ioctl-parameters in this case pointer to int, pointer
to int (ent_count) and another (to size)?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/