日期:2014-05-18  浏览次数:20756 次

这段C代码要如何转换成C#代码?
C代码:
....
struct   meterhdr   {       /*   Meter   header   format   */
  unsigned   long   rx_bytes;     /*   Received   bytes(increment)   */
  unsigned   long   tx_bytes;     /*   Transmitted   bytes(increment)   */
  unsigned   long   rx_packets;     /*   Received   packets(increment)   */
  unsigned   long   tx_packets;     /*   Transmitted   packets(increment)   */
};
..........................
cbBytesRead   =   recvfrom(listenSocket,(char   *)chRequest,BUFSIZE,0,(struct   sockaddr   *)&saCaller,&nLen);
.........................
meterHdr   =   (struct   meterhdr   *)chRequest;


---------------------------------
我的问题是C#中如何把读到的buffer   chRequest   强制转换成(struct   meterhdr   *)。不是很明白。谢谢!!!!


------解决方案--------------------
Byte[] byteReceived = host.Receive(ref ipe);
unsafe
{
fixed (byte* buffer = byteReceived)
{
meterhdr* mHdr = (meterhdr*)buffer;
}
}