导航

WINDOWS下用RAW Socket捕获IP包

#include
#include
#pragma comment(lib,"ws2_32.lib")

函数指针

函数指针,只可意会,不可言传。
如:
long (*pFuncOne) (int, int);
long SomeFunction (int, int);
pFuncOne = SomeFunction; //他们的参数个数、类型应该一致
pFuncOne(5,7); //:或者 (*pFuncOne)(5,7)效果一样的。

static用法小结【转载】

static关键字是C, C++中都存在的关键字, 它主要有三种使用方式, 其中前两种只指在C语言中使用, 第三种在C++中使用(C,C++中具体细微操作不尽相同, 本文以C++为准).
(1)局部静态变量
(2)外部静态变量/函数
(3)静态数据成员/成员函数
下面就这三种使用方式及注意事项分别说明

CONST的思考【转载】

1、什么是const?
常类型是指使用类型修饰符const说明的类型,常类型的变量或对象的值是不能被更新的。(当然,我们可以偷梁换柱进行更新:)

2、为什么引入const?
  const 推出的初始目的,正是为了取代预编译指令,消除它的缺点,同时继承它的优点。

libpcap主要接口函数

libpcap的英文意思是 Packet Capture library,即数据包捕获函数库。该库提供的C函数接口可用于需要捕获经过网络接口(只要经过该接口,目标地址不一定为本机)数据包的系统开发上。由 Berkeley大学Lawrence Berkeley National Laboratory研究院的Van Jacobson、Craig Leres和Steven McCanne编写。该函数库支持Linux、Solaris和*BSD系统平台。

FC6高速下载站点

不小心打算下FC6,又不小心找到了个速度非常快的下载站点,不敢独享,拿出来和大家分享。

总共5张碟,下载地址如下:
http://coblitz.codeen.org:3125/coblitz.planet-lab.org/pub/fedora/linux/core/6/i386/iso/FC-6-i386-disc1.iso
http://coblitz.codeen.org:3125/coblitz.planet-lab.org/pub/fedora/linux/core/6/i386/iso/FC-6-i386-disc2.iso
http://coblitz.codeen.org:3125/coblitz.planet-lab.org/pub/fedora/linux/core/6/i386/iso/FC-6-i386-disc3.iso

... ...

链接指示符extern "C"的使用

如果你希望在你的C++程序中调用C代码写的函数,那么你必须在你的函数调用之前告诉编译器:我要使用C代码写的函数了.
链接指示符(linkage directive)extern "C"的作用就是完成这个功能的,它有两种存在形式:一、 单一语句形式(single statement);二、复合语句形式(compound statement)。
// 单一语句形式的链接指示符

extern "C" int math(int);

Linux FAQ

date -s 11/11/2006 //:修改日期
今天运行程序,一会down掉。重新编译报错,找了好久原来是少个fclose()。纠正了还是报错,好久才猛然发现原来纠正的文件并没有被主程序include,而应该纠正内核里的同个文件,纠正后立马好了

GNU make笔记


makefile是一个文本形式的数据库文件,包含一些规则告诉make编译那些文件、怎样编译、以及在什么条件下去编译。
每条规则包含以下内容:
(1):一个“目标体”(target)
(2):一个或多个“依赖体”(dependency)
(2):“命令”(command)
如下makefile文件:

howdy: howdy.o helper.o helper.h
       gcc howdy.o helper.o -o howdy

    helper.o: helper.c helper.h
       gcc -c helper.c

    howdy.o: howdy.c
       gcc -c howdy.c
 
    hello: hello.c
    gcc hello.c -o hello

    all: howdy hello

    .PHONY : clean

    clean:
       rm howdy hello *.o

GCC编程笔记

$gcc hello.c -o hello

$gcc -E hello.c -o hello.cpp /* -E选项表示预处理后停止编译*/
$gcc -x cpp-output -c hello.cpp -o hello.o /*编译成目标代码*/
$gcc hello.o -o hello /*链接*/

$gcc 1.c 2.c -o file /*链接,-o选项默认生成file为a.out*/

$gcc myapp.c -I /home/fred/include -o myapp
$gcc myapp.c -L/home/fred/lib -lnew -o myapp
/*GCC默认使用共享库连接,如果需要静态库用-static参数*/

/*-ansi,-pedantic,-pedantic-errors,-Wall用于让编译器能够报错*/
/*-O选项进行对代码的优化*/

$gcc -g hello.c -o hello /* -g,-ggdb调试*/


内联函数:

使用内联函数需要用关键字inline.还要用-O优化选项,如:
inline void swap(int *a,int *b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}


函数和变量属性:

使用关键字attribute,如:
声明:void die_on_error(void) _attribute_ ((noreturn));/*表示无返回类型*/
定义:void die_on_error(void) /*定义和平常一样*/
int int_var _attribute_ ((aligned 16)) = 0; /*让变量int_var的边界按16字节对齐*/
float big_salary _attribute_ ((unused)); /*关闭对未用变量发出的所有警告*/


构造函数名称:

GCC预先定义_FUNCTION_为当前函数.在调试代码难以确定出错位置时很有用.
如:
在swap()函数的代码中加入一句:
printf("The current function is %s\n",_FUNCTION_);
则显示结果为:
The current function is swap.
分页:[«] 1[2] [»]

Powered By SunK

Copyright 2005-2006 sunk.cn 蜀ICP备06007105号