lkml.org 
[lkml]   [2001]   [May]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Subject/dev/random - having a (trivial) coding problem
Date
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/

\
 
 \ /
  Last update: 2005-03-22 12:52    [W:0.017 / U:1.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site