netlink_packet_route/
address_family_linux.rs

1// SPDX-License-Identifier: MIT
2
3const AF_KCM: u8 = 41;
4const AF_QIPCRTR: u8 = 42;
5const AF_SMC: u8 = 43;
6const AF_XDP: u8 = 44;
7const AF_MCTP: u8 = 45;
8
9#[derive(Debug, PartialEq, Eq, Clone, Copy, Default, Hash, PartialOrd, Ord)]
10#[non_exhaustive]
11pub enum AddressFamily {
12    #[default]
13    Unspec,
14    Local,
15    Unix,
16    Inet,
17    Ax25,
18    Ipx,
19    Appletalk,
20    Netrom,
21    Bridge,
22    Atmpvc,
23    X25,
24    Inet6,
25    Rose,
26    Decnet,
27    Netbeui,
28    Security,
29    Key,
30    Route,
31    Netlink,
32    Packet,
33    Ash,
34    Econet,
35    Atmsvc,
36    Rds,
37    Sna,
38    Irda,
39    Pppox,
40    Wanpipe,
41    Llc,
42    Ib,
43    Mpls,
44    Can,
45    Tipc,
46    Bluetooth,
47    Iucv,
48    Rxrpc,
49    Isdn,
50    Phonet,
51    Ieee802154,
52    Caif,
53    Alg,
54    Nfc,
55    Vsock,
56    Kcm,
57    Qipcrtr,
58    Smc,
59    Xdp,
60    Mctp,
61    Other(u8),
62}
63
64impl From<u8> for AddressFamily {
65    fn from(d: u8) -> Self {
66        match d {
67            d if d == libc::AF_UNSPEC as u8 => Self::Unspec,
68            d if d == libc::AF_UNIX as u8 => Self::Unix,
69            d if d == libc::AF_LOCAL as u8 => Self::Local,
70            d if d == libc::AF_INET as u8 => Self::Inet,
71            d if d == libc::AF_AX25 as u8 => Self::Ax25,
72            d if d == libc::AF_IPX as u8 => Self::Ipx,
73            d if d == libc::AF_APPLETALK as u8 => Self::Appletalk,
74            d if d == libc::AF_NETROM as u8 => Self::Netrom,
75            d if d == libc::AF_BRIDGE as u8 => Self::Bridge,
76            d if d == libc::AF_ATMPVC as u8 => Self::Atmpvc,
77            d if d == libc::AF_X25 as u8 => Self::X25,
78            d if d == libc::AF_INET6 as u8 => Self::Inet6,
79            d if d == libc::AF_ROSE as u8 => Self::Rose,
80            d if d == libc::AF_DECnet as u8 => Self::Decnet,
81            d if d == libc::AF_NETBEUI as u8 => Self::Netbeui,
82            d if d == libc::AF_SECURITY as u8 => Self::Security,
83            d if d == libc::AF_KEY as u8 => Self::Key,
84            d if d == libc::AF_NETLINK as u8 => Self::Netlink,
85            d if d == libc::AF_ROUTE as u8 => Self::Route,
86            d if d == libc::AF_PACKET as u8 => Self::Packet,
87            d if d == libc::AF_ASH as u8 => Self::Ash,
88            d if d == libc::AF_ECONET as u8 => Self::Econet,
89            d if d == libc::AF_ATMSVC as u8 => Self::Atmsvc,
90            d if d == libc::AF_RDS as u8 => Self::Rds,
91            d if d == libc::AF_SNA as u8 => Self::Sna,
92            d if d == libc::AF_IRDA as u8 => Self::Irda,
93            d if d == libc::AF_PPPOX as u8 => Self::Pppox,
94            d if d == libc::AF_WANPIPE as u8 => Self::Wanpipe,
95            d if d == libc::AF_LLC as u8 => Self::Llc,
96            d if d == libc::AF_IB as u8 => Self::Ib,
97            d if d == libc::AF_MPLS as u8 => Self::Mpls,
98            d if d == libc::AF_CAN as u8 => Self::Can,
99            d if d == libc::AF_TIPC as u8 => Self::Tipc,
100            d if d == libc::AF_BLUETOOTH as u8 => Self::Bluetooth,
101            d if d == libc::AF_IUCV as u8 => Self::Iucv,
102            d if d == libc::AF_RXRPC as u8 => Self::Rxrpc,
103            d if d == libc::AF_ISDN as u8 => Self::Isdn,
104            d if d == libc::AF_PHONET as u8 => Self::Phonet,
105            d if d == libc::AF_IEEE802154 as u8 => Self::Ieee802154,
106            d if d == libc::AF_CAIF as u8 => Self::Caif,
107            d if d == libc::AF_ALG as u8 => Self::Alg,
108            d if d == libc::AF_NFC as u8 => Self::Nfc,
109            d if d == libc::AF_VSOCK as u8 => Self::Vsock,
110            d if d == AF_KCM => Self::Kcm,
111            d if d == AF_QIPCRTR => Self::Qipcrtr,
112            d if d == AF_SMC => Self::Smc,
113            d if d == AF_XDP => Self::Xdp,
114            d if d == AF_MCTP => Self::Mctp,
115            _ => Self::Other(d),
116        }
117    }
118}
119
120impl From<AddressFamily> for u8 {
121    fn from(v: AddressFamily) -> u8 {
122        match v {
123            AddressFamily::Unspec => libc::AF_UNSPEC as u8,
124            AddressFamily::Local => libc::AF_LOCAL as u8,
125            AddressFamily::Unix => libc::AF_UNIX as u8,
126            AddressFamily::Inet => libc::AF_INET as u8,
127            AddressFamily::Ax25 => libc::AF_AX25 as u8,
128            AddressFamily::Ipx => libc::AF_IPX as u8,
129            AddressFamily::Appletalk => libc::AF_APPLETALK as u8,
130            AddressFamily::Netrom => libc::AF_NETROM as u8,
131            AddressFamily::Bridge => libc::AF_BRIDGE as u8,
132            AddressFamily::Atmpvc => libc::AF_ATMPVC as u8,
133            AddressFamily::X25 => libc::AF_X25 as u8,
134            AddressFamily::Inet6 => libc::AF_INET6 as u8,
135            AddressFamily::Rose => libc::AF_ROSE as u8,
136            AddressFamily::Decnet => libc::AF_DECnet as u8,
137            AddressFamily::Netbeui => libc::AF_NETBEUI as u8,
138            AddressFamily::Security => libc::AF_SECURITY as u8,
139            AddressFamily::Key => libc::AF_KEY as u8,
140            AddressFamily::Route => libc::AF_ROUTE as u8,
141            AddressFamily::Netlink => libc::AF_NETLINK as u8,
142            AddressFamily::Packet => libc::AF_PACKET as u8,
143            AddressFamily::Ash => libc::AF_ASH as u8,
144            AddressFamily::Econet => libc::AF_ECONET as u8,
145            AddressFamily::Atmsvc => libc::AF_ATMSVC as u8,
146            AddressFamily::Rds => libc::AF_RDS as u8,
147            AddressFamily::Sna => libc::AF_SNA as u8,
148            AddressFamily::Irda => libc::AF_IRDA as u8,
149            AddressFamily::Pppox => libc::AF_PPPOX as u8,
150            AddressFamily::Wanpipe => libc::AF_WANPIPE as u8,
151            AddressFamily::Llc => libc::AF_LLC as u8,
152            AddressFamily::Ib => libc::AF_IB as u8,
153            AddressFamily::Mpls => libc::AF_MPLS as u8,
154            AddressFamily::Can => libc::AF_CAN as u8,
155            AddressFamily::Tipc => libc::AF_TIPC as u8,
156            AddressFamily::Bluetooth => libc::AF_BLUETOOTH as u8,
157            AddressFamily::Iucv => libc::AF_IUCV as u8,
158            AddressFamily::Rxrpc => libc::AF_RXRPC as u8,
159            AddressFamily::Isdn => libc::AF_ISDN as u8,
160            AddressFamily::Phonet => libc::AF_PHONET as u8,
161            AddressFamily::Ieee802154 => libc::AF_IEEE802154 as u8,
162            AddressFamily::Caif => libc::AF_CAIF as u8,
163            AddressFamily::Alg => libc::AF_ALG as u8,
164            AddressFamily::Nfc => libc::AF_NFC as u8,
165            AddressFamily::Vsock => libc::AF_VSOCK as u8,
166            AddressFamily::Kcm => AF_KCM,
167            AddressFamily::Qipcrtr => AF_QIPCRTR,
168            AddressFamily::Smc => AF_SMC,
169            AddressFamily::Xdp => AF_XDP,
170            AddressFamily::Mctp => AF_MCTP,
171            AddressFamily::Other(d) => d,
172        }
173    }
174}