linux.lover wrote:
Hello all,
I am analysing 2.4 and 2.6 series ip_output.c file code. What i
found is that 2.6 kernel initialised
ip_packet_type with following definition
static struct packet_type ip_packet_type = {
.type = __constant_htons(ETH_P_IP),
.func = ip_rcv,
^^ Are you sure this comma is there? };
And 2.4 have following definition.
static struct packet_type ip_packet_type =
{
__constant_htons(ETH_P_IP),
NULL, /* All devices */
ip_rcv,
(void*)1,
NULL,
^^ Are you sure this comma is there? };
Why . is used in 2.6 series kernels and not in 2.4 series?Also other
structure members are why not necessary to define in 2.6 kernel?
The 2.6 code (based on either the C99 standard or gcc, no doubt) allows
one to write initializations knowing only the names of the relevant
members of the struct. The 2.4 code (based on C90) requires one to know
the order of the members of the struct, including those that are not
relevant if they precede any of the relevant ones.
Note the members that you don't care about in the 2.4 code:
static struct packet_type ip_packet_type =
{
__constant_htons(ETH_P_IP), /* relevant */
NULL, /* NOT relevant */
ip_rcv, /* relevant */
(void*)1, /* NOT relevant */
NULL /* NOT relevant */
};
It appears that the (void *)1 for the fourth member is not needed as
more than a place holder and that the final NULL is silly. Even so, the
pruned down initialization requires that you know that you are
initializing the first and second elements:
static struct packet_type ip_packet_type =
{
__constant_htons(ETH_P_IP), /* relevant */
NULL, /* NOT relevant */
ip_rcv /* relevant */
};