Use Marshal.PtrToStructure
:
var bytes = yourUnmanagedByteArray;
fixed (byte* b = bytes)
return (T)Marshal.PtrToStructure(new IntPtr(b), typeof(DivertIPv6Header));
You could make it work without a fixed
buffer too, if you don't want to use unsafe
code.