@@ -44,6 +44,7 @@ use core::fmt;
4444use core:: fmt:: Debug ;
4545use core:: ops:: Deref ;
4646use core:: str:: FromStr ;
47+ use std:: net:: SocketAddr ;
4748use crate :: io:: { self , Cursor , Read } ;
4849use crate :: io_extras:: read_to_end;
4950
@@ -958,26 +959,31 @@ impl From<std::net::SocketAddr> for SocketAddress {
958959
959960#[ cfg( feature = "std" ) ]
960961impl std:: net:: ToSocketAddrs for SocketAddress {
961- type Iter = std:: option :: IntoIter < std:: net:: SocketAddr > ;
962+ type Iter = std:: vec :: IntoIter < std:: net:: SocketAddr > ;
962963
963964 fn to_socket_addrs ( & self ) -> std:: io:: Result < Self :: Iter > {
964965 match self {
965966 SocketAddress :: TcpIpV4 { addr, port } => {
966967 let ip_addr = std:: net:: Ipv4Addr :: from ( * addr) ;
967- ( ip_addr, * port) . to_socket_addrs ( )
968+ let socket_addr = SocketAddr :: new ( ip_addr. into ( ) , * port) ;
969+ Ok ( vec ! [ socket_addr] . into_iter ( ) )
968970 }
969971 SocketAddress :: TcpIpV6 { addr, port } => {
970972 let ip_addr = std:: net:: Ipv6Addr :: from ( * addr) ;
971- ( ip_addr, * port) . to_socket_addrs ( )
973+ let socket_addr = SocketAddr :: new ( ip_addr. into ( ) , * port) ;
974+ Ok ( vec ! [ socket_addr] . into_iter ( ) )
972975 }
973976 SocketAddress :: Hostname { ref hostname, port } => {
974- Ok ( ( hostname. as_str ( ) , * port) . to_socket_addrs ( ) ?. next ( ) . into_iter ( ) )
977+ let socket_addr: Vec < SocketAddr > = ( hostname. as_str ( ) , * port) . to_socket_addrs ( ) ?. collect ( ) ;
978+ Ok ( socket_addr. into_iter ( ) )
975979 }
976980 SocketAddress :: OnionV2 ( ..) => {
977- Err ( std:: io:: Error :: from ( std:: io:: ErrorKind :: Other ) )
981+ Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , "Resolution of these \
982+ addresses is currently unsupported.") )
978983 }
979984 SocketAddress :: OnionV3 { .. } => {
980- Err ( std:: io:: Error :: from ( std:: io:: ErrorKind :: Other ) )
985+ Err ( std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , "Resolution of these \
986+ addresses is currently unsupported.") )
981987 }
982988 }
983989 }
0 commit comments