Function mles_utils::addr2str
[−]
[src]
pub fn addr2str(addr: &SocketAddr) -> String
Do a valid UTF-8 string from a SocketAddr
.
For IPv4 the format is "x.x.x.x:y", where x is u8 and y is u16 For IPv6 the format is "[z:z:z:z:z:z:z:z]:y", where z is u16 in hexadecimal format and y is u16
Example
use std::net::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr}; use mles_utils::addr2str; let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); let addrstr = addr2str(&addr); assert_eq!("127.0.0.1:8080", addrstr); let addr = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0xff03, 0, 0, 0, 0, 0, 0, 1)), 8077); let addrstr = addr2str(&addr); assert_eq!("[ff03:0:0:0:0:0:0:1]:8077", addrstr);