Skip to content
Advertisement

How to use nix’s ioctl?

I want to call ioctl from Rust. I know that I should use the nix crate, but how exactly? From the documentation it’s not clear.

I have this C:

JavaScript

How would I do that same thing using the nix crate? There are no TUN* constants in the nix crate and it isn’t clear how to use the ioctl macro.

Advertisement

Answer

There is some example usage in rust-spidev. I will try to apply that to your code.

TUNSETIFF is defined as:

JavaScript

That would be this in Rust using nix:

JavaScript

The above macro will define the function, which you can call like this:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement