My Rat Hat Enterprise 5 OS has only one tun device in /dev/net/tun and no tap.
I would like to create more taps and tuns but I don't know how.
I used the programe below to create 2 tap devices.
int tun_create(char *dev, int flags)
{
struct ifreq ifr;
int fd, err;

assert(dev != NULL);

if ((fd = open("/dev/net/tun", O_RDWR)) < 0)
return fd;

memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags |= flags;
if (*dev != '\0')
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;
}


int main(int argc, char *argv[])
{
char tun_name[IFNAMSIZ]="tap0";
char tun_name1[IFNAMSIZ]="tap1";

Tap=tun_create(tun_name, IFF_TAP | IFF_NO_PI);
if (Tap< 0) {
perror("tun_create");
return 1;
}
printf("TAP name is %s\n", tun_name);
printf("Tap=%d\n",Tap);

system("ifconfig tap0 10.0.0.185 netmask 255.255.0.0 up");


Tap1=tun_create(tun_name1, IFF_TAP | IFF_NO_PI);
if (Tap1< 0) {
perror("tun_create");
return 1;
}
printf("TAP1 name is %s\n", tun_name1);
printf("Tap1=%d\n",Tap1);

system("ifconfig tap1 10.0.0.186 netmask 255.255.0.0 up");
}

But it doesn't work well.When pinging the tap 10.0.0.185,the response received is from the tap 10.0.0.186.I don't know why.
My email is simba226@163.com.
Thanks!