1 /* Copyright 2002 Yon Uriarte and Jeff Dike
2 * Licensed under the GPL
3 * This file is part of the original uml_switch code
4 * Modified 2003 Renzo Davoli
14 #include <sys/ioctl.h>
16 #include <linux/if_tun.h>
21 void send_tap(int fd
, void *packet
, int len
, void *unused
)
25 n
= write(fd
, packet
, len
);
27 if(errno
!= EAGAIN
) printlog(LOG_WARNING
,"send_tap %s",strerror(errno
));
31 int open_tap(char *dev
)
36 if((fd
= open("/dev/net/tun", O_RDWR
)) < 0){
37 printlog(LOG_ERR
,"Failed to open /dev/net/tun %s",strerror(errno
));
40 memset(&ifr
, 0, sizeof(ifr
));
41 ifr
.ifr_flags
= IFF_TAP
| IFF_NO_PI
;
42 strncpy(ifr
.ifr_name
, dev
, sizeof(ifr
.ifr_name
) - 1);
43 /*printf("dev=\"%s\", ifr.ifr_name=\"%s\"\n", ifr.ifr_name, dev);*/
44 if(ioctl(fd
, TUNSETIFF
, (void *) &ifr
) < 0){
45 printlog(LOG_ERR
,"TUNSETIFF failed %s",strerror(errno
));