diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2007-07-05 18:01:42 +0200 |
---|---|---|
committer | Sascha Hauer <sha@octopus.labnet.pengutronix.de> | 2007-07-05 18:01:42 +0200 |
commit | be27e7ea088c82f9adc8347f91b21b217aaa1ce0 (patch) | |
tree | 23865dfdea6e75a7a36c2f3d81210f592354bbcd /arch/linux/lib/tap.c | |
parent | 798de5071d2a775af8931e99560a0eb9f72dfec3 (diff) | |
download | barebox-be27e7ea088c82f9adc8347f91b21b217aaa1ce0.tar.gz barebox-be27e7ea088c82f9adc8347f91b21b217aaa1ce0.tar.xz |
svn_rev_308
add arch/linux/
Diffstat (limited to 'arch/linux/lib/tap.c')
-rw-r--r-- | arch/linux/lib/tap.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/arch/linux/lib/tap.c b/arch/linux/lib/tap.c new file mode 100644 index 0000000000..bad1c4b655 --- /dev/null +++ b/arch/linux/lib/tap.c @@ -0,0 +1,37 @@ +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/if.h> +#include <linux/if_tun.h> +#include <string.h> + +int tap_alloc(char *dev) +{ + struct ifreq ifr; + int fd, err; + + if ((fd = open("/dev/net/tun", O_RDWR)) < 0) + return -1; + + 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_TAP | IFF_NO_PI; + if (*dev) + strncpy(ifr.ifr_name, dev, IFNAMSIZ); + + if ((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) { + close(fd); + return err; + } + + strcpy(dev, ifr.ifr_name); + return fd; +} |