As you can see, we use the System.IO.MemoryStream and System.IO.BinaryReader to read data in perfectly managed code. This approach may seem like a lot of work but you end up writing less code in your main app if you do it this way. It doesn’t copy memory around from unmaged space to managed and back like Marshal.Copy would for instance and you don’t have to worry about freeing up pointers from memory either.
UShortNTOHS is the ntohs function that comes with the samples. The System.Net.Ipaddress.NetworkToHostOrder function does NOT work with unsigned shorts and you get weird results with anything other than UShort so stick to this.
So there you have it. Just one approach to solving the problem. It works very well for me. Feel free to share your expereince in this.