@@ -3,7 +3,9 @@ use std::{
33    os:: fd:: AsRawFd , 
44} ; 
55
6- use  libc:: { c_char,  kld_load,  IFF_UP ,  IF_NAMESIZE } ; 
6+ #[ cfg( target_os = "freebsd" ) ]  
7+ use  libc:: { c_char,  kld_load} ; 
8+ use  libc:: { IFF_UP ,  IF_NAMESIZE } ; 
79use  nix:: { ioctl_readwrite,  ioctl_write_ptr,  sys:: socket:: AddressFamily } ; 
810
911use  super :: { 
@@ -20,11 +22,17 @@ ioctl_write_ptr!(destroy_clone_if, b'i', 121, IfReq);
2022// SIOCIFCREATE2 
2123ioctl_readwrite ! ( create_clone_if,  b'i' ,  124 ,  IfReq ) ; 
2224// SIOCAIFADDR 
25+ #[ cfg( target_os = "freebsd" ) ]  
2326ioctl_write_ptr ! ( add_addr_if,  b'i' ,  43 ,  InAliasReq ) ; 
27+ #[ cfg( target_os = "macos" ) ]  
28+ ioctl_write_ptr ! ( add_addr_if,  b'i' ,  26 ,  InAliasReq ) ; 
2429// SIOCDIFADDR 
2530ioctl_write_ptr ! ( del_addr_if,  b'i' ,  25 ,  IfReq ) ; 
2631// SIOCAIFADDR_IN6 
32+ #[ cfg( target_os = "freebsd" ) ]  
2733ioctl_write_ptr ! ( add_addr_if_in6,  b'i' ,  27 ,  In6AliasReq ) ; 
34+ #[ cfg( target_os = "macos" ) ]  
35+ ioctl_write_ptr ! ( add_addr_if_in6,  b'i' ,  26 ,  In6AliasReq ) ; 
2836// SIOCDIFADDR_IN6 
2937ioctl_write_ptr ! ( del_addr_if_in6,  b'i' ,  25 ,  IfReq6 ) ; 
3038// SIOCSIFFLAGS 
@@ -51,14 +59,17 @@ impl IfReq {
5159
5260        // First, try to load a kernel module for this type of network interface. 
5361        // Omit digits at the end of interface name, e.g. "wg0" -> "if_wg". 
54-         let  index = if_name
55-             . find ( |c :  char | c. is_ascii_digit ( ) ) 
56-             . unwrap_or ( if_name. len ( ) ) ; 
57-         let  mod_name = format ! ( "if_{}" ,  & if_name[ 0 ..index] ) ; 
58-         unsafe  { 
59-             // Ignore the return value for the time being. 
60-             // Do the cast because `c_char` differs across platforms. 
61-             kld_load ( mod_name. as_ptr ( )  as  * const  c_char ) ; 
62+         #[ cfg( target_os = "freebsd" ) ]  
63+         { 
64+             let  index = if_name
65+                 . find ( |c :  char | c. is_ascii_digit ( ) ) 
66+                 . unwrap_or ( if_name. len ( ) ) ; 
67+             let  mod_name = format ! ( "if_{}" ,  & if_name[ 0 ..index] ) ; 
68+             unsafe  { 
69+                 // Ignore the return value for the time being. 
70+                 // Do the cast because `c_char` differs across platforms. 
71+                 kld_load ( mod_name. as_ptr ( )  as  * const  c_char ) ; 
72+             } 
6273        } 
6374
6475        Self  { 
@@ -87,7 +98,7 @@ impl IfReq {
8798        Ok ( ( ) ) 
8899    } 
89100
90-     pub ( super )  fn  delete_address ( & mut  self ,  addr :  & Ipv4Addr )  -> Result < ( ) ,  IoError >  { 
101+     pub ( super )  fn  delete_address ( & mut  self ,  addr :  Ipv4Addr )  -> Result < ( ) ,  IoError >  { 
91102        self . ifr_ifru  = addr. into ( ) ; 
92103
93104        let  socket = create_socket ( AddressFamily :: Inet ) . map_err ( IoError :: WriteIo ) ?; 
@@ -104,6 +115,7 @@ impl IfReq {
104115pub  struct  IfReq6  { 
105116    ifr_name :  [ u8 ;  IF_NAMESIZE ] , 
106117    ifr_ifru :  SockAddrIn6 , 
118+     _padding :  [ u8 ;  244 ] , 
107119} 
108120
109121impl  IfReq6  { 
@@ -119,10 +131,11 @@ impl IfReq6 {
119131        Self  { 
120132            ifr_name, 
121133            ifr_ifru :  SockAddrIn6 :: default ( ) , 
134+             _padding :  [ 0u8 ;  244 ] , 
122135        } 
123136    } 
124137
125-     pub ( super )  fn  delete_address ( & mut  self ,  addr :  & Ipv6Addr )  -> Result < ( ) ,  IoError >  { 
138+     pub ( super )  fn  delete_address ( & mut  self ,  addr :  Ipv6Addr )  -> Result < ( ) ,  IoError >  { 
126139        self . ifr_ifru  = addr. into ( ) ; 
127140
128141        let  socket = create_socket ( AddressFamily :: Inet6 ) . map_err ( IoError :: WriteIo ) ?; 
@@ -141,16 +154,17 @@ pub struct InAliasReq {
141154    ifra_addr :  SockAddrIn , 
142155    ifra_broadaddr :  SockAddrIn , 
143156    ifra_mask :  SockAddrIn , 
157+     #[ cfg( target_os = "freebsd" ) ]  
144158    ifra_vhid :  u32 , 
145159} 
146160
147161impl  InAliasReq  { 
148162    #[ must_use]  
149163    pub ( super )  fn  new ( 
150164        if_name :  & str , 
151-         addr :   & Ipv4Addr , 
152-         broadcast :  & Ipv4Addr , 
153-         mask :  & Ipv4Addr , 
165+         address :   Ipv4Addr , 
166+         broadcast :  Ipv4Addr , 
167+         mask :  Ipv4Addr , 
154168    )  -> Self  { 
155169        let  mut  ifr_name = [ 0u8 ;  IF_NAMESIZE ] ; 
156170        if_name
@@ -161,9 +175,10 @@ impl InAliasReq {
161175
162176        Self  { 
163177            ifr_name, 
164-             ifra_addr :  addr . into ( ) , 
178+             ifra_addr :  address . into ( ) , 
165179            ifra_broadaddr :  broadcast. into ( ) , 
166180            ifra_mask :  mask. into ( ) , 
181+             #[ cfg( target_os = "freebsd" ) ]  
167182            ifra_vhid :  0 , 
168183        } 
169184    } 
@@ -192,16 +207,17 @@ pub struct In6AliasReq {
192207    ia6t_preferred :  u64 , 
193208    ia6t_vltime :  u32 , 
194209    ia6t_pltime :  u32 , 
210+     #[ cfg( target_os = "freebsd" ) ]  
195211    ifra_vhid :  u32 , 
196212} 
197213
198214impl  In6AliasReq  { 
199215    #[ must_use]  
200216    pub ( super )  fn  new ( 
201217        if_name :  & str , 
202-         address :  & Ipv6Addr , 
203-         dstaddr :  & Ipv6Addr , 
204-         prefixmask :  & Ipv6Addr , 
218+         address :  Ipv6Addr , 
219+         // FIXME: currenlty unused:  dstaddr: Ipv6Addr,
220+         prefixmask :  Ipv6Addr , 
205221    )  -> Self  { 
206222        let  mut  ifr_name = [ 0u8 ;  IF_NAMESIZE ] ; 
207223        if_name
@@ -213,13 +229,14 @@ impl In6AliasReq {
213229        Self  { 
214230            ifr_name, 
215231            ifra_addr :  address. into ( ) , 
216-             ifra_dstaddr :  dstaddr . into ( ) , 
232+             ifra_dstaddr :  SockAddrIn6 :: zeroed ( ) , 
217233            ifra_prefixmask :  prefixmask. into ( ) , 
218234            ifra_flags :  0 , 
219235            ia6t_expire :  0 , 
220236            ia6t_preferred :  0 , 
221237            ia6t_vltime :  ND6_INFINITE_LIFETIME , 
222238            ia6t_pltime :  ND6_INFINITE_LIFETIME , 
239+             #[ cfg( target_os = "freebsd" ) ]  
223240            ifra_vhid :  0 , 
224241        } 
225242    } 
0 commit comments