public IPAddress GetIPAddress() { Win32_SOCKADDR win32_SOCKADDR = (Win32_SOCKADDR)Marshal.PtrToStructure(this.Sockaddr, typeof(Win32_SOCKADDR)); byte[] array; if (win32_SOCKADDR.AddressFamily == 23) { array = new byte[16]; Array.Copy(win32_SOCKADDR.AddressData, 6, array, 0, 16); } else { array = new byte[4]; Array.Copy(win32_SOCKADDR.AddressData, 2, array, 0, 4); } return(new IPAddress(array)); }
public IPAddress GetIPAddress() { Win32_SOCKADDR sa = (Win32_SOCKADDR)Marshal.PtrToStructure(Sockaddr, typeof(Win32_SOCKADDR)); //foreach (byte b in sa.AddressData) Console.Write ("{0:X02}", b); Console.WriteLine (); byte [] arr; if (sa.AddressFamily == AF_INET6) { arr = new byte [16]; Array.Copy(sa.AddressData, 6, arr, 0, 16); } else { arr = new byte [4]; Array.Copy(sa.AddressData, 2, arr, 0, 4); } //foreach (byte b in arr) Console.Write ("{0:X02}", b); Console.WriteLine (); return(new IPAddress(arr)); }