From: Jay Vosburgh <jay.vosburgh@canonical.com>
To: mr.bo.jangles3@gmail.com
Cc: xdp-newbies@vger.kernel.org
Subject: Re: sizeof pointer vs sizeof struct
Date: Thu, 29 Feb 2024 18:10:30 -0800 [thread overview]
Message-ID: <24438.1709259030@famine> (raw)
In-Reply-To: <CAFR4CiudyKWsSe3xdaDTFn-zGS12w47tF8kKb8fd+s=cMsRA5A@mail.gmail.com>
Logan B <mrbojangles3@gmail.com> wrote:
>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.
The referenced code at [0] is:
struct ethhdr *eth = nh->pos;
int hdrsize = sizeof(*eth);
"*eth" means "what eth points to," so this is indeed taking the
sizeof struct ethhdr.
I suspect you missed the "*" in your reading of the code; in
this context, "*" is the indirection operator, per K&R 2, (The C
Programming Language, 2nd Edition), Appendix A 7.4.3.
-J
>
>#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
>
---
-Jay Vosburgh, jay.vosburgh@canonical.com
next prev parent reply other threads:[~2024-03-01 2:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 1:20 sizeof pointer vs sizeof struct Logan B
2024-03-01 2:10 ` Jay Vosburgh [this message]
2024-03-01 2:30 ` Logan B
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=24438.1709259030@famine \
--to=jay.vosburgh@canonical.com \
--cc=mr.bo.jangles3@gmail.com \
--cc=xdp-newbies@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).