我想打电话ioctl给Rust.我知道我应该使用nix箱子,但究竟是怎么回事?从文档中不清楚.
我有这个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);
/* ioctl will use if_name as the name of TUN
* interface to open: "tun0", etc. */
if ( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) == -1 ) {
perror("ioctl TUNSETIFF");close(fd);exit(1);
}
//..........
Run Code Online (Sandbox Code Playgroud)
如何使用nix箱子做同样的事情?TUN*nix crate 中没有常量,并且不清楚如何使用ioctl宏.