- 論壇徽章:
- 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 }
復制代碼
對應的是數(shù)組
- unsigned int hook_entry[NF_IP_NUMHOOKS];
復制代碼
我試了一下,數(shù)組確實是可以這樣來初始化的:
- 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;
- }
復制代碼 |
|