Socket address

cli
E. Almqvist 2 years ago
parent 5a03b191e2
commit cb61dbe5c8
  1. 7
      src/ipv4.rs

@ -1,4 +1,4 @@
use std::net::{IpAddr, Ipv4Addr};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use anyhow::{Result, anyhow};
use convert_base::Convert;
@ -46,6 +46,11 @@ impl IPv4 {
Err(anyhow!("Unable to unpack IPv4 address"))
}
}
pub fn to_socketaddr(self: &mut Self, port: u16) -> Result<SocketAddr> {
let ip_addr = self.to_ipaddr()?;
Ok(SocketAddr::new(ip_addr, port))
}
}

Loading…
Cancel
Save