@@ -44,6 +44,7 @@ use core::fmt;
44
44
use core:: fmt:: Debug ;
45
45
use core:: ops:: Deref ;
46
46
use core:: str:: FromStr ;
47
+ use std:: net:: SocketAddr ;
47
48
use crate :: io:: { self , Cursor , Read } ;
48
49
use crate :: io_extras:: read_to_end;
49
50
@@ -958,26 +959,31 @@ impl From<std::net::SocketAddr> for SocketAddress {
958
959
959
960
#[ cfg( feature = "std" ) ]
960
961
impl std:: net:: ToSocketAddrs for SocketAddress {
961
- type Iter = std:: option :: IntoIter < std:: net:: SocketAddr > ;
962
+ type Iter = std:: vec :: IntoIter < std:: net:: SocketAddr > ;
962
963
963
964
fn to_socket_addrs ( & self ) -> std:: io:: Result < Self :: Iter > {
964
965
match self {
965
966
SocketAddress :: TcpIpV4 { addr, port } => {
966
967
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 ( ) )
968
970
}
969
971
SocketAddress :: TcpIpV6 { addr, port } => {
970
972
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 ( ) )
972
975
}
973
976
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 ( ) )
975
979
}
976
980
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.") )
978
983
}
979
984
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.") )
981
987
}
982
988
}
983
989
}
0 commit comments