This link https://stackoverflow.com/a/25601662/5536829 tells how to delete interface in BSD operating system.
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, "tun0");
int fd = socket(PF_INET, SOCK_STREAM, 0);
ioctl(fd, SIOCIFDESTROY, &ifr);
But how to do it in Linux? cuz Linux does not have SIOCIFDESTROY.