Netfilter代码在初始化initial_table表的时候,针对里面的数组成员,使用了如下的初始化方式:
struct ebt_replace_kernel { char name[EBT_TABLE_MAXNAMELEN]; unsigned int valid_hooks; /* nr of rules in the table */ unsigned int nentries; /* total size of the entries */ unsigned int entries_size; /* start of the chains */ struct ebt_entries *hook_entry[NF_BR_NUMHOOKS]; /* nr of counters userspace expects back */ unsigned int num_counters; /* where the kernel will put the old counters */ struct ebt_counter *counters; char *entries; };
|
static struct ebt_replace_kernel initial_table = { .name = "filter", .valid_hooks = FILTER_VALID_HOOKS, .entries_size = 3 * sizeof(struct ebt_entries), .hook_entry = { [NF_BR_LOCAL_IN] = &initial_chains[0], [NF_BR_FORWARD] = &initial_chains[1], [NF_BR_LOCAL_OUT] = &initial_chains[2], }, .entries = (char *)initial_chains, };
|
即在初始化数组的时候使用了[NF_BR_LOCAL_IN] = &initial_chains[0];的形式。可能有些朋友对这种方式还不太熟悉。
下面是我以前写的一个相似的代码:
#include<stdio.h> #include<stdlib.h>
struct A { char name[10]; int a1; int a2; int a3; int arr[5]; };
struct B { struct A testa; }structb = { { "test1", 10, 20, 30, { [1] = 100, [2] = 200, [3] = 300, [4] = 400, } } };
int main() { int i; for(i = 0; i < 5; i++) printf("%d\n", structb.testa.arr[i]); return 0; }
|
阅读(16608) | 评论(0) | 转发(0) |