Fix netutils test (#10842)
This commit is contained in:
parent
cabedc0f36
commit
3a3b7a399a
|
@ -4386,6 +4386,7 @@ dependencies = [
|
||||||
"solana-version",
|
"solana-version",
|
||||||
"tokio 0.1.22",
|
"tokio 0.1.22",
|
||||||
"tokio-codec",
|
"tokio-codec",
|
||||||
|
"url 2.1.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -23,6 +23,7 @@ solana-logger = { path = "../logger", version = "1.3.0" }
|
||||||
solana-version = { path = "../version", version = "1.3.0" }
|
solana-version = { path = "../version", version = "1.3.0" }
|
||||||
tokio = "0.1"
|
tokio = "0.1"
|
||||||
tokio-codec = "0.1"
|
tokio-codec = "0.1"
|
||||||
|
url = "2.1.1"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "solana_net_utils"
|
name = "solana_net_utils"
|
||||||
|
|
|
@ -7,6 +7,7 @@ use std::io::{self, Read, Write};
|
||||||
use std::net::{IpAddr, SocketAddr, TcpListener, TcpStream, ToSocketAddrs, UdpSocket};
|
use std::net::{IpAddr, SocketAddr, TcpListener, TcpStream, ToSocketAddrs, UdpSocket};
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
mod ip_echo_server;
|
mod ip_echo_server;
|
||||||
use ip_echo_server::IpEchoServerMessage;
|
use ip_echo_server::IpEchoServerMessage;
|
||||||
|
@ -298,6 +299,14 @@ pub fn parse_port_range(port_range: &str) -> Option<PortRange> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_host(host: &str) -> Result<IpAddr, String> {
|
pub fn parse_host(host: &str) -> Result<IpAddr, String> {
|
||||||
|
// First, check if the host syntax is valid. This check is needed because addresses
|
||||||
|
// such as `("localhost:1234", 0)` will resolve to IPs on some networks.
|
||||||
|
let parsed_url = Url::parse(&format!("http://{}", host)).map_err(|e| e.to_string())?;
|
||||||
|
if parsed_url.port().is_some() {
|
||||||
|
return Err(format!("Expected port in URL: {}", host));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next, check to see if it resolves to an IP address
|
||||||
let ips: Vec<_> = (host, 0)
|
let ips: Vec<_> = (host, 0)
|
||||||
.to_socket_addrs()
|
.to_socket_addrs()
|
||||||
.map_err(|err| err.to_string())?
|
.map_err(|err| err.to_string())?
|
||||||
|
|
Loading…
Reference in New Issue