-
-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rust): converted socket addresses to hostnames in command
- Loading branch information
1 parent
d77cfff
commit bf4b56d
Showing
30 changed files
with
266 additions
and
313 deletions.
There are no files selected for viewing
24 changes: 1 addition & 23 deletions
24
examples/rust/mitm_node/src/tcp_interceptor/transport/common.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,7 @@ | ||
use ockam_core::compat::net::{SocketAddr, ToSocketAddrs}; | ||
use ockam_core::compat::net::SocketAddr; | ||
use ockam_core::Result; | ||
use ockam_transport_core::TransportError; | ||
|
||
/// Resolve the given peer to a [`SocketAddr`](std::net::SocketAddr) | ||
pub(super) fn resolve_peer(peer: String) -> Result<SocketAddr> { | ||
// Try to parse as SocketAddr | ||
if let Ok(p) = parse_socket_addr(&peer) { | ||
return Ok(p); | ||
} | ||
|
||
// Try to resolve hostname | ||
if let Ok(mut iter) = peer.to_socket_addrs() { | ||
// Prefer ip4 | ||
if let Some(p) = iter.find(|x| x.is_ipv4()) { | ||
return Ok(p); | ||
} | ||
if let Some(p) = iter.find(|x| x.is_ipv6()) { | ||
return Ok(p); | ||
} | ||
} | ||
|
||
// Nothing worked, return an error | ||
Err(TransportError::InvalidAddress(peer))? | ||
} | ||
|
||
pub(super) fn parse_socket_addr(s: &str) -> Result<SocketAddr> { | ||
Ok(s.parse().map_err(|_| TransportError::InvalidAddress(s.to_string()))?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.