My objective is to create a to create a virtual wireless interface and to attach a listener on that interface. I am trying to do this using a C program.
So far I have been able to create the virtual interface by the following methods :
- Using the linux iw commands : `
sudo iw phy phy0 interface add mySta1 type station
but I was unable to find the library to do the same using C program.
Using Tun/Tap persistent interfaces :
http://backreference.org/2010/03/26/tuntap-interface-tutorial/
char tun_name[IFNAMSIZ]; strcpy(tun_name, "MyTun"); tunfd = tun_alloc(tun_name, IFF_TUN | IFF_NO_PI);
where tun_alloc is my function which uses ioctl to create the interface
ioctl(fd, TUNSETIFF, (void *) &ifr)
but there is no wireless extensions for this interface
For listening on the interface :
nread = read(tunfd,buffer,sizeof(buffer));
But this only works on tun devices which I create using my program or programs like openvpn. When used with any other interface like wlan0, ioctl gives the error 'Invalid argument'
Is my approach to the problem correct ? Is there any other way to achieve this ? I want to know the following :
- Is there a way of attaching the tun device on devices created by 'iw add interface' commands ?
- Is there a way of making a virtual wireless tun/tap interface or changing the type of an existing tun interface to wireless ?