+/// Essentially SocketAddr but without a traffic class or scope
+#[derive(Clone, PartialEq, Eq, Hash)]
+enum SockAddr {
+ V4(SocketAddrV4),
+ V6((Ipv6Addr, u16)),
+}
+impl From<SocketAddr> for SockAddr {
+ fn from(addr: SocketAddr) -> SockAddr {
+ match addr {
+ SocketAddr::V4(sa) => SockAddr::V4(sa),
+ SocketAddr::V6(sa) => SockAddr::V6((sa.ip().clone(), sa.port())),
+ }
+ }
+}
+impl Into<SocketAddr> for &SockAddr {
+ fn into(self) -> SocketAddr {
+ match self {
+ &SockAddr::V4(sa) => SocketAddr::V4(sa),
+ &SockAddr::V6(sa) => SocketAddr::V6(SocketAddrV6::new(sa.0, sa.1, 0, 0))
+ }
+ }
+}
+impl ToString for SockAddr {
+ fn to_string(&self) -> String {
+ let sa: SocketAddr = self.into();
+ sa.to_string()
+ }
+}
+impl SockAddr {
+ pub fn port(&self) -> u16 {
+ match *self {
+ SockAddr::V4(sa) => sa.port(),
+ SockAddr::V6((_, port)) => port,
+ }
+ }
+ pub fn ip(&self) -> IpAddr {
+ match *self {
+ SockAddr::V4(sa) => IpAddr::V4(sa.ip().clone()),
+ SockAddr::V6((ip, _)) => IpAddr::V6(ip),
+ }
+ }
+}
+