在pcap_compile 函数中
root = NULL; // root就是 struct block的指针
...中间没有对root 操作,有必要判断吗? 有必要的
中间的
***** (void)pcap_parse(); *******
if (root == NULL) /* 全局的block 结构 */
root = gen_retblk(snaplen);
program->bf_insns = icode_to_fcode(root, &len); // root 作为参数的调用
---------------------------------------------------------
下面来认识一下这个结构
struct block {
int id;
struct
slist *stmts; /* side effect stmts */
struct stmt s; /* branch stmt 分支语句
*/
int mark;
int longjt;
/* jt branch requires long jump */
int longjf; /* jf branch requires
long jump */
int level;
int
offset;
int sense;
struct edge et;
// edge true
struct edge ef; // edge false
struct block *head; // 指向head部 , 如果没有其他block 则指向自身
struct block *link; /* link field used by optimizer
*/
uset dom; // uset的定义 typedef bpf_u_int32
*uset;
uset closure;
struct edge
*in_edges;
atomset def, kill; // typedef bpf_u_int32
*uset; 定义
atomset in_use;
atomset
out_use;
int oval;
int val[N_ATOMS];
// #define N_ATOMS (BPF_MEMWORDS+2) = 18
};
-------------------------------------------------------------------------------------
optimize.c:icode_to_fcode(root, lenp) pcap虚拟机的重要级函数
libpcap 中的 struct block,布布扣,bubuko.com
原文:http://www.cnblogs.com/kwingmei/p/3627413.html