@@ -46,6 +46,7 @@ use core::fmt::Debug;
46
46
use core:: ops:: Deref ;
47
47
#[ cfg( feature = "std" ) ]
48
48
use core:: str:: FromStr ;
49
+ use std:: net:: SocketAddr ;
49
50
use crate :: io:: { self , Cursor , Read } ;
50
51
use crate :: io_extras:: read_to_end;
51
52
@@ -960,26 +961,31 @@ impl From<std::net::SocketAddr> for SocketAddress {
960
961
961
962
#[ cfg( feature = "std" ) ]
962
963
impl std:: net:: ToSocketAddrs for SocketAddress {
963
- type Iter = std:: option :: IntoIter < std:: net:: SocketAddr > ;
964
+ type Iter = std:: vec :: IntoIter < std:: net:: SocketAddr > ;
964
965
965
966
fn to_socket_addrs ( & self ) -> std:: io:: Result < Self :: Iter > {
966
967
match self {
967
968
SocketAddress :: TcpIpV4 { addr, port } => {
968
969
let ip_addr = std:: net:: Ipv4Addr :: from ( * addr) ;
969
- ( ip_addr, * port) . to_socket_addrs ( )
970
+ let socket_addr = SocketAddr :: new ( ip_addr. into ( ) , * port) ;
971
+ Ok ( vec ! [ socket_addr] . into_iter ( ) )
970
972
}
971
973
SocketAddress :: TcpIpV6 { addr, port } => {
972
974
let ip_addr = std:: net:: Ipv6Addr :: from ( * addr) ;
973
- ( ip_addr, * port) . to_socket_addrs ( )
975
+ let socket_addr = SocketAddr :: new ( ip_addr. into ( ) , * port) ;
976
+ Ok ( vec ! [ socket_addr] . into_iter ( ) )
974
977
}
975
978
SocketAddress :: Hostname { ref hostname, port } => {
976
- Ok ( ( hostname. as_str ( ) , * port) . to_socket_addrs ( ) ?. next ( ) . into_iter ( ) )
979
+ let socket_addr: Vec < SocketAddr > = ( hostname. as_str ( ) , * port) . to_socket_addrs ( ) ?. collect ( ) ;
980
+ Ok ( socket_addr. into_iter ( ) )
977
981
}
978
982
SocketAddress :: OnionV2 ( ..) => {
979
- Err ( std:: io:: Error :: from ( std:: io:: ErrorKind :: Other ) )
983
+ Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , "Resolution of these \
984
+ addresses is currently unsupported.") )
980
985
}
981
986
SocketAddress :: OnionV3 { .. } => {
982
- Err ( std:: io:: Error :: from ( std:: io:: ErrorKind :: Other ) )
987
+ Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , "Resolution of these \
988
+ addresses is currently unsupported.") )
983
989
}
984
990
}
985
991
}
0 commit comments