diff --git a/src/ipv4.rs b/src/ipv4.rs index 5c1a031..1f5763a 100644 --- a/src/ipv4.rs +++ b/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 { + let ip_addr = self.to_ipaddr()?; + Ok(SocketAddr::new(ip_addr, port)) + } }