From: Christoph Kappel Date: 2009-09-23T18:27:56+09:00 Subject: Re: Getting essid via ioctl ------=_Part_6046_960807515.1253698065266 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey Joel, thanks for both hints - FFI looks interesting but I don't want to wrap a li= brary.=20 Funny that I missed the 'p' of pack - it's working now: require "socket" # Copied from wireless.h SIOCGIWESSID =3D 0x8B1B =20 IW_ESSID_MAX_SIZE =3D 32 iwreq =3D [ "wlan0", " " * IW_ESSID_MAX_SIZE, IW_ESSID_MAX_SIZE, 0 ].pack("= a16pII") sock =3D Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0) sock.ioctl(SIOCGIWESSID, iwreq) interface, essid, len, flags =3D iwreq.unpack("a16pII") puts essid Now I can check if I can fetch the max. link quality via ioctl too. Wbr, Christoph ---- On Tue, 22 Sep 2009 16:58:46 -0700 Joel VanderWerf wrote ----=20 > Christoph Kappel wrote: > > Hello. > >=20 > > To avoid relying on the wireless tools I want to get the essid directl= y from the device with ioctl, in C=20 > > this wouldn't be a problem, but in Ruby it's quite different. > >=20 > > The problem is following struct from wireless.h that is used as input/= reply of ioctl: > >=20 > > struct iw_point > > { > > void __user *pointer; /* Pointer to the data (in user space) */ > > __u16 length; /* number of fields or size in bytes */ > > __u16 flags; /* Optional params */ > > }; > >=20 > > The pointer part must be a valid address of a memory area, followed by= the length in bytes,=20 > > followed by a flag field. I tried with Array#pack and the bit-struct g= em, but haven't found a solution yet. > >=20 > > Is there a way to bypass this memory pointer problem? >=20 > Christoph, >=20 > How are you calling ioctl() ? If you're using FFI, then googling for=20 > FFI::Pointer should help. If you're calling it in some other way and are= =20 > trying to access the binary data in ruby, does the P specifier in=20 > pack/unpack work? >=20 > --=20 > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407 > ------=_Part_6046_960807515.1253698065266--