使用BitArray C#解码IPFIX数据包 [英] Decoding IPFIX packets using BitArray C#

查看:97
本文介绍了使用BitArray C#解码IPFIX数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接着我之前的线程,我似乎更接近使用C#中的UDP侦听器和BitArray从Sonicwall防火墙解码IPFIX数据.

Following on from my previous thread, I seem to be closer to decoding IPFIX data from a Sonicwall firewall using a UDP listener and a BitArray in C#.

我现在在我的BitArray中获取数据,但这没有任何意义-我以为我会在我的数组中看到二进制,但是我得到的值非常不同,例如8-10个字符,一些为正,一些为负,并且数组的计数总是变化.

I now get data in my BitArray but it doesnt make sense - I thought I would see binary in my array but I am getting values very different e.g. 8 - 10 characters some positive and some negative and the Count of the array always varies.

这是我用来获取位的代码的主要部分:

Here is the main part of the code I am using to get the bits:

byte[] bytes = listener.Receive(ref _myEndPoint);

BitArray bitarray = new BitArray(bytes);

有人知道我可以解码IPFIX数据还是有任何指针可以帮助我吗?

Does any one know of any way I can decode my IPFIX data or have any pointers that will help me?

预先感谢

詹姆斯

克里斯提供的代码输出:

Output from code supplied by Chris:

byte []个字节= {0x00、0x0A,0x04、0xB4、0x4D,0xAE,0x8F,0xF4、0x00、0x6D,0x8F,0xC7、0x16、0x2B,0xFC,0x00、0x01、0x01、0x04、0xA4 ,0xAE,0x8F,0xD2、0x8D,0xCC,0xC8、0x20、0x00、0x26、0x99、0xD4、0x5F,0xD7、0x30、0x37、0xA6、0xD6、0xBE,0xB9、0x51、0x90、0x90、0x90, ,0xE6、0x84、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x03、0x00、0x00、0x00、0x02、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 ,0x00、0x38、0x69、0x00、0x50、0x00、0x00、0x00、0x06、0x00、0x00、0x07、0xB3、0x00、0x00、0x00、0x04、0x00、0x00、0x03、0x42、0x00、0x00、0x00、0x00 ,0x00、0x00、0x03、0xC7、0x00、0x00、0x00、0x01、0x00、0x00、0x01、0x72、0x4D,0xAE,0x8F,0xD2、0x4D,0xAE,0x8F,0xF4、0x00、0x31、0x00 ,0x00、0x10、0x8F,0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 ,0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x0 0、0x82、0x00、0x00、0x01、0x4D,0xAE,0x8F,0xEE,0x8E,0x42、0xF9、0xA0、0x30、0x37、0xA6、0xD6、0xBE,0xB9、0x00、0x50、0x56、0x96 0x51、0x8D,0x42、0xFE,0x51、0x90、0xF3、0x46、0x51、0x90、0xF3、0x41、0x51、0x90、0xF3、0x41、0x00、0x00、0x00、0x02、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0xC5、0x85、0x00、0x50、0x00、0x00、0x00、0x18、0x00、0x00、0x09、0x6E,0x00、0x00、0x00、0x00、0x29、0x00 0xDF,0xE1、0x00、0x00、0x00、0x0B,0x00、0x00、0x04、0x86、0x00、0x00、0x00、0x14、0x00、0x00、0x6E,0x65、0x4D,0xAE,0x8F,0xEE,0x4D 0xF4、0x00、0x31、0x06、0x00、0x00、0x00、0x10、0x93、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x01、0x4D,0xAE,0x8F,0xF3、0x8E,0x5B,0x17、0xA0、0x00、0x00、0x00、0x00、0x00、0x00、0 x00、0x00、0x00、0x00、0x00、0x00、0x0A,0x00、0x01、0x55、0xC0、0xA8、0x6F,0x37、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x01、0x10、0x00、0x0A,0x01、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x0A,0xF8、0x23、0x8C,0x00、0x00、0x00、0x01、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x01、0x00、0x00、0x00、0x30、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0xAE,0x8F,0xF3、0x4D,0xAE,0x8F,0xF4、0x00、0x01、0x06、0x00、0x00、0x00、0xC0、0x2E,0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x44、0x00、0x00、0x00、0x4D,0xAE,0x8F,0xBE,0x8E,0xA0、0x53、0xA0、0x1C,0xC1、0xDE,0xA7、0x2D,0x37 0xA6、0xD6、0xBE,0xB9、0x0A,0x00、0x01、0x5A,0x4A,0xC9、0x75、0xF7、0x00、0x00、0x00、0x00、0x00, 0x00、0x00、0x00、0x00、0x00、0x00、0x01、0x00、0x00、0x00、0x02、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0xC3、0x8F,0x00、0x00、0x50、0x00 0x00、0x06、0x00、0x00、0x02、0xA4、0x00、0x00、0x00、0x04、0x00、0x00、0x04、0x07、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x4D,0xAE,0x8F,0xBE,0x4D,0xAE,0x8F,0xF4、0x00、0x03、0x06、0x00、0x00、0x00、0xC0、0x17、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x82、0x00、0x00、0x01、0x4D,0xAE,0x8F,0xB6、0x8D,0xCE,0x0A1、0x20、0x20 0xDE,0xA7、0x2D,0x01、0x30、0x37、0xA6、0xD6、0xBE,0xB9、0x0A,0x00、0x01、0x5A,0x5D,0xB8、0xDD,0x85、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x01、0x00、0x00、0x00、0x02、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x0 0、0xC3、0x77、0x00、0x50、0x00、0x00、0x00、0x04、0x00、0x00、0x00、0xBE,0x00、0x00、0x00、0x02、0x00、0x00、0x00、0x62、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x4D,0xAE,0x8F,0xB6、0x4D,0xAE,0x8F,0xF4、0x00、0x03、0x03、0x06 0x00、0xC0、0x17、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x82、0x00、0x00、0x00、0x4D,0xAE, 0xB6、0x8E,0x58、0xD0、0xE0、0x1C,0xC1、0xDE,0xA7、0x2D,0x01、0x30、0x37、0xA6、0xD6、0xBE,0xB9、0x0A,0x00、0x01、0x5、0x5、0x5、0x5、0x5、0x5、0x5、0x5、0x5、0x5、0x5 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x01、0x00、0x00、0x00、0x02、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x72、0x00、0x50、0x00、0x00、0x00、0x0D,0x00、0x00、0x04、0x86、0x00、0x00、0x00、0x17、0x00、0x00、0 x77、0x77、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x4D,0xAE,0x8F,0xB6、0x4D,0x8F 0xF4、0x00、0x03、0x06、0x00、0x00、0x00、0xC0、0x17、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x01、0x4D,0xAE,0x8F,0xB5、0x8E,0x95、0xA4、0x60、0x1C,0xC1、0xDE,0xA7、0x2D,0x01、0x30、0x37、0xA6、0xD6、0xA0 0x01、0x5A,0x40、0x98、0xD0、0x42、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x01、0x00、0x00、0x00、0x02、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0xC3、0x6E,0x00、0x50、0x00、0x00、0x00、0x07、0x00、0x00、0x05、0x7E,0x00、0x00、0x00、0x03、0x00、0x00、0x88、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x4D, 0xAE,0x8F,0xB5、0x4D,0xAE,0x8F,0xF4、0x00、0x03、0x06、0x00、0x00、0x00、0xC0、0x17、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x84、0x00、0x00、0x01、0x4D,0xAE,0x8F,0xB4、0x8E,0xDA,0xAB,0xE0、0x1C,0xC1、0xDE,0xA7、0x2D,0x37 0xA6、0xD6、0xBE,0xB9、0x0A,0x00、0x01、0x5A,0xD1、0x55、0x8F,0x60、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x02、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0xC3、0x5F,0x00、0x50、0x00、0x00、0x00、0x05、0x00、0x00、0x02、0x54、0x00 0x00、0x03、0x00、0x00、0x01、0x11、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x4D,0xAE,0xF 0xB4、0x4D,0xAE,0x8F,0xF4、0x00、0x03、0x06、0x00、0x00、0x00、0xC0、0x17、0x00、0x00、0x00、0x0 0、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00 0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x82、0x00、0x00、0x01};

byte[] bytes = {0x00, 0x0A, 0x04, 0xB4, 0x4D, 0xAE, 0x8F, 0xF4, 0x00, 0x6D, 0x8F, 0xC7, 0x16, 0x2B, 0xFC, 0x00, 0x01, 0x01, 0x04, 0xA4, 0x4D, 0xAE, 0x8F, 0xD2, 0x8D, 0xCC, 0xC8, 0x20, 0x00, 0x26, 0x99, 0xD4, 0x5F, 0xD7, 0x30, 0x37, 0xA6, 0xD6, 0xBE, 0xB9, 0x51, 0x90, 0xF3, 0x45, 0x4A, 0x7D, 0xE6, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x69, 0x00, 0x50, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x07, 0xB3, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x42, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x03, 0xC7, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x72, 0x4D, 0xAE, 0x8F, 0xD2, 0x4D, 0xAE, 0x8F, 0xF4, 0x00, 0x31, 0x06, 0x00, 0x00, 0x00, 0x10, 0x8F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x01, 0x4D, 0xAE, 0x8F, 0xEE, 0x8E, 0x42, 0xF9, 0xA0, 0x30, 0x37, 0xA6, 0xD6, 0xBE, 0xB9, 0x00, 0x50, 0x56, 0x96, 0x00, 0x00, 0x51, 0x8D, 0x42, 0xFE, 0x51, 0x90, 0xF3, 0x46, 0x51, 0x90, 0xF3, 0x41, 0x51, 0x90, 0xF3, 0x41, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0x85, 0x00, 0x50, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x09, 0x6E, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0xDF, 0xE1, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x04, 0x86, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x6E, 0x65, 0x4D, 0xAE, 0x8F, 0xEE, 0x4D, 0xAE, 0x8F, 0xF4, 0x00, 0x31, 0x06, 0x00, 0x00, 0x00, 0x10, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x01, 0x4D, 0xAE, 0x8F, 0xF3, 0x8E, 0x5B, 0x17, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x55, 0xC0, 0xA8, 0x6F, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xF8, 0x23, 0x8C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0xAE, 0x8F, 0xF3, 0x4D, 0xAE, 0x8F, 0xF4, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0xC0, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x4D, 0xAE, 0x8F, 0xBE, 0x8E, 0xA0, 0x53, 0xA0, 0x1C, 0xC1, 0xDE, 0xA7, 0x2D, 0x01, 0x30, 0x37, 0xA6, 0xD6, 0xBE, 0xB9, 0x0A, 0x00, 0x01, 0x5A, 0x4A, 0xC9, 0x75, 0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x8F, 0x00, 0x50, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x02, 0xA4, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0xAE, 0x8F, 0xBE, 0x4D, 0xAE, 0x8F, 0xF4, 0x00, 0x03, 0x06, 0x00, 0x00, 0x00, 0xC0, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x01, 0x4D, 0xAE, 0x8F, 0xB6, 0x8D, 0xCE, 0x0A, 0x20, 0x1C, 0xC1, 0xDE, 0xA7, 0x2D, 0x01, 0x30, 0x37, 0xA6, 0xD6, 0xBE, 0xB9, 0x0A, 0x00, 0x01, 0x5A, 0x5D, 0xB8, 0xDD, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x77, 0x00, 0x50, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xBE, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0xAE, 0x8F, 0xB6, 0x4D, 0xAE, 0x8F, 0xF4, 0x00, 0x03, 0x06, 0x00, 0x00, 0x00, 0xC0, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x4D, 0xAE, 0x8F, 0xB6, 0x8E, 0x58, 0xD0, 0xE0, 0x1C, 0xC1, 0xDE, 0xA7, 0x2D, 0x01, 0x30, 0x37, 0xA6, 0xD6, 0xBE, 0xB9, 0x0A, 0x00, 0x01, 0x5A, 0x58, 0xDD, 0x5E, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x72, 0x00, 0x50, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x04, 0x86, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0xAE, 0x8F, 0xB6, 0x4D, 0xAE, 0x8F, 0xF4, 0x00, 0x03, 0x06, 0x00, 0x00, 0x00, 0xC0, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x01, 0x4D, 0xAE, 0x8F, 0xB5, 0x8E, 0x95, 0xA4, 0x60, 0x1C, 0xC1, 0xDE, 0xA7, 0x2D, 0x01, 0x30, 0x37, 0xA6, 0xD6, 0xBE, 0xB9, 0x0A, 0x00, 0x01, 0x5A, 0x40, 0x98, 0xD0, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x6E, 0x00, 0x50, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x05, 0x7E, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0xAE, 0x8F, 0xB5, 0x4D, 0xAE, 0x8F, 0xF4, 0x00, 0x03, 0x06, 0x00, 0x00, 0x00, 0xC0, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x01, 0x4D, 0xAE, 0x8F, 0xB4, 0x8E, 0xDA, 0xAB, 0xE0, 0x1C, 0xC1, 0xDE, 0xA7, 0x2D, 0x01, 0x30, 0x37, 0xA6, 0xD6, 0xBE, 0xB9, 0x0A, 0x00, 0x01, 0x5A, 0xD1, 0x55, 0x8F, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x5F, 0x00, 0x50, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x02, 0x54, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0xAE, 0x8F, 0xB4, 0x4D, 0xAE, 0x8F, 0xF4, 0x00, 0x03, 0x06, 0x00, 0x00, 0x00, 0xC0, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x01};

推荐答案

能否给我们转储您收到的字节数据包之一?将数组传递给下面的代码,它将转储到输出窗口.这将帮助我们看到原始数据包.

Can you give us a dump of one of the byte packets that you're receiving? Pass the array to the code below and it will dump it to the output window. This will help us see a raw packet.

    private static string PrintByteArray(byte[] bytes){
        return "byte[] bytes = {0x" + BitConverter.ToString(bytes).Replace("-", ", 0x") + "};";
    }

您了解@Paul Sasik在回答解析数据时在说什么吗?该结构位于他链接的 RFC规范中.数据包的前两个字节(16位)将是版本号.我没有阅读过规范,但是字节可以用两种不同的方式写入,小而大的字节序.因此,根据规范,前两个字节应类似于0x00 0x0a0x0a 0x00.

Do you understand what @Paul Sasik was talking about in his answer for parsing the data? The structure is in the RFC spec that he linked to. The first two bytes (16 bits) of the packet will be the version number. I haven't read through the spec but bytes can be written in two different ways, little and big endian. So according to the spec the first two bytes should be something like 0x00 0x0a or 0x0a 0x00.

编辑

不要以位与字节的方式来思考,而只是认为后者是前者中8个的集合.

Don't think in terms of bits versus bytes, just that the latter is a collection of 8 of the former.

规范说,前16位(2字节)是与您所拥有的版本号匹配的版本号0x000a.然后,它说接下来的2个字节是整个消息的长度(以字节为单位)(实际上是八位字节,同样的意思).您的数据的0x04b4十进制为1204,这恰好是字节数组的长度.下一个字段是一个4字节字段,表示自1970年1月1日以来的导出时间(以秒为单位)(又名Unix/Posix时间).根据此站点,您有0x4dae8ff4十进制为1,303,285,748. .您可以使用下面的代码来解析邮件头.希望这会帮助您解析原始数据.

The spec says that the first 16 bits (2 bytes) are the version number 0x000a which matches what you have. It then says the next 2 bytes are the length of the entire message in bytes (it actually says octets, same thing). Your data has 0x04b4 which is 1204 in decimal which is exactly how long the byte array is. The next field is a 4 byte field for export time in seconds since Jan 1st, 1970 (aka Unix/Posix time). You have 0x4dae8ff4 which is 1,303,285,748 in decimal which according to this site is Wed, 20 Apr 2011 07:49:08 GMT. You can use the code below to parse the message header. Hopefully this will get you going on parsing the raw data.

    private static IPFIX ParseMessageHeader(byte[] bytes)
    {
        IPFIX ret = new IPFIX();
        ret.Version = ToUInt16BigEndian(bytes, 0);
        ret.Length = ToUInt16BigEndian(bytes, 2);
        ret.ExportTime = (new DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(ToUInt32BigEndian(bytes, 4));
        ret.SequenceNumber = ToUInt32BigEndian(bytes, 8);
        ret.ObservationDomainID = ToUInt32BigEndian(bytes, 12);
        ret.Sets = new List<Set>();
        Int32 CurOctet = 16;
        Set S;
        while (true)
        {
            S = new Set();
            S.SetId = ToUInt16BigEndian(bytes, CurOctet);
            S.Length = ToUInt16BigEndian(bytes, CurOctet + 2);
            S.data = bytes.Skip(CurOctet).Take(S.Length).ToArray();
            ret.Sets.Add(S);
            CurOctet += S.Length;
            if (CurOctet >= ret.Length)
            {
                break;
            }
        }

        return ret;
    }

    //These two functions are from here http://snipplr.com/view/15179/adapt-systembitconverter-to-handle-big-endian-network-byte-ordering-in-order-to-create-number-types-from-bytes-and-viceversa/
    //BitConverter.ToUInt16 would parse the results in "little endian" order so 0x000a would actually be parsed as 0x0a00 and give you 2,560 instead of 10.
    //The spec says that everything should be in "big endian" (also known as "network order"
    public static UInt16 ToUInt16BigEndian(byte[] value, int startIndex)
    {
        return System.BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(UInt16) - startIndex);
    }
    public static UInt32 ToUInt32BigEndian(byte[] value, int startIndex)
    {
        return System.BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(UInt32) - startIndex);
    }
    struct IPFIX
    {
        public UInt16 Version;
        public UInt16 Length;
        public DateTime ExportTime;
        public UInt32 SequenceNumber;
        public UInt32 ObservationDomainID;
        public List<Set> Sets;
    }
    struct Set
    {
        public UInt16 SetId;
        public UInt16 Length;
        public byte[] data;
        public SetType SetType
        {
            get
            {
                if (SetId == 2) return SetType.TemplateSet;
                if (SetId == 3) return SetType.OptionTemplate;
                if (SetId > 255) return SetType.DataSet;
                throw new ArgumentOutOfRangeException("SetId", "SetId not in expected range of 2, 3 or >255");
            }
        }

    }
    enum SetType { TemplateSet, OptionTemplate, DataSet };

要注意的一件事是字节序". Windows默认情况下将值解析为小尾数,但此处的所有值都需要按照规范解析为大尾数.普通的BitConvertor类在这里不起作用,因此上方有两个辅助函数可根据需要对其进行调整.另外,您会看到我使用的是UInt16UInt32而不是常规的int.这也是根据规范. Int16包含负数和正数,而UInt16则不具有两者的概念(尽管我们通常将其视为正数).

One thing to be careful of is "endian-ness". Windows parses values as little endian by default but all values here need to be parsed as big endian per spec. The normal BitConvertor class won't work here so there are two helper functions above that tweak it to work as needed. Also, you'll see that instead of regular ints I'm using UInt16 and UInt32. That's also per spec. An Int16 holds both negative and positive numbers while an UInt16 doesn't have the concept of either (although we generally think of it as positive).

这篇关于使用BitArray C#解码IPFIX数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆