public static unsafe bool TryCopy(IntPtr source, long size, Sockaddr destination) { if (destination == null) { throw new ArgumentNullException("destination"); } byte[] array = Sockaddr.GetDynamicData(destination); fixed(SockaddrType *addr = &Sockaddr.GetAddress (destination).type) fixed(byte *data = Sockaddr.GetDynamicData(destination)) { var dyn = new _SockaddrDynamic(destination, data, useMaxLength: true); var r = ToSockaddr(source, size, Sockaddr.GetNative(&dyn, addr)); dyn.Update(destination); // SockaddrStorage has to be handled extra because the native code assumes that SockaddrStorage input is used in-place if (r == 0 && destination.type == (SockaddrType.SockaddrStorage | SockaddrType.MustBeWrapped)) { Marshal.Copy(source, array, 0, (int)destination.GetDynamicLength()); } return(r == 0); } }
public static unsafe bool TryCopy(Sockaddr source, IntPtr destination) { if (source == null) { throw new ArgumentNullException("source"); } byte[] array = Sockaddr.GetDynamicData(source); // SockaddrStorage has to be handled extra because the native code assumes that SockaddrStorage input is used in-place if (source.type == (SockaddrType.SockaddrStorage | SockaddrType.MustBeWrapped)) { Marshal.Copy(array, 0, destination, (int)source.GetDynamicLength()); return(true); } fixed(SockaddrType *addr = &Sockaddr.GetAddress (source).type) fixed(byte *data = array) { var dyn = new _SockaddrDynamic(source, data, useMaxLength: false); return(FromSockaddr(Sockaddr.GetNative(&dyn, addr), destination) == 0); } }