File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,18 @@ pub struct InterfaceAddress {
30
30
pub destination : Option < SockAddr > ,
31
31
}
32
32
33
+ cfg_if ! {
34
+ if #[ cfg( any( target_os = "emscripten" , target_os = "fuchsia" , target_os="linux" ) ) ] {
35
+ fn get_ifu_from_sockaddr( info: & libc:: ifaddrs) -> * const libc:: sockaddr {
36
+ info. ifa_ifu
37
+ }
38
+ } else {
39
+ fn get_ifu_from_sockaddr( info: & libc:: ifaddrs) -> * const libc:: sockaddr {
40
+ info. ifa_dstaddr;
41
+ }
42
+ }
43
+ }
44
+
33
45
impl InterfaceAddress {
34
46
/// Create an `InterfaceAddress` from the libc struct.
35
47
fn from_libc_ifaddrs ( info : & libc:: ifaddrs ) -> InterfaceAddress {
@@ -45,14 +57,7 @@ impl InterfaceAddress {
45
57
destination : None ,
46
58
} ;
47
59
48
- let ifu : * mut libc:: sockaddr ;
49
-
50
- #[ cfg( any( target_os = "linux" , target_os = "emscripten" , target_os = "fuchsia" ) ) ]
51
- { ifu = info. ifa_ifu ; }
52
-
53
- #[ cfg( not( any( target_os = "linux" , target_os = "emscripten" , target_os = "fuchsia" ) ) ) ]
54
- { ifu = info. ifa_dstaddr ; }
55
-
60
+ let ifu = get_ifu_from_sockaddr ( info) ;
56
61
if addr. flags . contains ( IFF_POINTOPOINT ) {
57
62
addr. destination = unsafe { SockAddr :: from_libc_sockaddr ( ifu) } ;
58
63
} else if addr. flags . contains ( IFF_BROADCAST ) {
Original file line number Diff line number Diff line change @@ -706,7 +706,7 @@ impl SockAddr {
706
706
}
707
707
708
708
/// Creates a `SockAddr` struct from libc's sockaddr.
709
- pub unsafe fn from_libc_sockaddr ( addr : * mut libc:: sockaddr ) -> Option < SockAddr > {
709
+ pub unsafe fn from_libc_sockaddr ( addr : * const libc:: sockaddr ) -> Option < SockAddr > {
710
710
if addr. is_null ( ) {
711
711
None
712
712
} else {
You can’t perform that action at this time.
0 commit comments