Create dummy tap interface
Build PPPOE-Hero / Build-PPPOE-Hero (push) Successful in 22s Details

This commit is contained in:
Félix Baylac Jacqué 2023-09-25 20:21:27 +02:00
parent baeebe8a48
commit a0327757ea
1 changed files with 53 additions and 2 deletions

View File

@ -1,3 +1,54 @@
int main(int argc, char* argv[]) {
return(0);
#include <fcntl.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.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));
ifr.ifr_flags = IFF_TAP | IFF_MULTI_QUEUE;
if(*dev) {
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
}
if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0) {
close(fd);
return err;
}
return fd;
}
int main(int argc, char* argv[]) {
int tap_fd;
char tap_name[IFNAMSIZ];
char buffer[4096];
strcpy(tap_name, "taptest");
tap_fd = tap_alloc(tap_name);
if(tap_fd < 0) {
perror("Error while allocating the tap interface");
exit(1);
}
while(1) {
int nread = read(tap_fd,buffer,sizeof(buffer));
if (nread < 0) {
perror("Error while reading from tap");
close(tap_fd);
exit(1);
}
printf("Read %d bytes from device %s\n", nread, tap_name);
}
}