@@ -46,6 +46,7 @@ use core::fmt::Debug;
4646use core:: ops:: Deref ;
4747#[ cfg( feature = "std" ) ]
4848use core:: str:: FromStr ;
49+ use std:: net:: SocketAddr ;
4950use crate :: io:: { self , Cursor , Read } ;
5051use crate :: io_extras:: read_to_end;
5152
@@ -960,26 +961,31 @@ impl From<std::net::SocketAddr> for SocketAddress {
960961
961962#[ cfg( feature = "std" ) ]
962963impl std:: net:: ToSocketAddrs for SocketAddress {
963- type Iter = std:: option :: IntoIter < std:: net:: SocketAddr > ;
964+ type Iter = std:: vec :: IntoIter < std:: net:: SocketAddr > ;
964965
965966 fn to_socket_addrs ( & self ) -> std:: io:: Result < Self :: Iter > {
966967 match self {
967968 SocketAddress :: TcpIpV4 { addr, port } => {
968969 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 ( ) )
970972 }
971973 SocketAddress :: TcpIpV6 { addr, port } => {
972974 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 ( ) )
974977 }
975978 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 ( ) )
977981 }
978982 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.") )
980985 }
981986 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.") )
983989 }
984990 }
985991 }
0 commit comments