From cb61dbe5c8a9d623e974d8bdb1dbe6fb411b59a6 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 8 Aug 2022 16:04:29 +0200 Subject: [PATCH] Socket address --- src/ipv4.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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)) + } }