Kri*_*son 16 c++ logging hex hexdump
我使用网络和串行通信软件工作很多,因此我经常需要使用代码来显示或记录数据包的十六进制转储.
每次我这样做,我都会从头开始编写另一个hex-dump例程.我将要再次这样做,但我想在这里问:那里有什么好的C++自由十六进制转储代码吗?
我想要的功能:
编辑: 澄清:我正在寻找可以轻松插入我自己的程序的代码,以写入stderr,stdout,日志文件或其他此类输出流.我不是在寻找命令行十六进制转储实用程序.
epa*_*tel 39
我经常使用我很久以前写的这个小片段.在调试等时,它可以简单易用地添加到任何地方......
#include <ctype.h>
#include <stdio.h>
void hexdump(void *ptr, int buflen) {
unsigned char *buf = (unsigned char*)ptr;
int i, j;
for (i=0; i<buflen; i+=16) {
printf("%06x: ", i);
for (j=0; j<16; j++)
if (i+j < buflen)
printf("%02x ", buf[i+j]);
else
printf(" ");
printf(" ");
for (j=0; j<16; j++)
if (i+j < buflen)
printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.');
printf("\n");
}
}
Run Code Online (Sandbox Code Playgroud)
unix工具xxd是作为一部分分发的vim,根据http://www.vmunix.com/vim/util.html#xxd,xxd的源代码是ftp://ftp.uni-erlangen.de:21/pub /utilities/etc/xxd-1.10.tar.gz.它是用C语言编写的,大约是721行.给出的唯一许可信息是:
* Distribute freely and credit me,
* make money and share with me,
* lose money and don't ask me.
Run Code Online (Sandbox Code Playgroud)
unix工具hexdump可从http://gd.tuwien.ac.at/softeng/Aegis/hexdump.html获得.它是用C编写的,可以从源代码编译.它比xxd大很多,并且在GPL下分发.
| 归档时间: |
|
| 查看次数: |
15995 次 |
| 最近记录: |