File tree Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Original file line number Diff line number Diff line change @@ -55,16 +55,9 @@ impl SockAddr {
55
55
/// Returns this address as a `SocketAddr` if it is in the `AF_INET` (IP v4)
56
56
/// or `AF_INET6` (IP v6) family, otherwise returns `None`.
57
57
pub fn as_std ( & self ) -> Option < SocketAddr > {
58
- let storage: * const sockaddr_storage = ( & self . storage ) as * const _ ;
59
- match self . storage . ss_family as c_int {
60
- AF_INET => Some ( SocketAddr :: V4 ( unsafe {
61
- * ( storage as * const sockaddr_in as * const _ )
62
- } ) ) ,
63
- AF_INET6 => Some ( SocketAddr :: V6 ( unsafe {
64
- * ( storage as * const sockaddr_in6 as * const _ )
65
- } ) ) ,
66
- _ => None ,
67
- }
58
+ self . as_inet ( )
59
+ . map ( |a| a. into ( ) )
60
+ . or_else ( || self . as_inet6 ( ) . map ( |a| a. into ( ) ) )
68
61
}
69
62
70
63
/// Returns this address as a `SocketAddrV4` if it is in the `AF_INET`
You can’t perform that action at this time.
0 commit comments