📄 hex.c
字号:
/* This file is part of sniffer, a packet capture utility and network moniter The author can be contacted at <mistral@stev.org> the lastest version is avilable from http://stev.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "config.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include "hex.h"/******************************************************* Log Hex ***************************************************************************//* this will return a pointer to a string *//* full of the stuff to print it will have a null on the end *//* do not forget to free the data *//* will return null if there is an error */char *hex_conv(char *data, int length) { int i; int g; char *pointer; char *buff; char *buff_p; /* the pointer to find out where to print to */ if (length == 0) return NULL; buff = malloc(length * 80); if (!buff) return NULL; buff_p = buff; pointer = data; while( pointer < data + length) { buff_p += sprintf(buff_p, "\t"); i = 0; while (pointer + i < data + length && i < 15) { buff_p += sprintf(buff_p, "%.2x ", pointer[i] & 0xFF ); i++; } if (i < 15) /* put spaces until we catch up to the data line */ for(g=i;g<15;g++) buff_p += sprintf(buff_p, " "); buff_p += sprintf(buff_p, "\t"); i = 0; while (pointer + i < data + length && i < 15) { if (pointer[i] > 0x20 && pointer[i] < 0x7E) { buff_p += sprintf(buff_p, "%c", pointer[i]); } else { buff_p += sprintf(buff_p, "."); } i++; } buff_p += sprintf(buff_p, "\n"); pointer += 15; } return buff;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -