I want to call ioctl from Rust. I know that I should use nix crate , but how exactly? This is not clear from the documentation.
I have a C:
int tun_open(char *devname) { struct ifreq ifr; int fd, err; if ( (fd = open("/dev/net/tun", O_RDWR)) == -1 ) { perror("open /dev/net/tun");exit(1); } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN; strncpy(ifr.ifr_name, devname, IFNAMSIZ); if ( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) == -1 ) { perror("ioctl TUNSETIFF");close(fd);exit(1); }
How can I do the same using the nix box? There are no TUN* constants in the nix box, and it is unclear how to use the ioctl macro.
source share