- 论坛徽章:
- 0
|
今天看内核中neitfilter部分的代码,在iptable_filter.c中有这样的变量:
- static struct
- {
- struct ipt_replace repl;
- struct ipt_standard entries[3];
- struct ipt_error term;
- } initial_table __initdata
- = { { "filter", FILTER_VALID_HOOKS, 4,
- sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error),
- { [NF_IP_LOCAL_IN] 0,
- [NF_IP_FORWARD] sizeof(struct ipt_standard),
- [NF_IP_LOCAL_OUT] sizeof(struct ipt_standard) * 2 },
- { [NF_IP_LOCAL_IN] 0,
- [NF_IP_FORWARD] sizeof(struct ipt_standard),
- [NF_IP_LOCAL_OUT] sizeof(struct ipt_standard) * 2 },
- 0, NULL, { } },
- {
- /* LOCAL_IN */
- { { { { 0 }, { 0 }, { 0 }, { 0 }, "", "", { 0 }, { 0 }, 0, 0, 0 },
- 0,
- sizeof(struct ipt_entry),
- sizeof(struct ipt_standard),
- 0, { 0, 0 }, { } },
- { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
- -NF_ACCEPT - 1 } },
- /* FORWARD */
- { { { { 0 }, { 0 }, { 0 }, { 0 }, "", "", { 0 }, { 0 }, 0, 0, 0 },
- 0,
- sizeof(struct ipt_entry),
- sizeof(struct ipt_standard),
- 0, { 0, 0 }, { } },
- { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
- -NF_ACCEPT - 1 } },
- /* LOCAL_OUT */
- { { { { 0 }, { 0 }, { 0 }, { 0 }, "", "", { 0 }, { 0 }, 0, 0, 0 },
- 0,
- sizeof(struct ipt_entry),
- sizeof(struct ipt_standard),
- 0, { 0, 0 }, { } },
- { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
- -NF_ACCEPT - 1 } }
- },
- /* ERROR */
- { { { { 0 }, { 0 }, { 0 }, { 0 }, "", "", { 0 }, { 0 }, 0, 0, 0 },
- 0,
- sizeof(struct ipt_entry),
- sizeof(struct ipt_error),
- 0, { 0, 0 }, { } },
- { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
- { } },
- "ERROR"
- }
- }
- };
复制代码
其中的结构体定义struct ipt_replace
是:
- /* The argument to IPT_SO_SET_REPLACE. */
- struct ipt_replace
- {
- /* Which table. */
- char name[IPT_TABLE_MAXNAMELEN];
-
- /* Which hook entry points are valid: bitmask. You can't
- change this. */
- unsigned int valid_hooks;
-
- /* Number of entries */
- unsigned int num_entries;
-
- /* Total size of new entries */
- unsigned int size;
-
- /* Hook entry points. */
- unsigned int hook_entry[NF_IP_NUMHOOKS];
-
- /* Underflow points. */
- unsigned int underflow[NF_IP_NUMHOOKS];
-
- /* Information about old entries: */
- /* Number of counters (must be equal to current number of entries). */
- unsigned int num_counters;
- /* The old entries' counters. */
- struct ipt_counters *counters;
-
- /* The entries (hang off end: not really an array). */
- struct ipt_entry entries[0];
- };
复制代码
他对应的前面这一大段代码:
- { "filter", FILTER_VALID_HOOKS, 4,
- sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error),
- { [NF_IP_LOCAL_IN] 0,
- [NF_IP_FORWARD] sizeof(struct ipt_standard),
- [NF_IP_LOCAL_OUT] sizeof(struct ipt_standard) * 2 },
- { [NF_IP_LOCAL_IN] 0,
- [NF_IP_FORWARD] sizeof(struct ipt_standard),
- [NF_IP_LOCAL_OUT] sizeof(struct ipt_standard) * 2 },
- 0, NULL, { } }
复制代码
关键在于:
- { [NF_IP_LOCAL_IN] 0,
- [NF_IP_FORWARD] sizeof(struct ipt_standard),
- [NF_IP_LOCAL_OUT] sizeof(struct ipt_standard) * 2 }
复制代码
对应的是数组
- unsigned int hook_entry[NF_IP_NUMHOOKS];
复制代码
我试了一下,数组确实是可以这样来初始化的:
- int main(int argc, char *argv[])
- {
- int array[5] = {[3]1, [1]1 , [2] 2, [4] 4};
- int i;
-
- for (i = 0; i < 5; ++i)
- {
- printf("array = %d\n", array[i]);
- }
-
- return 0;
- }
复制代码 |
|