ioctl

Niels Diepeveen niels at endea.demon.nl
Tue Jan 11 15:25:25 EST 2000


Matt Cheselka schreef:
>         >>> xxx = 0
>         >>> val = fcntl.ioctl (fd.fileno(), RNDGETENTCNT, xxx)
>         Traceback (innermost last):
>           File "<stdin>", line 1, in ?
>         IOError: (14, 'Bad address')
> 
> So it appears as though I'm not passing the correct value of 'xxx' since it
> looks like fcntl.ioctl is interpreting 'xxx=0' to be the address of where to
> place the result, which is in the ROM and not legal.
> 
> So I've got two questions:
> 
>         1. is this essientially the correct way to do ioctl stuff or is there
>            a better way?

It would be a little cleaner to put things like this into a C module, so
you could do something like
 val = rnddev.getentcnt()
but for occasional use this is probably acceptable.

>         2. how do I pass this method the correct address?

First, you need to set up a mutable buffer to accept the returned value.
An array object with one integer element seems most appropriate:
  val = array.array('i', [0])
Then you can do
  fcntl.ioctl (fd.fileno(), RNDGETENTCNT, val.buffer_info()[0])
and the entropy count will be in val[0].

-- 
Niels Diepeveen
Endea automatisering




More information about the Python-list mailing list