lkml.org 
[lkml]   [2002]   [Feb]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectTUN/TAP driver doesn't work.
Hello,

I am trying to use TUN/TAP driver. My OS is RH71, kernel is 2.4.17, with
tuntap compiled as a module. Module is inserted properly when I try to
open '/dev/net/tun', and I get kernel message saying "TUN/TAP universal
driver, (c)...etc.". But ioctls don't work and always return '-1'.
To test it I was using code from tuntap's documentation (included below this
message and btw I don't understand dev's name str-copying in this code)
and pengaol, newest version, which I know works with tuntap. None of these
2 programs work for me.

Any help would be really greatly appreciated.

-marek

-- test code --
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/if_tun.h>

int tun_alloc(char *dev)
{
struct ifreq ifr;
int fd, err;

if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
printf("open error\n");
return 0;
}

memset(&ifr, 0, sizeof(ifr));

/* Flags: IFF_TUN - TUN device (no Ethernet headers)
* IFF_TAP - TAP device
* IFF_NO_PI - Do not provide packet information
*
*/
ifr.ifr_flags = IFF_TUN;

if( *dev )
strncpy(ifr.ifr_name, dev, IFNAMSIZ);

if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){
printf("ioctl err %d: %s\n", err, strerror(err));
close(fd);
return err;
}
strcpy(dev, ifr.ifr_name);
return fd;
}

int main(int argc, char **argv)
{
char test[100] = "1234567890123456";
tun_alloc(test);
return 0;
}



-
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 13:18    [W:0.048 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site