From a4a8d936e8cc2b613d52c856928a996ef1646b6c Mon Sep 17 00:00:00 2001 From: dahall Date: Tue, 5 Jul 2022 14:25:00 -0600 Subject: [PATCH] Added conversion operators to SOCKADDR_STORAGE with SOCKADDR_INET --- PInvoke/Ws2_32/ws2def.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/PInvoke/Ws2_32/ws2def.cs b/PInvoke/Ws2_32/ws2def.cs index 30267507..af638262 100644 --- a/PInvoke/Ws2_32/ws2def.cs +++ b/PInvoke/Ws2_32/ws2def.cs @@ -1414,6 +1414,16 @@ namespace Vanara.PInvoke return mem.ToStructure(); } + /// Performs an explicit conversion from to . + /// The address. + /// The resulting instance from the conversion. + public static explicit operator SOCKADDR_STORAGE(SOCKADDR_INET addr) + { + using var mem = SafeHGlobalHandle.CreateFromStructure(addr); + mem.Size = Marshal.SizeOf(typeof(SOCKADDR_STORAGE)); + return mem.ToStructure(); + } + /// Performs an explicit conversion from to . /// The addr. /// The resulting instance from the conversion. @@ -1428,6 +1438,11 @@ namespace Vanara.PInvoke /// The addr. /// The resulting instance from the conversion. public static explicit operator SOCKADDR_IN6(SOCKADDR_STORAGE addr) => (SOCKADDR_IN6)SOCKADDR.CreateFromStructure(addr); + + /// Performs an explicit conversion from to . + /// The addr. + /// The resulting instance from the conversion. + public static explicit operator SOCKADDR_INET(SOCKADDR_STORAGE addr) => (SOCKADDR_INET)SOCKADDR.CreateFromStructure(addr); } /// The SOCKET_ADDRESS structure stores protocol-specific address information.