1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
use constants::*;

#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub struct LinkFlags(pub u32);

impl From<u32> for LinkFlags {
    fn from(flags: u32) -> Self {
        LinkFlags(flags)
    }
}

impl<'a> From<&'a LinkFlags> for u32 {
    fn from(flags: &'a LinkFlags) -> u32 {
        flags.0
    }
}

impl From<LinkFlags> for u32 {
    fn from(flags: LinkFlags) -> u32 {
        flags.0
    }
}

impl Default for LinkFlags {
    fn default() -> Self {
        LinkFlags::new()
    }
}

impl LinkFlags {
    pub fn new() -> Self {
        LinkFlags(0)
    }

    /// Set the `IFF_UP` flag
    pub fn set_up(&mut self) {
        self.0 |= IFF_UP
    }

    /// Check if the `IFF_UP` flag is set
    pub fn is_up(self) -> bool {
        self.0 & IFF_UP == IFF_UP
    }

    /// Set the `IFF_RUNNING` flag
    pub fn set_running(&mut self) {
        self.0 |= IFF_RUNNING
    }

    /// Check if the `IFF_RUNNING` flag is set
    pub fn is_running(self) -> bool {
        self.0 & IFF_RUNNING == IFF_RUNNING
    }

    /// Set the `IFF_LOWER_UP` flag
    pub fn set_lower_up(&mut self) {
        self.0 |= IFF_LOWER_UP
    }

    /// Check if the `IFF_LOWER_UP` flag is set
    pub fn is_lower_up(self) -> bool {
        self.0 & IFF_LOWER_UP == IFF_LOWER_UP
    }

    /// Set the `IFF_DORMANT` flag
    pub fn set_dormant(&mut self) {
        self.0 |= IFF_DORMANT
    }

    /// Check if the `IFF_DORMANT` flag is set
    pub fn is_dormant(self) -> bool {
        self.0 & IFF_DORMANT == IFF_DORMANT
    }

    /// Set the `IFF_BROADCAST` flag
    pub fn set_broadcast(&mut self) {
        self.0 |= IFF_BROADCAST
    }

    /// Check if the `IFF_BROADCAST` flag is set
    pub fn is_broadcast(self) -> bool {
        self.0 & IFF_BROADCAST == IFF_BROADCAST
    }

    /// Set the `IFF_MULTICAST` flag
    pub fn set_multicast(&mut self) {
        self.0 |= IFF_MULTICAST
    }

    /// Check if the `IFF_MULTICAST` flag is set
    pub fn is_multicast(self) -> bool {
        self.0 & IFF_MULTICAST == IFF_MULTICAST
    }

    /// Set the `IFF_ALLMULTI` flag
    pub fn set_allmulti(&mut self) {
        self.0 |= IFF_ALLMULTI
    }

    /// Check if the `IFF_ALLMULTI` flag is set
    pub fn is_allmulti(self) -> bool {
        self.0 & IFF_ALLMULTI == IFF_ALLMULTI
    }

    /// Set the `IFF_DEBUG` flag
    pub fn set_debug(&mut self) {
        self.0 |= IFF_DEBUG
    }

    /// Check if the `IFF_DEBUG` flag is set
    pub fn is_debug(self) -> bool {
        self.0 & IFF_DEBUG == IFF_DEBUG
    }

    /// Set the `IFF_LOOPBACK` flag
    pub fn set_loopback(&mut self) {
        self.0 |= IFF_LOOPBACK
    }

    /// Check if the `IFF_LOOPBACK` flag is set
    pub fn is_loopback(self) -> bool {
        self.0 & IFF_LOOPBACK == IFF_LOOPBACK
    }

    /// Set the `IFF_POINTOPOINT` flag
    pub fn set_point_to_point(&mut self) {
        self.0 |= IFF_POINTOPOINT
    }

    /// Check if the `IFF_POINTOPOINT` flag is set
    pub fn is_point_to_point(self) -> bool {
        self.0 & IFF_POINTOPOINT == IFF_POINTOPOINT
    }

    /// Set the `IFF_NOARP` flag
    pub fn set_no_arp(&mut self) {
        self.0 |= IFF_NOARP
    }

    /// Check if the `IFF_NOARP` flag is set
    pub fn is_no_arp(self) -> bool {
        self.0 & IFF_NOARP == IFF_NOARP
    }

    /// Set the `IFF_PROMISC` flag
    pub fn set_promiscuous(&mut self) {
        self.0 |= IFF_PROMISC
    }

    /// Check if the `IFF_PROMISC` flag is set
    pub fn is_promiscuous(self) -> bool {
        self.0 & IFF_PROMISC == IFF_PROMISC
    }

    /// Set the `IFF_MASTER` flag
    pub fn set_master(&mut self) {
        self.0 |= IFF_MASTER
    }

    /// Check if the `IFF_MASTER` flag is set
    pub fn is_master(self) -> bool {
        self.0 & IFF_MASTER == IFF_MASTER
    }

    /// Set the `IFF_SLAVE` flag
    pub fn set_slave(&mut self) {
        self.0 |= IFF_SLAVE
    }

    /// Check if the `IFF_SLAVE` flag is set
    pub fn is_slave(self) -> bool {
        self.0 & IFF_SLAVE == IFF_SLAVE
    }

    /// Set the `IFF_PORTSEL` flag
    pub fn set_port_select(&mut self) {
        self.0 |= IFF_PORTSEL
    }

    /// Check if the `IFF_PORTSEL` flag is set
    pub fn is_port_select(self) -> bool {
        self.0 & IFF_PORTSEL == IFF_PORTSEL
    }

    /// Set the `IFF_AUTOMEDIA` flag
    pub fn set_auto_media_type(&mut self) {
        self.0 |= IFF_AUTOMEDIA
    }

    /// Check if the `IFF_AUTOMEDIA` flag is set
    pub fn is_auto_media_type(self) -> bool {
        self.0 & IFF_AUTOMEDIA == IFF_AUTOMEDIA
    }

    // TODO: ECHO, DYNAMIC, NOTRAILERS
}