解析二进制数据用C? [英] Parsing Binary Data in C?

查看:120
本文介绍了解析二进制数据用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有如何阅读和使用C解析二进制数据?任何库或指南

Are there any libraries or guides for how to read and parse binary data in C?

我在看一些功能,将网络套接字接收TCP数据包,然后根据规范解析二进制数据,由code转动信息融入了更多可用的形式。

I am looking at some functionality that will receive TCP packets on a network socket and then parse that binary data according to a specification, turning the information into a more useable form by the code.

有没有做到这一点的所有库在那里,甚至在执行这种类型的事情底漆?

Are there any libraries out there that do this, or even a primer on performing this type of thing?

推荐答案

标准方式C / C ++是真正铸造结构为gwaredd建议这样做。

The standard way to do this in C/C++ is really casting to structs as 'gwaredd' suggested

这并不像人们想象的那么不安全。你先投给你意料之中的,因为在他/她的例子结构,,然后您测试结构的有效性。你要测试的最大/最小值,终止序列等。

It is not as unsafe as one would think. You first cast to the struct that you expected, as in his/her example, then you test that struct for validity. You have to test for max/min values, termination sequences, etc.

http://mixter.void.ru/rawip.html 使用原始套接字一个简单的例子。

Checkout http://mixter.void.ru/rawip.html for a quick example using raw sockets.

什么都你的平台上,你必须阅读 UNIX网络编程卷1:套接字联网API 。买吧,借用它,窃取它(受害者就会明白,这就像偷菜什么的...),但不要读它。

What ever platform you are on you must read Unix Network Programming, Volume 1: The Sockets Networking API. Buy it, borrow it, steal it ( the victim will understand, it's like stealing food or something... ), but do read it.

阅读史蒂文斯​​后,大部分的这将使很多更有意义。

After reading the Stevens, most of this will make a lot more sense.

这篇关于解析二进制数据用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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