Current section
Files
Jump to
Current section
Files
edoc/ioctl-5.edoc
@doc ioctl(2): control device
Controls a device using a file descriptor previously obtained using
open/5.
Argp can be either a binary or a list representation of a C struct. See
prctl/7 below for a description of the list elements.
On success, ioctl/5 returns a 3-tuple:
• Result: an integer equal to the return value of the ioctl
Usually 0 but some ioctls may use the return value as the output
parameter.
• Bin: the value depends on the type of the input parameter Argp
• cstruct: contains the contents of the memory pointed to by Argp
• integer/binary: an empty binary
== Examples ==
An example of creating a tap device in a net namespace on Linux:
```
1> {ok, Drv} = alcove_drv:start([{exec, "sudo -n"}]).
{ok,<0.177.0>}
2> {ok, Pid} = alcove:clone(Drv, [], [clone_newnet]).
{ok,8288}
3> {ok, FD} = alcove:open(Drv, [Pid], "/dev/net/tun", [o_rdwr], 0).
{ok,6}
4> {ok, 0, <<"tap", _/binary>>} = alcove:ioctl(Drv, [Pid], FD, tunsetiff, <<
4> % generate a tuntap device name
4> 0:(16 * 8),
4> % IFF_TAP, IFF_NO_PI
4> (16#0002 bor 16#1000):2/native-unsigned-integer-unit:8,
4> 0:(14 * 8)
4> >>).
{ok,0,
<<116,97,112,48,0,0,0,0,0,0,0,0,0,0,0,0,2,16,0,0,0,0,0,0,
0,0,...>>}
'''