摘要: inline 定义一个函数时最好前面再加上static;static inline 定义的函数,会在链接阶段将代码段中没有使用的inline 函数定义“剔除”,从而减小编译体积;即使加了-g参数仍然如此;如果没有加上static 则不会有这种剔除;即使加了 -s 参数仍然如此;所以对于一个公用的inline函数,以static inline的方式定义在头文件中是自然而然的了; 阅读全文
posted @ 2013-10-05 01:12 庄庄庄 阅读(282) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stdarg.h>/* 该函数ret = min(size, 实际写入长度) - 1,即ret永远小于size * scnprintf(NULL, ...) -> segment err * scnprintf(str, 0, ...) -> -1 * scnprintf(str, 1, ...) -> 0 * scnprintf(str, size, "%s", NULL) <==> scnprintf(str, size, "%s", &qu 阅读全文
posted @ 2013-06-18 02:34 庄庄庄 阅读(1309) 评论(0) 推荐(0) 编辑
摘要: proc h2d {{hex_num 0}} { return [format "%d" 0x$hex_num]}proc d2h {{dec_num 0} {width 1}} { return [format "%0${width}x" $dec_num]}set dbg_switch closeproc dbg {{switch 0}} { global dbg_switch if {"$switch" == "open" || "$switch" == "close" 阅读全文
posted @ 2013-05-30 01:14 庄庄庄 阅读(576) 评论(0) 推荐(0) 编辑
摘要: 常用端口(1)端口号码 / 层名称注释1tcpmuxTCP 端口服务多路复用5rje远程作业入口7echoEcho 服务9discard用于连接测试的空服务11systat用于列举连接了的端口的系统状态13daytime给请求主机发送日期和时间17qotd给连接了的主机发送每日格言18msp消息发送协议19chargen字符生成服务;发送无止境的字符流20ftp-dataFTP 数据端口21ftp文件传输协议(FTP)端口;有时被文件服务协议(FSP)使用22ssh安全 Shell(SSH)服务23telnetTelnet 服务25smtp简单邮件传输协议(SMTP)37time时间协议39r 阅读全文
posted @ 2013-01-05 23:35 庄庄庄 阅读(432) 评论(0) 推荐(0) 编辑
摘要: #include <windows.h>void cls( HANDLE hConsole ){ COORD coordScreen = { 0, 0 }; // home for the cursor DWORD cCharsWritten; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD dwConSize;// Get the number of character cells in the current buffer. if( !GetConsoleScreenBufferInfo( hConsole, &csbi )) ... 阅读全文
posted @ 2013-01-04 23:47 庄庄庄 阅读(774) 评论(1) 推荐(0) 编辑
摘要: #ifndef _MYDBG_H_#define _MYDBG_H_static int dbg_switch = 0;static inline void open_dbg(void){ dbg_switch = 1;}static inline void close_dbg(void){ dbg_switch = 0;}static inline int test_dbg(void){ return dbg_switch;}/* fmt 必须是常量字符串 */#define dbg_printf(A,fmt,...) \do{\ if(A && dbg_switch... 阅读全文
posted @ 2012-12-29 21:43 庄庄庄 阅读(289) 评论(2) 推荐(0) 编辑
摘要: 如何定义变长tlv结构体TLV是一种常用的用于通信的结构体格式。T表示tag,L表示length,V表示value。其中T和L是固定大小的,V是可变大小,L表示的是V的长度。通常用于结构化网络通信中的数据流。如0x3 3 'aa\0',0x3 5 'aaaa\0',其中0x3表示tag的值,3 or 5表示的是后面的字符串的长度。由于V是可变长度的,所以在定义TLV结构时,需要将V定义成为可变大小。可定义如下:struct TLV{ uint8_t tag; uint16_t len; char value[0];}__attribute__((packed)) 阅读全文
posted @ 2012-12-27 00:02 庄庄庄 阅读(1364) 评论(0) 推荐(0) 编辑
摘要: 以下是Linux系统调用的一个列表,包含了大部分常用系统调用和由系统调用派生出的的函数。这可能是你在互联网上所能看到的唯一一篇中文注释的Linux系统调用列表,即使是简单的字母序英文列表,能做到这么完全也是很罕见的。 按照惯例,这个列表以man pages第2节,即系统调用节为蓝本。按照笔者的理解,对其作了大致的分类,同时也作了一些小小的修改,删去了几个仅供内核使用,不允许用户调用的系统调用,对个别本人稍觉不妥的地方作了一些小的修改,并对所有列出的系统调用附上简要注释。 其中有一些函数的作用完全相同,只是参数不同。(可能很多熟悉C++朋友马上就能联想起函数重载,但是别忘了Linux... 阅读全文
posted @ 2012-12-21 23:14 庄庄庄 阅读(213) 评论(0) 推荐(0) 编辑
摘要: strtok 源码分析:char * __cdecl strtok ( char * string, const char * control ){ unsigned char *str; const unsigned char *ctrl = control; unsigned char map[32]; int count; static char *nextoken; /* Clear control map */ for (count = 0; c... 阅读全文
posted @ 2012-11-24 12:13 庄庄庄 阅读(438) 评论(0) 推荐(0) 编辑
摘要: 00401292 <_main>:int main(int argc, char **argv){ 401292: 55 push %ebp 401293: 89 e5 mov %esp,%ebp 401295: 83 ec 18 sub $0x18,%esp 401298: 83 e4 f0 and $0xfffffff0,%esp 40129b: b8 00 00 00 00 mov $0x0,%eax 4012a0... 阅读全文
posted @ 2012-11-23 23:44 庄庄庄 阅读(480) 评论(0) 推荐(0) 编辑