From: Matt Corallo Date: Tue, 4 May 2021 22:06:13 +0000 (+0000) Subject: Switch to ToSocketAddrs to support connecting to hostnames not IPs X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=43092b875273841f3b19845a7bf3cb3e961d4cca;p=ldk-sample Switch to ToSocketAddrs to support connecting to hostnames not IPs --- diff --git a/src/cli.rs b/src/cli.rs index d7a76bc..d2d5a21 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -18,7 +18,7 @@ use lightning_invoice::{utils, Currency, Invoice}; use std::env; use std::io; use std::io::{BufRead, Write}; -use std::net::SocketAddr; +use std::net::{SocketAddr, ToSocketAddrs}; use std::ops::Deref; use std::path::Path; use std::str::FromStr; @@ -639,12 +639,12 @@ pub(crate) fn parse_peer_info( return Err(std::io::Error::new( std::io::ErrorKind::Other, "ERROR: incorrectly formatted peer - info. Should be formatted as: `pubkey@host:port`", + info. Should be formatted as: `pubkey@host:port`", )); } - let peer_addr: Result = peer_addr_str.unwrap().parse(); - if peer_addr.is_err() { + let peer_addr = peer_addr_str.unwrap().to_socket_addrs().map(|mut r| r.next()); + if peer_addr.is_err() || peer_addr.as_ref().unwrap().is_none() { return Err(std::io::Error::new( std::io::ErrorKind::Other, "ERROR: couldn't parse pubkey@host:port into a socket address", @@ -659,5 +659,5 @@ pub(crate) fn parse_peer_info( )); } - Ok((pubkey.unwrap(), peer_addr.unwrap())) + Ok((pubkey.unwrap(), peer_addr.unwrap().unwrap())) }