sizeof pointer vs sizeof struct

Logan B <[email protected]> Thu, 29 Feb 2024 20:20:38 -0500
Newsgroups org.kernel.vger.xdp-newbies
Message-ID <CAFR4CiudyKWsSe3xdaDTFn-zGS12w47tF8kKb8fd+s=cMsRA5A@mail.gmail.com>
Hello,
I was recently working through the xdp tutorial and in the
packet01-parsing lesson the sizeof a pointer to the ethernet header
struct is used, not the sizeof the struct itself[0]. I peeked and the
solution for this section also still uses the sizeof a pointer and not
the struct so this isn't part of the tutorial and I was wondering what
is going on? I don't think the verifier is re-writing these addresses,
only those for the memory access into the packet data.

#include <stdio.h>
#include <linux/if_ether.h>

int main(void)

       {

                           struct ethhdr normal = {0};
    struct ethhdr *eth_hdr_ptr;

     printf("Size of struct %lu\n",sizeof(normal)); // prints 14
    printf("Size of struct pointer %lu\n",sizeof(eth_hdr_ptr)); //
prints 8
    return 0;
}


[0]https://github.com/xdp-project/xdp-tutorial/blob/master/packet01-parsing/xdp_prog_kern.c#L34
--
Logan