tun_sync/platform/linux/
sys.rs

1//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2//                    Version 2, December 2004
3//
4// Copyleft (ↄ) meh. <meh@schizofreni.co> | http://meh.schizofreni.co
5//
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9//
10//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11//   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12//
13//  0. You just DO WHAT THE FUCK YOU WANT TO.
14
15//! Bindings to internal Linux stuff.
16
17use ioctl::*;
18use libc::sockaddr;
19use libc::{c_char, c_int, c_short, c_uchar, c_uint, c_ulong, c_ushort, c_void};
20
21pub const IFNAMSIZ: usize = 16;
22
23pub const IFF_UP: c_short = 0x1;
24pub const IFF_RUNNING: c_short = 0x40;
25
26pub const IFF_TUN: c_short = 0x0001;
27pub const IFF_TAP: c_short = 0x0002;
28pub const IFF_NO_PI: c_short = 0x1000;
29pub const IFF_MULTI_QUEUE: c_short = 0x0100;
30
31#[repr(C)]
32#[derive(Copy, Clone)]
33pub struct ifmap {
34    pub mem_start: c_ulong,
35    pub mem_end: c_ulong,
36    pub base_addr: c_ushort,
37    pub irq: c_uchar,
38    pub dma: c_uchar,
39    pub port: c_uchar,
40}
41
42#[repr(C)]
43#[derive(Copy, Clone)]
44pub union ifsu {
45    pub raw_hdlc_proto: *mut c_void,
46    pub cisco: *mut c_void,
47    pub fr: *mut c_void,
48    pub fr_pvc: *mut c_void,
49    pub fr_pvc_info: *mut c_void,
50    pub sync: *mut c_void,
51    pub te1: *mut c_void,
52}
53
54#[repr(C)]
55#[derive(Copy, Clone)]
56pub struct if_settings {
57    pub type_: c_uint,
58    pub size: c_uint,
59    pub ifsu: ifsu,
60}
61
62#[repr(C)]
63#[derive(Copy, Clone)]
64pub union ifrn {
65    pub name: [c_char; IFNAMSIZ],
66}
67
68#[repr(C)]
69#[derive(Copy, Clone)]
70pub union ifru {
71    pub addr: sockaddr,
72    pub dstaddr: sockaddr,
73    pub broadaddr: sockaddr,
74    pub netmask: sockaddr,
75    pub hwaddr: sockaddr,
76
77    pub flags: c_short,
78    pub ivalue: c_int,
79    pub mtu: c_int,
80    pub map: ifmap,
81    pub slave: [c_char; IFNAMSIZ],
82    pub newname: [c_char; IFNAMSIZ],
83    pub data: *mut c_void,
84    pub settings: if_settings,
85}
86
87#[repr(C)]
88#[derive(Copy, Clone)]
89pub struct ifreq {
90    pub ifrn: ifrn,
91    pub ifru: ifru,
92}
93
94ioctl!(bad read siocgifflags with 0x8913; ifreq);
95ioctl!(bad write siocsifflags with 0x8914; ifreq);
96ioctl!(bad read siocgifaddr with 0x8915; ifreq);
97ioctl!(bad write siocsifaddr with 0x8916; ifreq);
98ioctl!(bad read siocgifdstaddr with 0x8917; ifreq);
99ioctl!(bad write siocsifdstaddr with 0x8918; ifreq);
100ioctl!(bad read siocgifbrdaddr with 0x8919; ifreq);
101ioctl!(bad write siocsifbrdaddr with 0x891a; ifreq);
102ioctl!(bad read siocgifnetmask with 0x891b; ifreq);
103ioctl!(bad write siocsifnetmask with 0x891c; ifreq);
104ioctl!(bad read siocgifmtu with 0x8921; ifreq);
105ioctl!(bad write siocsifmtu with 0x8922; ifreq);
106ioctl!(bad write siocsifname with 0x8923; ifreq);
107
108ioctl!(write tunsetiff with b'T', 202; c_int);
109ioctl!(write tunsetpersist with b'T', 203; c_int);
110ioctl!(write tunsetowner with b'T', 204; c_int);
111ioctl!(write tunsetgroup with b'T', 206; c_int);